mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-11 21:04:11 +00:00
eth_getCode and helper func strToAddress
This commit is contained in:
parent
25f8123c6f
commit
ee15f4a995
@ -9,7 +9,17 @@
|
|||||||
import
|
import
|
||||||
nimcrypto, json_rpc/rpcserver, eth_p2p, hexstrings, strutils, stint,
|
nimcrypto, json_rpc/rpcserver, eth_p2p, hexstrings, strutils, stint,
|
||||||
../config, ../vm_state, ../constants, eth_trie/[memdb, types],
|
../config, ../vm_state, ../constants, eth_trie/[memdb, types],
|
||||||
../db/[db_chain, state_db], eth_common, rpc_types, byteutils
|
../db/[db_chain, state_db], eth_common, rpc_types, byteutils,
|
||||||
|
ranges/typedranges
|
||||||
|
|
||||||
|
#[
|
||||||
|
Note:
|
||||||
|
* Hexstring types (HexQuantitySt, HexDataStr, EthAddressStr, EthHashStr)
|
||||||
|
are parsed to check format before the RPC blocks are executed and will
|
||||||
|
raise an exception if invalid.
|
||||||
|
]#
|
||||||
|
|
||||||
|
func strToAddress(value: string): EthAddress = hexToPaddedByteArray[20](value)
|
||||||
|
|
||||||
func headerFromTag(chain:BaseChainDB, blockTag: string): BlockHeader =
|
func headerFromTag(chain:BaseChainDB, blockTag: string): BlockHeader =
|
||||||
let tag = blockTag.toLowerAscii
|
let tag = blockTag.toLowerAscii
|
||||||
@ -87,7 +97,7 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
|||||||
## Returns integer of the current balance in wei.
|
## Returns integer of the current balance in wei.
|
||||||
let
|
let
|
||||||
account_db = accountDbFromTag(quantityTag)
|
account_db = accountDbFromTag(quantityTag)
|
||||||
addrBytes = hexToPaddedByteArray[20](data.string)
|
addrBytes = strToAddress(data.string)
|
||||||
balance = account_db.get_balance(addrBytes)
|
balance = account_db.get_balance(addrBytes)
|
||||||
|
|
||||||
result = balance.toInt
|
result = balance.toInt
|
||||||
@ -101,12 +111,11 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
|||||||
## Returns: the value at this storage position.
|
## Returns: the value at this storage position.
|
||||||
let
|
let
|
||||||
account_db = accountDbFromTag(quantityTag)
|
account_db = accountDbFromTag(quantityTag)
|
||||||
addrBytes = hexToPaddedByteArray[20](data.string)
|
addrBytes = strToAddress(data.string)
|
||||||
storage = account_db.getStorage(addrBytes, quantity.u256)
|
storage = account_db.getStorage(addrBytes, quantity.u256)
|
||||||
if storage[1]:
|
if storage[1]:
|
||||||
result = ("0x" & storage[0].toHex).HexDataStr
|
result = ("0x" & storage[0].toHex).HexDataStr
|
||||||
|
|
||||||
|
|
||||||
rpcsrv.rpc("eth_getTransactionCount") do(data: EthAddressStr, quantityTag: string) -> int:
|
rpcsrv.rpc("eth_getTransactionCount") do(data: EthAddressStr, quantityTag: string) -> int:
|
||||||
## Returns the number of transactions sent from an address.
|
## Returns the number of transactions sent from an address.
|
||||||
##
|
##
|
||||||
@ -164,7 +173,17 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
|||||||
## data: address
|
## data: address
|
||||||
## quantityTag: integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.
|
## quantityTag: integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.
|
||||||
## Returns the code from the given address.
|
## Returns the code from the given address.
|
||||||
discard
|
let
|
||||||
|
account_db = accountDbFromTag(quantityTag)
|
||||||
|
addrBytes = strToAddress(data.string)
|
||||||
|
storage = account_db.getCode(addrBytes)
|
||||||
|
var
|
||||||
|
idx = 2
|
||||||
|
res = newString(storage.len + 2)
|
||||||
|
res[0..1] = "0x"
|
||||||
|
for b in storage:
|
||||||
|
res[idx] = b.char
|
||||||
|
result = hexDataStr(res)
|
||||||
|
|
||||||
rpcsrv.rpc("eth_sign") do(data: EthAddressStr, message: HexDataStr) -> HexDataStr:
|
rpcsrv.rpc("eth_sign") do(data: EthAddressStr, message: HexDataStr) -> HexDataStr:
|
||||||
## The sign method calculates an Ethereum specific signature with: sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))).
|
## The sign method calculates an Ethereum specific signature with: sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user