diff --git a/premix/graphql_downloader.nim b/premix/graphql_downloader.nim index e752c2a13..ec57db065 100644 --- a/premix/graphql_downloader.nim +++ b/premix/graphql_downloader.nim @@ -53,6 +53,7 @@ query getBlock($blockNumber: Long!) { address storageKeys } + index } } } @@ -68,7 +69,7 @@ proc fromJson(_: type ChainId, n: JsonNode, name: string): ChainId = fromJson(n, name, chainId) ChainId(chainId) -proc requestBlock*(blockNumber: BlockNumber): Block = +proc requestBlock*(blockNumber: BlockNumber, parseTx = true): Block = let address = initTAddress("127.0.0.1:8545") let clientRes = GraphqlHttpClientRef.new(address) if clientRes.isErr: @@ -92,12 +93,13 @@ proc requestBlock*(blockNumber: BlockNumber): Block = let chainId = ChainId.fromJson(n["data"], "chainID") result.header = parseBlockHeader(nh) - let txs = nh["transactions"] - for txn in txs: - var tx = parseTransaction(txn) - tx.chainId = chainId - validateTxSenderAndHash(txn, tx) - result.body.transactions.add tx + if parseTx: + let txs = nh["transactions"] + for txn in txs: + var tx = parseTransaction(txn) + tx.chainId = chainId + validateTxSenderAndHash(txn, tx) + result.body.transactions.add tx let uncles = nh["ommers"] for un in uncles: diff --git a/premix/parser.nim b/premix/parser.nim index fbeb72794..4447fb8f1 100644 --- a/premix/parser.nim +++ b/premix/parser.nim @@ -84,6 +84,13 @@ proc fromJson*[T](n: JsonNode, name: string, x: var Option[T]) = n.fromJson(name, val) x = some(val) +proc fromJson*(n: JsonNode, name: string, x: var TxType) = + let node = n[name] + if node.kind == JInt: + x = TxType(node.getInt) + else: + x = hexToInt(node.getStr(), int).TxType + proc parseBlockHeader*(n: JsonNode): BlockHeader = n.fromJson "parentHash", result.parentHash n.fromJson "sha3Uncles", result.ommersHash @@ -130,14 +137,17 @@ proc parseTransaction*(n: JsonNode): Transaction = n.fromJson "s", tx.S if n["type"].kind != JNull: - tx.txType = TxType(n["type"].getInt) + n.fromJson "type", tx.txType - if tx.txType == TxEip1559: + if tx.txType >= TxEip1559: n.fromJson "maxPriorityFeePerGas", tx.maxPriorityFee n.fromJson "maxFeePerGas", tx.maxFee - if tx.txType == TxEip2930: - # chainId is set from top level query + if tx.txType >= TxEip2930: + if n.hasKey("chainId"): + let id = hexToInt(n["chainId"].getStr(), int) + tx.chainId = ChainId(id) + let accessList = n["accessList"] if accessList.len > 0: for acn in accessList: