add dumpBlockState stub

This commit is contained in:
andri lim 2018-12-11 17:05:49 +07:00 committed by zah
parent 403e12b91f
commit f613f8b3c6
4 changed files with 41 additions and 15 deletions

View File

@ -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)

View File

@ -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 =

View File

@ -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)

View File

@ -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