-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeeDelegateDecode.js
86 lines (83 loc) · 4.08 KB
/
FeeDelegateDecode.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
module.exports = { UnsignedTxDecode,SignedTxDecode }
const Utils = require('ethereumjs-util')
const RLP = Utils.rlp
const D_TxType = "0x02"
const FD_TxType = "0x16"
// DynamicFeeTx & Fee Delegate(FD) DynamicFeeTx Unsigned RLP decode
function UnsignedTxDecode(rawTransaction) {
let decodeTx = {}
let txType = rawTransaction.slice(0, 4)
console.log("decodeRLP=", txType)
if (txType == D_TxType) {
let [chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gas, to, value, data, [accessList]] = RLP.decode(Utils.toBuffer('0x' + rawTransaction.slice(4)))
decodeTx.chainId = Utils.bufferToInt(chainId);
decodeTx.nonce = Utils.bufferToInt(nonce);
decodeTx.maxPriorityFeePerGas = Utils.bufferToHex(maxPriorityFeePerGas);
decodeTx.maxFeePerGas = Utils.bufferToHex(maxFeePerGas);
decodeTx.gas = Utils.bufferToHex(gas);
decodeTx.to = Utils.bufferToHex(to);
decodeTx.value = Utils.bufferToHex(value);
decodeTx.input = Utils.bufferToHex(data);
decodeTx.accessList = Utils.bufferToHex(accessList);
if (decodeTx.accessList == '0x') decodeTx.accessList = []
} else if (txType == FD_TxType) {
let [[chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gas, to, value, data, [accessList], v, r, s], feePayer] = RLP.decode(Utils.toBuffer('0x' + rawTransaction.slice(4)))
decodeTx.chainId = Utils.bufferToInt(chainId);
decodeTx.nonce = Utils.bufferToInt(nonce);
decodeTx.maxPriorityFeePerGas = Utils.bufferToHex(maxPriorityFeePerGas);
decodeTx.maxFeePerGas = Utils.bufferToHex(maxFeePerGas);
decodeTx.gas = Utils.bufferToHex(gas);
decodeTx.to = Utils.bufferToHex(to);
decodeTx.value = Utils.bufferToHex(value);
decodeTx.input = Utils.bufferToHex(data);
decodeTx.accessList = Utils.bufferToHex(accessList);
if (decodeTx.accessList == '0x') decodeTx.accessList = []
decodeTx.v = v;
decodeTx.r = r;
decodeTx.s = s;
decodeTx.feePayer = Utils.bufferToHex(feePayer);
}
return decodeTx
}
// DynamicFeeTx & Fee Delegate(FD) DynamicFeeTx Signed RLP decode
function SignedTxDecode(rawTransaction){
let decodeTx={}
let txType = rawTransaction.slice(0,4)
console.log("decodeRLP=",txType)
if(txType == D_TxType) {
let [chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gas, to, value, data, [accessList], v, r, s] = RLP.decode(Utils.toBuffer('0x' + rawTransaction.slice(4)))
decodeTx.chainId = Utils.bufferToInt(chainId);
decodeTx.nonce = Utils.bufferToInt(nonce);
decodeTx.maxPriorityFeePerGas = Utils.bufferToHex(maxPriorityFeePerGas);
decodeTx.maxFeePerGas = Utils.bufferToHex(maxFeePerGas);
decodeTx.gas = Utils.bufferToHex(gas);
decodeTx.to = Utils.bufferToHex(to);
decodeTx.value = Utils.bufferToHex(value);
decodeTx.input = Utils.bufferToHex(data);
decodeTx.accessList = Utils.bufferToHex(accessList);
if(decodeTx.accessList=='0x') decodeTx.accessList=[]
decodeTx.v = v;
decodeTx.r = r;
decodeTx.s = s;
}else if(txType == FD_TxType) {
let [[chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gas, to, value, data, [accessList], v, r, s], feePayer, fv, fr, fs] = RLP.decode(Utils.toBuffer('0x' + rawTransaction.slice(4)))
decodeTx.chainId = Utils.bufferToInt(chainId);
decodeTx.nonce = Utils.bufferToInt(nonce);
decodeTx.maxPriorityFeePerGas = Utils.bufferToHex(maxPriorityFeePerGas);
decodeTx.maxFeePerGas = Utils.bufferToHex(maxFeePerGas);
decodeTx.gas = Utils.bufferToHex(gas);
decodeTx.to = Utils.bufferToHex(to);
decodeTx.value = Utils.bufferToHex(value);
decodeTx.input = Utils.bufferToHex(data);
decodeTx.accessList = Utils.bufferToHex(accessList);
if(decodeTx.accessList=='0x') decodeTx.accessList=[]
decodeTx.v = v;
decodeTx.r = r;
decodeTx.s = s;
decodeTx.feePayer = Utils.bufferToHex(feePayer);
decodeTx.fv = fv;
decodeTx.fr = fr;
decodeTx.fs = fs;
}
return decodeTx
}