mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-23 17:28:27 +00:00
add dumpBlockState stub
This commit is contained in:
parent
403e12b91f
commit
f613f8b3c6
@ -60,3 +60,25 @@ proc setupDebugRpc*(chainDB: BaseChainDB, rpcsrv: RpcServer) =
|
|||||||
if opts.disableState.isTrue: flags.incl TracerFlags.DisableState
|
if opts.disableState.isTrue: flags.incl TracerFlags.DisableState
|
||||||
|
|
||||||
traceTransaction(chainDB, blockHeader, blockBody, txDetails.index, flags)
|
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)
|
||||||
|
@ -33,20 +33,6 @@ template balance(addressDb: AccountStateDb, address: EthAddress): GasInt =
|
|||||||
# TODO: Account balance u256 but GasInt is int64?
|
# TODO: Account balance u256 but GasInt is int64?
|
||||||
addressDb.getBalance(address).truncate(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) =
|
proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) =
|
||||||
|
|
||||||
func getAccountDb(header: BlockHeader, readOnly = true): AccountStateDb =
|
func getAccountDb(header: BlockHeader, readOnly = true): AccountStateDb =
|
||||||
|
@ -7,7 +7,9 @@
|
|||||||
# This file may not be copied, modified, or distributed except according to
|
# This file may not be copied, modified, or distributed except according to
|
||||||
# those terms.
|
# 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)
|
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.} =
|
func toHash*(value: EthHashStr): Hash256 {.inline.} =
|
||||||
result = hexToPaddedByteArray[32](value.string).toHash
|
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)
|
@ -87,3 +87,6 @@ proc traceTransaction*(db: BaseChainDB, header: BlockHeader,
|
|||||||
for k, v in pairsInMemoryDB(memoryDB):
|
for k, v in pairsInMemoryDB(memoryDB):
|
||||||
n[k.prefixHex] = %v.prefixHex
|
n[k.prefixHex] = %v.prefixHex
|
||||||
result["state"] = n
|
result["state"] = n
|
||||||
|
|
||||||
|
proc dumpBlockState*(header: BlockHeader): JsonNode =
|
||||||
|
discard
|
Loading…
x
Reference in New Issue
Block a user