mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 05:14:14 +00:00
Merge pull request #124 from status-im/chain-db-interface
Separate Chain from ChainDB
This commit is contained in:
commit
3adc9f04f7
@ -11,7 +11,7 @@ import
|
|||||||
../errors, ../block_types, ../utils/header, ../constants, ./storage_types.nim
|
../errors, ../block_types, ../utils/header, ../constants, ./storage_types.nim
|
||||||
|
|
||||||
type
|
type
|
||||||
BaseChainDB* = ref object of AbstractChainDB
|
BaseChainDB* = ref object
|
||||||
db*: TrieDatabaseRef
|
db*: TrieDatabaseRef
|
||||||
# TODO db*: JournalDB
|
# TODO db*: JournalDB
|
||||||
|
|
||||||
@ -80,6 +80,9 @@ proc getBlockHeader*(self: BaseChainDB; n: BlockNumber): BlockHeader =
|
|||||||
## Raises BlockNotFound error if the block is not in the DB.
|
## Raises BlockNotFound error if the block is not in the DB.
|
||||||
self.getBlockHeader(self.getBlockHash(n))
|
self.getBlockHeader(self.getBlockHash(n))
|
||||||
|
|
||||||
|
proc getBlockBody*(self: BaseChainDB, h: Hash256, output: var BlockBody): bool =
|
||||||
|
discard # TODO:
|
||||||
|
|
||||||
proc getScore*(self: BaseChainDB; blockHash: Hash256): int =
|
proc getScore*(self: BaseChainDB; blockHash: Hash256): int =
|
||||||
rlp.decode(self.db.get(blockHashToScoreKey(blockHash).toOpenArray).toRange, int)
|
rlp.decode(self.db.get(blockHashToScoreKey(blockHash).toOpenArray).toRange, int)
|
||||||
|
|
||||||
@ -250,34 +253,6 @@ proc persistBlockToDb*(self: BaseChainDB; blk: Block) =
|
|||||||
proc getStateDb*(self: BaseChainDB; stateRoot: Hash256; readOnly: bool = false): AccountStateDB =
|
proc getStateDb*(self: BaseChainDB; stateRoot: Hash256; readOnly: bool = false): AccountStateDB =
|
||||||
result = newAccountStateDB(self.db, stateRoot)
|
result = newAccountStateDB(self.db, stateRoot)
|
||||||
|
|
||||||
method genesisHash*(db: BaseChainDB): KeccakHash =
|
|
||||||
db.getBlockHash(0.toBlockNumber)
|
|
||||||
|
|
||||||
method getBlockHeader*(db: BaseChainDB, b: HashOrNum): BlockHeaderRef =
|
|
||||||
var h: BlockHeader
|
|
||||||
var ok = case b.isHash
|
|
||||||
of true:
|
|
||||||
db.getBlockHeader(b.hash, h)
|
|
||||||
else:
|
|
||||||
db.getBlockHeader(b.number, h)
|
|
||||||
|
|
||||||
if ok:
|
|
||||||
result.new()
|
|
||||||
result[] = h
|
|
||||||
|
|
||||||
method getBestBlockHeader*(self: BaseChainDB): BlockHeaderRef =
|
|
||||||
result.new()
|
|
||||||
result[] = self.getCanonicalHead()
|
|
||||||
|
|
||||||
method getSuccessorHeader*(db: BaseChainDB, h: BlockHeader): BlockHeaderRef =
|
|
||||||
let n = h.blockNumber + 1
|
|
||||||
var r: BlockHeader
|
|
||||||
if db.getBlockHeader(n, r):
|
|
||||||
result.new()
|
|
||||||
result[] = r
|
|
||||||
|
|
||||||
method getBlockBody*(db: BaseChainDB, blockHash: KeccakHash): BlockBodyRef =
|
|
||||||
result = nil
|
|
||||||
|
|
||||||
# Deprecated:
|
# Deprecated:
|
||||||
proc getBlockHeaderByHash*(self: BaseChainDB; blockHash: Hash256): BlockHeader {.deprecated.} =
|
proc getBlockHeaderByHash*(self: BaseChainDB; blockHash: Hash256): BlockHeader {.deprecated.} =
|
||||||
@ -288,3 +263,4 @@ proc lookupBlockHash*(self: BaseChainDB; n: BlockNumber): Hash256 {.deprecated.}
|
|||||||
|
|
||||||
proc getCanonicalBlockHeaderByNumber*(self: BaseChainDB; n: BlockNumber): BlockHeader {.deprecated.} =
|
proc getCanonicalBlockHeaderByNumber*(self: BaseChainDB; n: BlockNumber): BlockHeader {.deprecated.} =
|
||||||
self.getBlockHeader(n)
|
self.getBlockHeader(n)
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import
|
|||||||
os, strutils, net, eth_common, db/[storage_types, db_chain],
|
os, strutils, net, eth_common, db/[storage_types, db_chain],
|
||||||
asyncdispatch2, json_rpc/rpcserver, eth_keys,
|
asyncdispatch2, json_rpc/rpcserver, eth_keys,
|
||||||
eth_p2p, eth_p2p/rlpx_protocols/[eth, les],
|
eth_p2p, eth_p2p/rlpx_protocols/[eth, les],
|
||||||
config, genesis, rpc/[common, p2p],
|
config, genesis, rpc/[common, p2p], p2p/chain,
|
||||||
eth_trie
|
eth_trie
|
||||||
|
|
||||||
const UseSqlite = true
|
const UseSqlite = true
|
||||||
@ -85,10 +85,10 @@ proc start(): NimbusObject =
|
|||||||
nimbus.ethNode = newEthereumNode(keypair, address, conf.net.networkId,
|
nimbus.ethNode = newEthereumNode(keypair, address, conf.net.networkId,
|
||||||
nil, nimbusClientId)
|
nil, nimbusClientId)
|
||||||
|
|
||||||
nimbus.ethNode.chain = chainDB
|
nimbus.ethNode.chain = newChain(chainDB)
|
||||||
|
|
||||||
if RpcFlags.Enabled in conf.rpc.flags:
|
if RpcFlags.Enabled in conf.rpc.flags:
|
||||||
setupP2PRpc(nimbus.ethNode, nimbus.rpcServer)
|
setupEthRpc(nimbus.ethNode, chainDB, nimbus.rpcServer)
|
||||||
|
|
||||||
## Starting servers
|
## Starting servers
|
||||||
nimbus.state = Starting
|
nimbus.state = Starting
|
||||||
@ -101,10 +101,9 @@ proc start(): NimbusObject =
|
|||||||
waitFor nimbus.ethNode.connectToNetwork(conf.net.bootNodes)
|
waitFor nimbus.ethNode.connectToNetwork(conf.net.bootNodes)
|
||||||
|
|
||||||
# TODO: temp code until the CLI/RPC interface is fleshed out
|
# TODO: temp code until the CLI/RPC interface is fleshed out
|
||||||
if os.getenv("START_SYNC") == "1":
|
let status = waitFor nimbus.ethNode.fastBlockchainSync()
|
||||||
let status = waitFor nimbus.ethNode.fastBlockchainSync()
|
if status != syncSuccess:
|
||||||
if status != syncSuccess:
|
echo "Block sync failed: ", status
|
||||||
echo "Block sync failed: ", status
|
|
||||||
|
|
||||||
nimbus.state = Running
|
nimbus.state = Running
|
||||||
result = nimbus
|
result = nimbus
|
||||||
@ -119,8 +118,8 @@ proc process*(nimbus: NimbusObject) =
|
|||||||
proc signalBreak(udata: pointer) =
|
proc signalBreak(udata: pointer) =
|
||||||
nimbus.state = Stopping
|
nimbus.state = Stopping
|
||||||
# Adding SIGINT, SIGTERM handlers
|
# Adding SIGINT, SIGTERM handlers
|
||||||
discard addSignal(SIGINT, signalBreak)
|
# discard addSignal(SIGINT, signalBreak)
|
||||||
discard addSignal(SIGTERM, signalBreak)
|
# discard addSignal(SIGTERM, signalBreak)
|
||||||
|
|
||||||
# Main loop
|
# Main loop
|
||||||
while nimbus.state == Running:
|
while nimbus.state == Running:
|
||||||
|
51
nimbus/p2p/chain.nim
Normal file
51
nimbus/p2p/chain.nim
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import ../db/db_chain, eth_common, chronicles, ../vm_state, ../vm_types, ../transaction,
|
||||||
|
../vm/[computation, interpreter_dispatch, message]
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
Chain* = ref object of AbstractChainDB
|
||||||
|
db: BaseChainDB
|
||||||
|
|
||||||
|
proc newChain*(db: BaseChainDB): Chain =
|
||||||
|
result.new
|
||||||
|
result.db = db
|
||||||
|
|
||||||
|
method genesisHash*(c: Chain): KeccakHash =
|
||||||
|
c.db.getBlockHash(0.toBlockNumber)
|
||||||
|
|
||||||
|
method getBlockHeader*(c: Chain, b: HashOrNum, output: var BlockHeader): bool =
|
||||||
|
case b.isHash
|
||||||
|
of true:
|
||||||
|
c.db.getBlockHeader(b.hash, output)
|
||||||
|
else:
|
||||||
|
c.db.getBlockHeader(b.number, output)
|
||||||
|
|
||||||
|
method getBestBlockHeader*(c: Chain): BlockHeader =
|
||||||
|
c.db.getCanonicalHead()
|
||||||
|
|
||||||
|
method getSuccessorHeader*(c: Chain, h: BlockHeader, output: var BlockHeader): bool =
|
||||||
|
let n = h.blockNumber + 1
|
||||||
|
c.db.getBlockHeader(n, output)
|
||||||
|
|
||||||
|
method getBlockBody*(c: Chain, blockHash: KeccakHash): BlockBodyRef =
|
||||||
|
result = nil
|
||||||
|
|
||||||
|
method persistBlocks*(c: Chain, headers: openarray[BlockHeader], bodies: openarray[BlockBody]) =
|
||||||
|
# Run the VM here
|
||||||
|
assert(headers.len == bodies.len)
|
||||||
|
|
||||||
|
for i in 0 ..< headers.len:
|
||||||
|
let head = c.db.getCanonicalHead()
|
||||||
|
# assert(head.blockNumber == headers[i].blockNumber - 1)
|
||||||
|
let vmState = newBaseVMState(head, c.db)
|
||||||
|
if bodies[i].transactions.len != 0:
|
||||||
|
# echo "block: ", headers[i].blockNumber
|
||||||
|
for t in bodies[i].transactions:
|
||||||
|
var msg: Message
|
||||||
|
# echo "trns: ", t
|
||||||
|
|
||||||
|
# let msg = newMessage(t.gasLimit, t.gasPrice, t.to, t.getSender,
|
||||||
|
|
||||||
|
# let c = newBaseComputation(vmState,
|
||||||
|
|
||||||
|
discard
|
@ -93,22 +93,17 @@ func headerFromTag(chain:BaseChainDB, blockTag: string): BlockHeader =
|
|||||||
let blockNum = stint.fromHex(UInt256, tag)
|
let blockNum = stint.fromHex(UInt256, tag)
|
||||||
result = chain.getBlockHeader(blockNum)
|
result = chain.getBlockHeader(blockNum)
|
||||||
|
|
||||||
proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) =
|
||||||
template chain: untyped = BaseChainDB(node.chain) # TODO: Sensible casting
|
proc accountDbFromTag(tag: string, readOnly = true): AccountStateDb =
|
||||||
|
|
||||||
proc getAccountDb(readOnly = true): AccountStateDb =
|
|
||||||
## Retrieves the account db from canonical head
|
|
||||||
let
|
|
||||||
header = chain.getCanonicalHead()
|
|
||||||
vmState = newBaseVMState(header, chain)
|
|
||||||
result = vmState.chaindb.getStateDb(vmState.blockHeader.hash, readOnly)
|
|
||||||
|
|
||||||
proc getAccountDbFromTag(tag: string, readOnly = true): AccountStateDb =
|
|
||||||
let
|
let
|
||||||
header = chain.headerFromTag(tag)
|
header = chain.headerFromTag(tag)
|
||||||
vmState = newBaseVMState(header, chain)
|
vmState = newBaseVMState(header, chain)
|
||||||
result = vmState.chaindb.getStateDb(vmState.blockHeader.hash, readOnly)
|
result = vmState.chaindb.getStateDb(vmState.blockHeader.hash, readOnly)
|
||||||
|
|
||||||
|
proc getBlockBody(hash: KeccakHash): BlockBody =
|
||||||
|
if not chain.getBlockBody(hash, result):
|
||||||
|
raise newException(ValueError, "Cannot find hash")
|
||||||
|
|
||||||
rpcsrv.rpc("net_version") do() -> uint:
|
rpcsrv.rpc("net_version") do() -> uint:
|
||||||
let conf = getConfiguration()
|
let conf = getConfiguration()
|
||||||
result = conf.net.networkId
|
result = conf.net.networkId
|
||||||
@ -197,23 +192,15 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
|||||||
## data: hash of a block
|
## data: hash of a block
|
||||||
## Returns integer of the number of transactions in this block.
|
## Returns integer of the number of transactions in this block.
|
||||||
var hashData = strToHash(data.string)
|
var hashData = strToHash(data.string)
|
||||||
let body = chain.getBlockBody(hashData)
|
result = getBlockBody(hashData).transactions.len
|
||||||
if body == nil:
|
|
||||||
raise newException(ValueError, "Cannot find hash")
|
|
||||||
result = body.transactions.len
|
|
||||||
|
|
||||||
rpcsrv.rpc("eth_getBlockTransactionCountByNumber") do(quantityTag: string) -> int:
|
rpcsrv.rpc("eth_getBlockTransactionCountByNumber") do(quantityTag: string) -> int:
|
||||||
## Returns the number of transactions in a block matching the given block number.
|
## Returns the number of transactions in a block matching the given block number.
|
||||||
##
|
##
|
||||||
## data: integer of a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.
|
## data: integer of a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.
|
||||||
## Returns integer of the number of transactions in this block.
|
## Returns integer of the number of transactions in this block.
|
||||||
let
|
let header = chain.headerFromTag(quantityTag)
|
||||||
header = chain.headerFromTag(quantityTag)
|
result = getBlockBody(header.hash).transactions.len
|
||||||
accountDb = getAccountDbFromTag(quantityTag)
|
|
||||||
body = chain.getBlockBody(header.hash)
|
|
||||||
if body == nil:
|
|
||||||
raise newException(ValueError, "Cannot find hash")
|
|
||||||
result = body.transactions.len
|
|
||||||
|
|
||||||
rpcsrv.rpc("eth_getUncleCountByBlockHash") do(data: HexDataStr) -> int:
|
rpcsrv.rpc("eth_getUncleCountByBlockHash") do(data: HexDataStr) -> int:
|
||||||
## Returns the number of uncles in a block from a block matching the given block hash.
|
## Returns the number of uncles in a block from a block matching the given block hash.
|
||||||
@ -221,22 +208,15 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
|||||||
## data: hash of a block.
|
## data: hash of a block.
|
||||||
## Returns integer of the number of uncles in this block.
|
## Returns integer of the number of uncles in this block.
|
||||||
var hashData = strToHash(data.string)
|
var hashData = strToHash(data.string)
|
||||||
let body = chain.getBlockBody(hashData)
|
result = getBlockBody(hashData).uncles.len
|
||||||
if body == nil:
|
|
||||||
raise newException(ValueError, "Cannot find hash")
|
|
||||||
result = body.uncles.len
|
|
||||||
|
|
||||||
rpcsrv.rpc("eth_getUncleCountByBlockNumber") do(quantityTag: string) -> int:
|
rpcsrv.rpc("eth_getUncleCountByBlockNumber") do(quantityTag: string) -> int:
|
||||||
## Returns the number of uncles in a block from a block matching the given block number.
|
## Returns the number of uncles in a block from a block matching the given block number.
|
||||||
##
|
##
|
||||||
## quantityTag: integer of a block number, or the string "latest", "earliest" or "pending", see the default block parameter.
|
## quantityTag: integer of a block number, or the string "latest", "earliest" or "pending", see the default block parameter.
|
||||||
## Returns integer of uncles in this block.
|
## Returns integer of uncles in this block.
|
||||||
let
|
let header = chain.headerFromTag(quantityTag)
|
||||||
header = chain.headerFromTag(quantityTag)
|
result = getBlockBody(header.hash).uncles.len
|
||||||
body = chain.getBlockBody(header.hash)
|
|
||||||
if body == nil:
|
|
||||||
raise newException(ValueError, "Cannot find hash")
|
|
||||||
result = body.uncles.len
|
|
||||||
|
|
||||||
rpcsrv.rpc("eth_getCode") do(data: EthAddressStr, quantityTag: string) -> HexDataStr:
|
rpcsrv.rpc("eth_getCode") do(data: EthAddressStr, quantityTag: string) -> HexDataStr:
|
||||||
## Returns code at a given address.
|
## Returns code at a given address.
|
||||||
@ -303,7 +283,7 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
|||||||
## Returns the amount of gas used.
|
## Returns the amount of gas used.
|
||||||
discard
|
discard
|
||||||
|
|
||||||
func populateBlockObject(header: BlockHeader, blockBody: BlockBodyRef): BlockObject =
|
func populateBlockObject(header: BlockHeader, blockBody: BlockBody): BlockObject =
|
||||||
result.number = some(header.blockNumber)
|
result.number = some(header.blockNumber)
|
||||||
result.hash = some(header.hash)
|
result.hash = some(header.hash)
|
||||||
result.parentHash = header.parentHash
|
result.parentHash = header.parentHash
|
||||||
@ -344,10 +324,7 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
|||||||
let
|
let
|
||||||
h = data.string.strToHash
|
h = data.string.strToHash
|
||||||
header = chain.getBlockHeader(h)
|
header = chain.getBlockHeader(h)
|
||||||
body = chain.getBlockBody(h)
|
result = some(populateBlockObject(header, getBlockBody(h)))
|
||||||
if body == nil:
|
|
||||||
raise newException(ValueError, "Cannot find hash")
|
|
||||||
result = some(populateBlockObject(header, body))
|
|
||||||
|
|
||||||
rpcsrv.rpc("eth_getBlockByNumber") do(quantityTag: string, fullTransactions: bool) -> Option[BlockObject]:
|
rpcsrv.rpc("eth_getBlockByNumber") do(quantityTag: string, fullTransactions: bool) -> Option[BlockObject]:
|
||||||
## Returns information about a block by block number.
|
## Returns information about a block by block number.
|
||||||
@ -357,10 +334,7 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
|||||||
## Returns BlockObject or nil when no block was found.
|
## Returns BlockObject or nil when no block was found.
|
||||||
let
|
let
|
||||||
header = chain.headerFromTag(quantityTag)
|
header = chain.headerFromTag(quantityTag)
|
||||||
body = chain.getBlockBody(header.hash)
|
result = some(populateBlockObject(header, getBlockBody(header.hash)))
|
||||||
if body == nil:
|
|
||||||
raise newException(ValueError, "Cannot find hash")
|
|
||||||
result = some(populateBlockObject(header, body))
|
|
||||||
|
|
||||||
proc populateTransactionObject(transaction: Transaction, txIndex: int64, blockHeader: BlockHeader, blockHash: Hash256): TransactionObject =
|
proc populateTransactionObject(transaction: Transaction, txIndex: int64, blockHeader: BlockHeader, blockHash: Hash256): TransactionObject =
|
||||||
let
|
let
|
||||||
@ -393,10 +367,7 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
|||||||
txDetails = chain.getTransactionKey(h)
|
txDetails = chain.getTransactionKey(h)
|
||||||
header = chain.getBlockHeader(txDetails.blockNumber)
|
header = chain.getBlockHeader(txDetails.blockNumber)
|
||||||
blockHash = chain.getBlockHash(txDetails.blockNumber)
|
blockHash = chain.getBlockHash(txDetails.blockNumber)
|
||||||
body = chain.getBlockBody(blockHash)
|
transaction = getBlockBody(blockHash).transactions[txDetails.index]
|
||||||
if body == nil:
|
|
||||||
raise newException(ValueError, "Cannot find hash")
|
|
||||||
let transaction = body.transactions[txDetails.index]
|
|
||||||
populateTransactionObject(transaction, txDetails.index, header, blockHash)
|
populateTransactionObject(transaction, txDetails.index, header, blockHash)
|
||||||
|
|
||||||
rpcsrv.rpc("eth_getTransactionByBlockHashAndIndex") do(data: HexDataStr, quantity: int) -> TransactionObject:
|
rpcsrv.rpc("eth_getTransactionByBlockHashAndIndex") do(data: HexDataStr, quantity: int) -> TransactionObject:
|
||||||
@ -407,12 +378,8 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
|||||||
## Returns requested transaction information.
|
## Returns requested transaction information.
|
||||||
let
|
let
|
||||||
blockHash = data.string.strToHash()
|
blockHash = data.string.strToHash()
|
||||||
body = chain.getBlockBody(blockHash)
|
|
||||||
if body == nil:
|
|
||||||
raise newException(ValueError, "Cannot find hash")
|
|
||||||
let
|
|
||||||
header = chain.getBlockHeader(blockHash)
|
header = chain.getBlockHeader(blockHash)
|
||||||
transaction = body.transactions[quantity]
|
transaction = getBlockBody(blockHash).transactions[quantity]
|
||||||
populateTransactionObject(transaction, quantity, header, blockHash)
|
populateTransactionObject(transaction, quantity, header, blockHash)
|
||||||
|
|
||||||
rpcsrv.rpc("eth_getTransactionByBlockNumberAndIndex") do(quantityTag: string, quantity: int) -> TransactionObject:
|
rpcsrv.rpc("eth_getTransactionByBlockNumberAndIndex") do(quantityTag: string, quantity: int) -> TransactionObject:
|
||||||
@ -423,11 +390,7 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
|||||||
let
|
let
|
||||||
header = chain.headerFromTag(quantityTag)
|
header = chain.headerFromTag(quantityTag)
|
||||||
blockHash = header.hash
|
blockHash = header.hash
|
||||||
body = chain.getBlockBody(blockHash)
|
transaction = getBlockBody(blockHash).transactions[quantity]
|
||||||
if body == nil:
|
|
||||||
raise newException(ValueError, "Cannot find hash")
|
|
||||||
let
|
|
||||||
transaction = body.transactions[quantity]
|
|
||||||
populateTransactionObject(transaction, quantity, header, blockHash)
|
populateTransactionObject(transaction, quantity, header, blockHash)
|
||||||
|
|
||||||
proc populateReceipt(receipt: Receipt, cumulativeGas: GasInt, transaction: Transaction, txIndex: int, blockHeader: BlockHeader): ReceiptObject =
|
proc populateReceipt(receipt: Receipt, cumulativeGas: GasInt, transaction: Transaction, txIndex: int, blockHeader: BlockHeader): ReceiptObject =
|
||||||
@ -458,9 +421,7 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
|||||||
h = data.string.strToHash()
|
h = data.string.strToHash()
|
||||||
txDetails = chain.getTransactionKey(h)
|
txDetails = chain.getTransactionKey(h)
|
||||||
header = chain.getBlockHeader(txDetails.blockNumber)
|
header = chain.getBlockHeader(txDetails.blockNumber)
|
||||||
body = chain.getBlockBody(h)
|
body = getBlockBody(header.hash)
|
||||||
if body == nil:
|
|
||||||
raise newException(ValueError, "Cannot find hash")
|
|
||||||
var
|
var
|
||||||
idx = 0
|
idx = 0
|
||||||
cumulativeGas: GasInt
|
cumulativeGas: GasInt
|
||||||
@ -478,9 +439,7 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
|||||||
## Returns BlockObject or nil when no block was found.
|
## Returns BlockObject or nil when no block was found.
|
||||||
let
|
let
|
||||||
blockHash = data.string.strToHash()
|
blockHash = data.string.strToHash()
|
||||||
body = chain.getBlockBody(blockHash)
|
body = getBlockBody(blockHash)
|
||||||
if body == nil:
|
|
||||||
raise newException(ValueError, "Cannot find hash")
|
|
||||||
if quantity < 0 or quantity >= body.uncles.len:
|
if quantity < 0 or quantity >= body.uncles.len:
|
||||||
raise newException(ValueError, "Uncle index out of range")
|
raise newException(ValueError, "Uncle index out of range")
|
||||||
let uncle = body.uncles[quantity]
|
let uncle = body.uncles[quantity]
|
||||||
@ -494,9 +453,7 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
|||||||
## Returns BlockObject or nil when no block was found.
|
## Returns BlockObject or nil when no block was found.
|
||||||
let
|
let
|
||||||
header = chain.headerFromTag(quantityTag)
|
header = chain.headerFromTag(quantityTag)
|
||||||
body = chain.getBlockBody(header.hash)
|
body = getBlockBody(header.hash)
|
||||||
if body == nil:
|
|
||||||
raise newException(ValueError, "Cannot find hash")
|
|
||||||
if quantity < 0 or quantity >= body.uncles.len:
|
if quantity < 0 or quantity >= body.uncles.len:
|
||||||
raise newException(ValueError, "Uncle index out of range")
|
raise newException(ValueError, "Uncle index out of range")
|
||||||
let uncle = body.uncles[quantity]
|
let uncle = body.uncles[quantity]
|
||||||
|
@ -60,7 +60,7 @@ proc doTests =
|
|||||||
rpcServer = newRpcSocketServer(["localhost:8545"])
|
rpcServer = newRpcSocketServer(["localhost:8545"])
|
||||||
client = newRpcSocketClient()
|
client = newRpcSocketClient()
|
||||||
setupCommonRpc(rpcServer)
|
setupCommonRpc(rpcServer)
|
||||||
setupP2PRpc(ethNode, rpcServer)
|
setupEthRpc(ethNode, chain, rpcServer)
|
||||||
|
|
||||||
# Begin tests
|
# Begin tests
|
||||||
rpcServer.start()
|
rpcServer.start()
|
||||||
@ -79,4 +79,4 @@ proc doTests =
|
|||||||
rpcServer.stop()
|
rpcServer.stop()
|
||||||
rpcServer.close()
|
rpcServer.close()
|
||||||
|
|
||||||
doTests()
|
doTests()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user