class Ethereum::Account
An Ethereum
account.
-
`@nonce`: the account's nonce (the number of transactions sent by the account)
-
`@balance`: the account's balance in wei
-
`@storage`: the root of the account's storage trie
-
`@code_hash`: the SHA3 hash of the code associated with the account
-
`@db`: the database in which the account's code is stored
Public Class Methods
build_blank(db, initial_nonce=0)
click to toggle source
Create a blank account.
The returned account will have zero nonce and balance, a blank storage trie and empty code.
@param db [BaseDB] the db in which the account will store its code
@return [Account] the created blank account
# File lib/ethereum/account.rb, line 35 def build_blank(db, initial_nonce=0) code_hash = Utils.keccak256 Constant::BYTE_EMPTY db.put code_hash, Constant::BYTE_EMPTY new initial_nonce, 0, Trie::BLANK_ROOT, code_hash, db end
new(*args)
click to toggle source
Calls superclass method
# File lib/ethereum/account.rb, line 43 def initialize(*args) @db = args.pop if args.size == 5 # (nonce, balance, storage, code_hash, db) @db = args.last.delete(:db) if args.last.is_a?(Hash) raise ArgumentError, "No database object given" unless @db.is_a?(DB::BaseDB) super(*args) end
Public Instance Methods
code()
click to toggle source
The EVM code of the account.
This property will be read from or written to the db at each access, with `code_hash` used as key.
# File lib/ethereum/account.rb, line 57 def code @db.get code_hash end
code=(value)
click to toggle source
# File lib/ethereum/account.rb, line 61 def code=(value) self.code_hash = Utils.keccak256 value # Technically a db storage leak, but doesn't really matter; the only # thing that fails to get garbage collected is when code disappears due # to a suicide. @db.inc_refcount(code_hash, value) end