address review comments
This commit is contained in:
parent
d902be66ee
commit
350188bd29
|
@ -92,8 +92,6 @@ proc setStorage*(db: var AccountStateDB,
|
|||
db.setAccount(address, account)
|
||||
|
||||
proc getStorage*(db: AccountStateDB, address: EthAddress, slot: UInt256): (UInt256, bool) =
|
||||
#validateGte(slot, 0, title="Storage Slot")
|
||||
|
||||
let
|
||||
account = db.getAccount(address)
|
||||
slotAsKey = createTrieKeyFromSlot slot
|
||||
|
@ -107,17 +105,13 @@ proc getStorage*(db: AccountStateDB, address: EthAddress, slot: UInt256): (UInt2
|
|||
else:
|
||||
result = (0.u256, false)
|
||||
|
||||
proc setNonce*(db: var AccountStateDB, address: EthAddress, nonce: UInt256) =
|
||||
#validateGte(nonce, 0, title="Nonce")
|
||||
|
||||
proc setNonce*(db: var AccountStateDB, address: EthAddress, newNonce: UInt256) =
|
||||
var account = db.getAccount(address)
|
||||
account.nonce = nonce
|
||||
|
||||
if newNonce != account.nonce:
|
||||
account.nonce = newNonce
|
||||
db.setAccount(address, account)
|
||||
|
||||
proc getNonce*(db: AccountStateDB, address: EthAddress): UInt256 =
|
||||
# TODO it is very strange that we require a var param here
|
||||
|
||||
let account = db.getAccount(address)
|
||||
account.nonce
|
||||
|
||||
|
@ -127,9 +121,10 @@ proc toByteRange_Unnecessary*(h: KeccakHash): ByteRange =
|
|||
return s.toRange
|
||||
|
||||
proc setCode*(db: var AccountStateDB, address: EthAddress, code: ByteRange) =
|
||||
|
||||
var account = db.getAccount(address)
|
||||
account.codeHash = keccak256.digest code.toOpenArray
|
||||
let newCodeHash = keccak256.digest code.toOpenArray
|
||||
if newCodeHash != account.codeHash:
|
||||
account.codeHash = newCodeHash
|
||||
# XXX: this uses the journaldb in py-evm
|
||||
db.trie.put(account.codeHash.toByteRange_Unnecessary, code)
|
||||
db.setAccount(address, account)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import db/[db_chain, state_db], genesis_alloc, eth_common, tables, stint,
|
||||
byteutils, times, config, rlp, ranges, block_types, eth_trie,
|
||||
eth_trie/memdb, constants, nimcrypto, chronicles
|
||||
eth_trie/memdb, account, constants, nimcrypto, chronicles
|
||||
|
||||
type
|
||||
Genesis* = object
|
||||
|
@ -69,18 +69,12 @@ proc toBlock*(g: Genesis): BlockHeader =
|
|||
var sdb = newAccountStateDB(tdb, trie.rootHash)
|
||||
|
||||
for address, account in g.alloc:
|
||||
sdb.setBalance(address, account.balance)
|
||||
|
||||
when false:
|
||||
# These properties are empty in all genesis blocks so far
|
||||
sdb.setAccount(address, newAccount(account.nonce, account.balance))
|
||||
sdb.setCode(address, account.code.toRange)
|
||||
sdb.setNonce(address, account.nonce)
|
||||
|
||||
for k, v in account.storage:
|
||||
sdb.setStorage(address, k, v)
|
||||
|
||||
var root = sdb.rootHash
|
||||
doAssert $root == "D7F8974FB5AC78D9AC099B9AD5018BEDC2CE0A72DAD1827A1709DA30580F0544"
|
||||
|
||||
result = BlockHeader(
|
||||
nonce: g.nonce,
|
||||
|
|
Loading…
Reference in New Issue