-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeeDelegateEncode.js
104 lines (91 loc) · 2.4 KB
/
FeeDelegateEncode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
module.exports = { FDDUnsignedTxEncode,FDDSignedTxEncode,DUnsignedTxEncode,DSignedTxEncode }
const Utils = require('ethereumjs-util')
const RLP = Utils.rlp
const D_TxType = "0x02"
const FD_TxType = "0x16"
// Fee Delegate(FD) DynamicFeeTx Unsigned RLP encode
function FDDUnsignedTxEncode(Tx){
let txRlp = RLP.encode([
[
Tx.chainId,
Tx.nonce,
Tx.maxPriorityFeePerGas,
Tx.maxFeePerGas,
Tx.gas,
Tx.to,
Tx.value,
Tx.input,
Tx.accessList,
Tx.v,
Tx.r,
Tx.s
],
Tx.feePayer
])
let typeTxHex = FD_TxType+Utils.bufferToHex(txRlp).slice(2)
let txHash = Utils.bufferToHex(Utils.keccak256(Utils.toBuffer(typeTxHex)))
return [txHash,typeTxHex]
}
// Fee Delegate(FD) DynamicFeeTx Signed RLP encode
function FDDSignedTxEncode(Tx){
let txRlp = RLP.encode([
[
Tx.chainId,
Tx.nonce,
Tx.maxPriorityFeePerGas,
Tx.maxFeePerGas,
Tx.gas,
Tx.to,
Tx.value,
Tx.input,
Tx.accessList,
Tx.v,
Tx.r,
Tx.s
],
Tx.feePayer,
Tx.fv,
Tx.fr,
Tx.fs,
])
let typeTxHex = FD_TxType+Utils.bufferToHex(txRlp).slice(2)
let txHash = Utils.bufferToHex(Utils.keccak256(Utils.toBuffer(typeTxHex)))
return [txHash,typeTxHex]
}
// DynamicFeeTx Unsigned RLP encode
function DUnsignedTxEncode(Tx){
let txRlp = RLP.encode([
Tx.chainId,
Tx.nonce,
Tx.maxPriorityFeePerGas,
Tx.maxFeePerGas,
Tx.gas,
Tx.to,
Tx.value,
Tx.input,
Tx.accessList,
])
let typeTxHex = D_TxType+Utils.bufferToHex(txRlp).slice(2)
let txHash = Utils.bufferToHex(Utils.keccak256(Utils.toBuffer(typeTxHex)))
return [txHash,typeTxHex]
}
// DynamicFeeTx Signed RLP encode
function DSignedTxEncode(Tx){
let txRlp = RLP.encode([
Tx.chainId,
Tx.nonce,
Tx.maxPriorityFeePerGas,
Tx.maxFeePerGas,
Tx.gas,
Tx.to,
Tx.value,
Tx.input,
Tx.accessList,
Tx.v,
Tx.r,
Tx.s,
])
let typeTxHex = D_TxType+Utils.bufferToHex(txRlp).slice(2)
let txHash = Utils.bufferToHex(Utils.keccak256(Utils.toBuffer(typeTxHex)))
return [txHash,typeTxHex]
}