@@ -54,7 +54,7 @@ proc calculateMedianGasPrice*(chain: CoreDbRef): GasInt {.raises: [RlpError].} =
5454 # For compatibility with `ethpandaops/ethereum-package`, set this to a
5555 # sane minimum for compatibility to unblock testing.
5656 # Note: When this is fixed, update `tests/graphql/queries.toml` and
57- # re-enable the "query.gasPrice" test case (remove `skip = true`).
57+ # re-enable the "query.gasPrice" test case (remove `skip = true`).
5858 result = max (result , minGasPrice)
5959
6060proc unsignedTx * (tx: TransactionArgs , chain: CoreDbRef , defaultNonce: AccountNonce , chainId: ChainId ): Transaction
@@ -92,112 +92,126 @@ proc unsignedTx*(tx: TransactionArgs, chain: CoreDbRef, defaultNonce: AccountNon
9292
9393proc toWd (wd: Withdrawal ): WithdrawalObject =
9494 WithdrawalObject (
95- index: Quantity wd.index,
95+ index: Quantity ( wd.index) ,
9696 validatorIndex: Quantity wd.validatorIndex,
9797 address: wd.address,
9898 amount: Quantity wd.amount,
9999 )
100100
101101proc toWdList (list: openArray [Withdrawal ]): seq [WithdrawalObject ] =
102- var res = newSeqOfCap [WithdrawalObject ](list.len)
102+ result = newSeqOfCap [WithdrawalObject ](list.len)
103103 for x in list:
104- res.add toWd (x)
105- return res
104+ result .add toWd (x)
106105
107- func toWdList (x: Opt [seq [eth_types. Withdrawal ]]):
106+ func toWdList (x: Opt [seq [Withdrawal ]]):
108107 Opt [seq [WithdrawalObject ]] =
109108 if x.isNone: Opt .none (seq [WithdrawalObject ])
110109 else : Opt .some (toWdList x.get)
111110
111+ func toAuth * (x: Authorization ): AuthorizationObject =
112+ AuthorizationObject (
113+ chainId: Quantity (x.chainId),
114+ address: x.address,
115+ nonce: Quantity (x.nonce),
116+ v: Quantity (x.v),
117+ r: x.r,
118+ s: x.s,
119+ )
120+
121+ proc toAuthList (list: openArray [Authorization ]): seq [AuthorizationObject ] =
122+ result = newSeqOfCap [AuthorizationObject ](list.len)
123+ for x in list:
124+ result .add toAuth (x)
125+
112126proc populateTransactionObject * (tx: Transaction ,
113127 optionalHash: Opt [eth_types.Hash32 ] = Opt .none (eth_types.Hash32 ),
114128 optionalNumber: Opt [eth_types.BlockNumber ] = Opt .none (eth_types.BlockNumber ),
115129 txIndex: Opt [uint64 ] = Opt .none (uint64 )): TransactionObject =
116- var res = TransactionObject ()
117- res .`type` = Opt .some Quantity (tx.txType)
118- res .blockHash = optionalHash
119- res .blockNumber = w3Qty (optionalNumber)
130+ result = TransactionObject ()
131+ result .`type` = Opt .some Quantity (tx.txType)
132+ result .blockHash = optionalHash
133+ result .blockNumber = w3Qty (optionalNumber)
120134
121135 if (let sender = tx.recoverSender (); sender.isOk):
122- res .`from` = sender[]
123- res .gas = Quantity (tx.gasLimit)
124- res .gasPrice = Quantity (tx.gasPrice)
125- res .hash = tx.rlpHash
126- res .input = tx.payload
127- res .nonce = Quantity (tx.nonce)
128- res .to = Opt .some (tx.destination)
136+ result .`from` = sender[]
137+ result .gas = Quantity (tx.gasLimit)
138+ result .gasPrice = Quantity (tx.gasPrice)
139+ result .hash = tx.rlpHash
140+ result .input = tx.payload
141+ result .nonce = Quantity (tx.nonce)
142+ result .to = Opt .some (tx.destination)
129143 if txIndex.isSome:
130- res .transactionIndex = Opt .some (Quantity (txIndex.get))
131- res .value = tx.value
132- res .v = Quantity (tx.V)
133- res .r = tx.R
134- res .s = tx.S
135- res .maxFeePerGas = Opt .some Quantity (tx.maxFeePerGas)
136- res .maxPriorityFeePerGas = Opt .some Quantity (tx.maxPriorityFeePerGas)
144+ result .transactionIndex = Opt .some (Quantity (txIndex.get))
145+ result .value = tx.value
146+ result .v = Quantity (tx.V)
147+ result .r = tx.R
148+ result .s = tx.S
149+ result .maxFeePerGas = Opt .some Quantity (tx.maxFeePerGas)
150+ result .maxPriorityFeePerGas = Opt .some Quantity (tx.maxPriorityFeePerGas)
137151
138152 if tx.txType >= TxEip2930 :
139- res .chainId = Opt .some (Quantity (tx.chainId))
140- res .accessList = Opt .some (tx.accessList)
153+ result .chainId = Opt .some (Quantity (tx.chainId))
154+ result .accessList = Opt .some (tx.accessList)
141155
142156 if tx.txType >= TxEip4844 :
143- res .maxFeePerBlobGas = Opt .some (tx.maxFeePerBlobGas)
144- res .blobVersionedHashes = Opt .some (tx.versionedHashes)
157+ result .maxFeePerBlobGas = Opt .some (tx.maxFeePerBlobGas)
158+ result .blobVersionedHashes = Opt .some (tx.versionedHashes)
145159
146- return res
160+ if tx.txType >= TxEip7702 :
161+ result .authorizationList = Opt .some (toAuthList (tx.authorizationList))
147162
148- proc populateBlockObject * (blockHash: Hash32 ,
163+ proc populateBlockObject * (blockHash: eth_types. Hash32 ,
149164 blk: Block ,
150165 totalDifficulty: UInt256 ,
151166 fullTx: bool ,
152- isUncle = false ): BlockObject =
167+ withUncles: bool = false ): BlockObject =
153168 template header : auto = blk.header
154169
155- var res = BlockObject ()
156- res .number = Quantity (header.number)
157- res .hash = blockHash
158- res .parentHash = header.parentHash
159- res .nonce = Opt .some (header.nonce)
160- res .sha3Uncles = header.ommersHash
161- res .logsBloom = header.logsBloom
162- res .transactionsRoot = header.txRoot
163- res .stateRoot = header.stateRoot
164- res .receiptsRoot = header.receiptsRoot
165- res .miner = header.coinbase
166- res .difficulty = header.difficulty
167- res .extraData = HistoricExtraData header.extraData
168- res .mixHash = Hash32 header.mixHash
170+ result = BlockObject ()
171+ result .number = Quantity (header.number)
172+ result .hash = blockHash
173+ result .parentHash = header.parentHash
174+ result .nonce = Opt .some (header.nonce)
175+ result .sha3Uncles = header.ommersHash
176+ result .logsBloom = header.logsBloom
177+ result .transactionsRoot = header.txRoot
178+ result .stateRoot = header.stateRoot
179+ result .receiptsRoot = header.receiptsRoot
180+ result .miner = header.coinbase
181+ result .difficulty = header.difficulty
182+ result .extraData = HistoricExtraData header.extraData
183+ result .mixHash = Hash32 header.mixHash
169184
170185 # discard sizeof(seq[byte]) of extraData and use actual length
171- let size = sizeof (Header ) - sizeof (seq [byte ]) + header.extraData.len
172- res.size = Quantity (size)
173-
174- res.gasLimit = Quantity (header.gasLimit)
175- res.gasUsed = Quantity (header.gasUsed)
176- res.timestamp = Quantity (header.timestamp)
177- res.baseFeePerGas = header.baseFeePerGas
178- res.totalDifficulty = totalDifficulty
179-
180- if not isUncle:
181- res.uncles = blk.uncles.mapIt (it.blockHash)
182-
183- if fullTx:
184- for i, tx in blk.transactions:
185- let txObj = populateTransactionObject (tx,
186- Opt .some (blockHash),
187- Opt .some (header.number), Opt .some (i.uint64 ))
188- res.transactions.add txOrHash (txObj)
189- else :
190- for i, tx in blk.transactions:
191- let txHash = rlpHash (tx)
192- res.transactions.add txOrHash (txHash)
193-
194- res.withdrawalsRoot = header.withdrawalsRoot
195- res.withdrawals = toWdList blk.withdrawals
196- res.parentBeaconBlockRoot = header.parentBeaconBlockRoot
197- res.blobGasUsed = w3Qty (header.blobGasUsed)
198- res.excessBlobGas = w3Qty (header.excessBlobGas)
199-
200- return res
186+ let size = sizeof (eth_types.Header ) - sizeof (eth_api_types.Blob ) + header.extraData.len
187+ result .size = Quantity (size)
188+
189+ result .gasLimit = Quantity (header.gasLimit)
190+ result .gasUsed = Quantity (header.gasUsed)
191+ result .timestamp = Quantity (header.timestamp)
192+ result .baseFeePerGas = header.baseFeePerGas
193+ result .totalDifficulty = totalDifficulty
194+
195+ if not withUncles:
196+ result .uncles = blk.uncles.mapIt (it.blockHash)
197+
198+ if fullTx:
199+ for i, tx in blk.transactions:
200+ let txObj = populateTransactionObject (tx,
201+ Opt .some (blockHash),
202+ Opt .some (header.number), Opt .some (i.uint64 ))
203+ result .transactions.add txOrHash (txObj)
204+ else :
205+ for i, tx in blk.transactions:
206+ let txHash = rlpHash (tx)
207+ result .transactions.add txOrHash (txHash)
208+
209+ result .withdrawalsRoot = header.withdrawalsRoot
210+ result .withdrawals = toWdList blk.withdrawals
211+ result .parentBeaconBlockRoot = header.parentBeaconBlockRoot
212+ result .blobGasUsed = w3Qty (header.blobGasUsed)
213+ result .excessBlobGas = w3Qty (header.excessBlobGas)
214+ result .requestsHash = header.requestsHash
201215
202216proc populateReceipt * (receipt: Receipt , gasUsed: GasInt , tx: Transaction ,
203217 txIndex: uint64 , header: Header ): ReceiptObject =
0 commit comments