Skip to content

Commit 3ef986c

Browse files
authored
Fusaka: Add EIP-7873 fields to TransactionObject/TransactionArgs (#198)
* Fusaka: Add EIP-7873 fields to TransactionObject/TransactionArgs * Fix: fields should be Optional * Fix transaction signing
1 parent e577619 commit 3ef986c

File tree

2 files changed

+58
-33
lines changed

2 files changed

+58
-33
lines changed

web3/eth_api_types.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ type
7171
# EIP-7702
7272
authorizationList*: Opt[seq[Authorization]]
7373

74+
# EIP-7873
75+
initCodes*: Opt[seq[seq[byte]]]
76+
7477
## A block header object
7578
BlockHeader* = ref object
7679
number*: Quantity
@@ -166,6 +169,7 @@ type
166169
maxFeePerBlobGas*: Opt[UInt256] # EIP-4844
167170
blobVersionedHashes*: Opt[seq[VersionedHash]] # EIP-4844
168171
authorizationList*: Opt[seq[Authorization]] # EIP-7702
172+
initCodes*: Opt[seq[seq[byte]]] # EIP-7873
169173

170174
ReceiptObject* = ref object # A transaction receipt object, or null when no receipt was found:
171175
transactionHash*: Hash32 # hash of the transaction.

web3/transaction_signing.nim

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import
1313

1414
func encodeTransactionLegacy(s: TransactionArgs, pk: PrivateKey): seq[byte] =
1515
var tr = Transaction(txType: TxLegacy)
16-
tr.gasLimit = s.gas.get.GasInt
17-
tr.gasPrice = s.gasPrice.get.GasInt
16+
tr.gasLimit = s.gas.get(0.Quantity).GasInt
17+
tr.gasPrice = s.gasPrice.get(0.Quantity).GasInt
1818
tr.to = s.to
1919

2020
if s.value.isSome:
21-
tr.value = s.value.get
22-
tr.nonce = uint64(s.nonce.get)
21+
tr.value = s.value.value
22+
tr.nonce = uint64(s.nonce.get(0.Quantity))
2323
tr.payload = s.payload
2424
tr.signature =
2525
if s.chainId.isSome():
@@ -31,67 +31,84 @@ func encodeTransactionLegacy(s: TransactionArgs, pk: PrivateKey): seq[byte] =
3131

3232
func encodeTransactionEip2930(s: TransactionArgs, pk: PrivateKey): seq[byte] =
3333
var tr = Transaction(txType: TxEip2930)
34-
tr.gasLimit = s.gas.get.GasInt
35-
tr.gasPrice = s.gasPrice.get.GasInt
34+
tr.gasLimit = s.gas.get(0.Quantity).GasInt
35+
tr.gasPrice = s.gasPrice.get(0.Quantity).GasInt
3636
tr.to = s.to
3737
if s.value.isSome:
38-
tr.value = s.value.get
39-
tr.nonce = uint64(s.nonce.get)
38+
tr.value = s.value.value
39+
tr.nonce = uint64(s.nonce.get(0.Quantity))
4040
tr.payload = s.payload
4141
tr.chainId = s.chainId.get
4242
tr.signature = tr.sign(pk, true)
43-
tr.accessList = s.accessList.get
43+
tr.accessList = s.accessList.value
4444
rlp.encode(tr)
4545

4646
func encodeTransactionEip1559(s: TransactionArgs, pk: PrivateKey): seq[byte] =
4747
var tr = Transaction(txType: TxEip1559)
48-
tr.gasLimit = s.gas.get.GasInt
49-
tr.maxPriorityFeePerGas = s.maxPriorityFeePerGas.get.GasInt
50-
tr.maxFeePerGas = s.maxFeePerGas.get.GasInt
48+
tr.gasLimit = s.gas.get(0.Quantity).GasInt
49+
tr.maxPriorityFeePerGas = s.maxPriorityFeePerGas.get(0.Quantity).GasInt
50+
tr.maxFeePerGas = s.maxFeePerGas.get(0.Quantity).GasInt
5151
tr.to = s.to
5252
if s.value.isSome:
53-
tr.value = s.value.get
54-
tr.nonce = uint64(s.nonce.get)
53+
tr.value = s.value.value
54+
tr.nonce = uint64(s.nonce.get(0.Quantity))
5555
tr.payload = s.payload
56-
tr.chainId = s.chainId.get
56+
tr.chainId = s.chainId.get(0.u256)
5757
tr.signature = tr.sign(pk, true)
5858
if s.accessList.isSome:
59-
tr.accessList = s.accessList.get
59+
tr.accessList = s.accessList.value
6060
rlp.encode(tr)
6161

6262
func encodeTransactionEip4844(s: TransactionArgs, pk: PrivateKey): seq[byte] =
6363
var tr = Transaction(txType: TxEip4844)
64-
tr.gasLimit = s.gas.get.GasInt
65-
tr.maxPriorityFeePerGas = s.maxPriorityFeePerGas.get.GasInt
66-
tr.maxFeePerGas = s.maxFeePerGas.get.GasInt
64+
tr.gasLimit = s.gas.get(0.Quantity).GasInt
65+
tr.maxPriorityFeePerGas = s.maxPriorityFeePerGas.get(0.Quantity).GasInt
66+
tr.maxFeePerGas = s.maxFeePerGas.get(0.Quantity).GasInt
6767
tr.to = s.to
6868
if s.value.isSome:
69-
tr.value = s.value.get
70-
tr.nonce = uint64(s.nonce.get)
69+
tr.value = s.value.value
70+
tr.nonce = uint64(s.nonce.get(0.Quantity))
7171
tr.payload = s.payload
72-
tr.chainId = s.chainId.get
72+
tr.chainId = s.chainId.get(0.u256)
7373
tr.signature = tr.sign(pk, true)
7474
if s.accessList.isSome:
75-
tr.accessList = s.accessList.get
76-
tr.maxFeePerBlobGas = s.maxFeePerBlobGas.get
77-
tr.versionedHashes = s.blobVersionedHashes.get
75+
tr.accessList = s.accessList.value
76+
tr.maxFeePerBlobGas = s.maxFeePerBlobGas.get(0.u256)
77+
tr.versionedHashes = s.blobVersionedHashes.value
7878
rlp.encode(tr)
7979

8080
func encodeTransactionEip7702(s: TransactionArgs, pk: PrivateKey): seq[byte] =
8181
var tr = Transaction(txType: TxEip7702)
82-
tr.gasLimit = s.gas.get.GasInt
83-
tr.maxPriorityFeePerGas = s.maxPriorityFeePerGas.get.GasInt
84-
tr.maxFeePerGas = s.maxFeePerGas.get.GasInt
82+
tr.gasLimit = s.gas.get(0.Quantity).GasInt
83+
tr.maxPriorityFeePerGas = s.maxPriorityFeePerGas.get(0.Quantity).GasInt
84+
tr.maxFeePerGas = s.maxFeePerGas.get(0.Quantity).GasInt
8585
tr.to = s.to
8686
if s.value.isSome:
87-
tr.value = s.value.get
88-
tr.nonce = uint64(s.nonce.get)
87+
tr.value = s.value.value
88+
tr.nonce = uint64(s.nonce.get(0.Quantity))
8989
tr.payload = s.payload
90-
tr.chainId = s.chainId.get
90+
tr.chainId = s.chainId.get(0.u256)
91+
tr.signature = tr.sign(pk, true)
92+
if s.accessList.isSome:
93+
tr.accessList = s.accessList.value
94+
tr.authorizationList = s.authorizationList.value
95+
rlp.encode(tr)
96+
97+
func encodeTransactionEip7873(s: TransactionArgs, pk: PrivateKey): seq[byte] =
98+
var tr = Transaction(txType: TxEip7873)
99+
tr.gasLimit = s.gas.get(0.Quantity).GasInt
100+
tr.maxPriorityFeePerGas = s.maxPriorityFeePerGas.get(0.Quantity).GasInt
101+
tr.maxFeePerGas = s.maxFeePerGas.get(0.Quantity).GasInt
102+
tr.to = s.to
103+
if s.value.isSome:
104+
tr.value = s.value.value
105+
tr.nonce = uint64(s.nonce.get(0.Quantity))
106+
tr.payload = s.payload
107+
tr.chainId = s.chainId.get(0.u256)
91108
tr.signature = tr.sign(pk, true)
92109
if s.accessList.isSome:
93-
tr.accessList = s.accessList.get
94-
tr.authorizationList = s.authorizationList.get
110+
tr.accessList = s.accessList.value
111+
tr.initCodes = s.initCodes.value
95112
rlp.encode(tr)
96113

97114
func encodeTransaction*(s: TransactionArgs, pk: PrivateKey, txType: TxType): seq[byte] =
@@ -106,8 +123,12 @@ func encodeTransaction*(s: TransactionArgs, pk: PrivateKey, txType: TxType): seq
106123
encodeTransactionEip4844(s, pk)
107124
of TxEip7702:
108125
encodeTransactionEip7702(s, pk)
126+
of TxEip7873:
127+
encodeTransactionEip7873(s, pk)
109128

110129
func txType(s: TransactionArgs): TxType =
130+
if s.initCodes.isSome:
131+
return TxEip7873
111132
if s.authorizationList.isSome:
112133
return TxEip7702
113134
if s.blobVersionedHashes.isSome:

0 commit comments

Comments
 (0)