From f613f8b3c67aad2801e7cb0871e1350cbe6d9c0d Mon Sep 17 00:00:00 2001 From: andri lim Date: Tue, 11 Dec 2018 17:05:49 +0700 Subject: [PATCH] add dumpBlockState stub --- nimbus/rpc/debug.nim | 22 ++++++++++++++++++++++ nimbus/rpc/p2p.nim | 14 -------------- nimbus/rpc/rpc_utils.nim | 17 ++++++++++++++++- nimbus/tracer.nim | 3 +++ 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/nimbus/rpc/debug.nim b/nimbus/rpc/debug.nim index 4f2de31d5..a2c533272 100644 --- a/nimbus/rpc/debug.nim +++ b/nimbus/rpc/debug.nim @@ -60,3 +60,25 @@ proc setupDebugRpc*(chainDB: BaseChainDB, rpcsrv: RpcServer) = if opts.disableState.isTrue: flags.incl TracerFlags.DisableState traceTransaction(chainDB, blockHeader, blockBody, txDetails.index, flags) + + rpcsrv.rpc("debug_dumpBlockStateByNumber") do(quantityTag: string) -> JsonNode: + ## Retrieves the state that corresponds to the block number and returns + ## a list of accounts (including storage and code). + ## + ## quantityTag: integer of a block number, or the string "earliest", + ## "latest" or "pending", as in the default block parameter. + let + header = chainDB.headerFromTag(quantityTag) + + dumpBlockState(header) + + rpcsrv.rpc("debug_dumpBlockStateByHash") do(data: EthHashStr) -> JsonNode: + ## Retrieves the state that corresponds to the block number and returns + ## a list of accounts (including storage and code). + ## + ## data: Hash of a block. + let + h = data.toHash + header = chainDB.getBlockHeader(h) + + dumpBlockState(header) diff --git a/nimbus/rpc/p2p.nim b/nimbus/rpc/p2p.nim index e2be27b5e..ef0dc0332 100644 --- a/nimbus/rpc/p2p.nim +++ b/nimbus/rpc/p2p.nim @@ -33,20 +33,6 @@ template balance(addressDb: AccountStateDb, address: EthAddress): GasInt = # TODO: Account balance u256 but GasInt is int64? addressDb.getBalance(address).truncate(int64) -func headerFromTag(chain:BaseChainDB, blockTag: string): BlockHeader = - let tag = blockTag.toLowerAscii - case tag - of "latest": result = chain.getCanonicalHead() - of "earliest": result = chain.getBlockHeader(GENESIS_BLOCK_NUMBER) - of "pending": - #TODO: Implement get pending block - raise newException(ValueError, "Pending tag not yet implemented") - else: - # Raises are trapped and wrapped in JSON when returned to the user. - tag.validateHexQuantity - let blockNum = stint.fromHex(UInt256, tag) - result = chain.getBlockHeader(blockNum) - proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) = func getAccountDb(header: BlockHeader, readOnly = true): AccountStateDb = diff --git a/nimbus/rpc/rpc_utils.nim b/nimbus/rpc/rpc_utils.nim index 89c110005..616e50317 100644 --- a/nimbus/rpc/rpc_utils.nim +++ b/nimbus/rpc/rpc_utils.nim @@ -7,7 +7,9 @@ # This file may not be copied, modified, or distributed except according to # those terms. -import hexstrings, nimcrypto, eth_common, byteutils +import hexstrings, nimcrypto, eth_common, byteutils, + ../db/[db_chain, state_db, storage_types], strutils, + ../constants, stint func toAddress*(value: EthAddressStr): EthAddress = hexToPaddedByteArray[20](value.string) @@ -17,3 +19,16 @@ func toHash*(value: array[32, byte]): Hash256 {.inline.} = func toHash*(value: EthHashStr): Hash256 {.inline.} = result = hexToPaddedByteArray[32](value.string).toHash +func headerFromTag*(chain: BaseChainDB, blockTag: string): BlockHeader = + let tag = blockTag.toLowerAscii + case tag + of "latest": result = chain.getCanonicalHead() + of "earliest": result = chain.getBlockHeader(GENESIS_BLOCK_NUMBER) + of "pending": + #TODO: Implement get pending block + raise newException(ValueError, "Pending tag not yet implemented") + else: + # Raises are trapped and wrapped in JSON when returned to the user. + tag.validateHexQuantity + let blockNum = stint.fromHex(UInt256, tag) + result = chain.getBlockHeader(blockNum) \ No newline at end of file diff --git a/nimbus/tracer.nim b/nimbus/tracer.nim index 9be9966d7..5f53abe2c 100644 --- a/nimbus/tracer.nim +++ b/nimbus/tracer.nim @@ -87,3 +87,6 @@ proc traceTransaction*(db: BaseChainDB, header: BlockHeader, for k, v in pairsInMemoryDB(memoryDB): n[k.prefixHex] = %v.prefixHex result["state"] = n + +proc dumpBlockState*(header: BlockHeader): JsonNode = + discard \ No newline at end of file