@ -56,13 +56,13 @@ func (storage Storage) Copy() Storage {
return cpy
}
// state Object represents an Ethereum account which is being modified.
// Object represents an Ethereum account which is being modified.
//
// The usage pattern is as follows:
// First you need to obtain a state object.
// Account values can be accessed and modified through the object.
// Finally, call CommitTrie to write the modified storage trie into a database.
type state Object struct {
type Object struct {
address common . Address
addrHash common . Hash // hash of ethereum address of the account
data Account
@ -91,7 +91,7 @@ type stateObject struct {
}
// empty returns whether the account is considered empty.
func ( s * state Object) empty ( ) bool {
func ( s * Object ) empty ( ) bool {
return s . data . Nonce == 0 && s . data . Balance . Sign ( ) == 0 && bytes . Equal ( s . data . CodeHash , emptyCodeHash )
}
@ -105,14 +105,14 @@ type Account struct {
}
// newObject creates a state object.
func newObject ( db * DB , address common . Address , data Account ) * state Object {
func newObject ( db * DB , address common . Address , data Account ) * Object {
if data . Balance == nil {
data . Balance = new ( big . Int )
}
if data . CodeHash == nil {
data . CodeHash = emptyCodeHash
}
return & state Object{
return & Object {
db : db ,
address : address ,
addrHash : crypto . Keccak256Hash ( address [ : ] ) ,
@ -123,22 +123,22 @@ func newObject(db *DB, address common.Address, data Account) *stateObject {
}
// EncodeRLP implements rlp.Encoder.
func ( s * state Object) EncodeRLP ( w io . Writer ) error {
func ( s * Object ) EncodeRLP ( w io . Writer ) error {
return rlp . Encode ( w , s . data )
}
// setError remembers the first non-nil error it is called with.
func ( s * state Object) setError ( err error ) {
func ( s * Object ) setError ( err error ) {
if s . dbErr == nil {
s . dbErr = err
}
}
func ( s * state Object) markSuicided ( ) {
func ( s * Object ) markSuicided ( ) {
s . suicided = true
}
func ( s * state Object) touch ( ) {
func ( s * Object ) touch ( ) {
s . db . journal . append ( touchChange {
account : & s . address ,
} )
@ -149,7 +149,7 @@ func (s *stateObject) touch() {
}
}
func ( s * state Object) getTrie ( db Database ) Trie {
func ( s * Object ) getTrie ( db Database ) Trie {
if s . trie == nil {
var err error
s . trie , err = db . OpenStorageTrie ( s . addrHash , s . data . Root )
@ -162,7 +162,7 @@ func (s *stateObject) getTrie(db Database) Trie {
}
// GetState retrieves a value from the account storage trie.
func ( s * state Object) GetState ( db Database , key common . Hash ) common . Hash {
func ( s * Object ) GetState ( db Database , key common . Hash ) common . Hash {
// If we have a dirty value for this state entry, return it
value , dirty := s . dirtyStorage [ key ]
if dirty {
@ -173,7 +173,7 @@ func (s *stateObject) GetState(db Database, key common.Hash) common.Hash {
}
// GetCommittedState retrieves a value from the committed account storage trie.
func ( s * state Object) GetCommittedState ( db Database , key common . Hash ) common . Hash {
func ( s * Object ) GetCommittedState ( db Database , key common . Hash ) common . Hash {
// If we have the original value cached, return that
value , cached := s . originStorage [ key ]
if cached {
@ -197,7 +197,7 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
}
// SetState updates a value in account storage.
func ( s * state Object) SetState ( db Database , key , value common . Hash ) {
func ( s * Object ) SetState ( db Database , key , value common . Hash ) {
// If the new value is the same as old, don't set
prev := s . GetState ( db , key )
if prev == value {
@ -212,12 +212,12 @@ func (s *stateObject) SetState(db Database, key, value common.Hash) {
s . setState ( key , value )
}
func ( s * state Object) setState ( key , value common . Hash ) {
func ( s * Object ) setState ( key , value common . Hash ) {
s . dirtyStorage [ key ] = value
}
// updateTrie writes cached storage modifications into the object's storage trie.
func ( s * state Object) updateTrie ( db Database ) Trie {
func ( s * Object ) updateTrie ( db Database ) Trie {
tr := s . getTrie ( db )
for key , value := range s . dirtyStorage {
delete ( s . dirtyStorage , key )
@ -240,14 +240,14 @@ func (s *stateObject) updateTrie(db Database) Trie {
}
// UpdateRoot sets the trie root to the current root hash of
func ( s * state Object) updateRoot ( db Database ) {
func ( s * Object ) updateRoot ( db Database ) {
s . updateTrie ( db )
s . data . Root = s . trie . Hash ( )
}
// CommitTrie the storage trie of the object to db.
// This updates the trie root.
func ( s * state Object) CommitTrie ( db Database ) error {
func ( s * Object ) CommitTrie ( db Database ) error {
s . updateTrie ( db )
if s . dbErr != nil {
return s . dbErr
@ -261,7 +261,7 @@ func (s *stateObject) CommitTrie(db Database) error {
// AddBalance removes amount from c's balance.
// It is used to add funds to the destination account of a transfer.
func ( s * state Object) AddBalance ( amount * big . Int ) {
func ( s * Object ) AddBalance ( amount * big . Int ) {
// EIP158: We must check emptiness for the objects such that the account
// clearing (0,0,0 objects) can take effect.
if amount . Sign ( ) == 0 {
@ -276,14 +276,14 @@ func (s *stateObject) AddBalance(amount *big.Int) {
// SubBalance removes amount from c's balance.
// It is used to remove funds from the origin account of a transfer.
func ( s * state Object) SubBalance ( amount * big . Int ) {
func ( s * Object ) SubBalance ( amount * big . Int ) {
if amount . Sign ( ) == 0 {
return
}
s . SetBalance ( new ( big . Int ) . Sub ( s . Balance ( ) , amount ) )
}
func ( s * state Object) SetBalance ( amount * big . Int ) {
func ( s * Object ) SetBalance ( amount * big . Int ) {
s . db . journal . append ( balanceChange {
account : & s . address ,
prev : new ( big . Int ) . Set ( s . data . Balance ) ,
@ -291,14 +291,14 @@ func (s *stateObject) SetBalance(amount *big.Int) {
s . setBalance ( amount )
}
func ( s * state Object) setBalance ( amount * big . Int ) {
func ( s * Object ) setBalance ( amount * big . Int ) {
s . data . Balance = amount
}
// Return the gas back to the origin. Used by the Virtual machine or Closures
func ( s * state Object) ReturnGas ( gas * big . Int ) { }
func ( s * Object ) ReturnGas ( gas * big . Int ) { }
func ( s * state Object) deepCopy ( db * DB ) * state Object {
func ( s * Object ) deepCopy ( db * DB ) * Object {
stateObject := newObject ( db , s . address , s . data )
if s . trie != nil {
stateObject . trie = db . db . CopyTrie ( s . trie )
@ -317,12 +317,12 @@ func (s *stateObject) deepCopy(db *DB) *stateObject {
//
// Returns the address of the contract/account
func ( s * state Object) Address ( ) common . Address {
func ( s * Object ) Address ( ) common . Address {
return s . address
}
// Code returns the contract code associated with this object, if any.
func ( s * state Object) Code ( db Database ) [ ] byte {
func ( s * Object ) Code ( db Database ) [ ] byte {
if s . code != nil {
return s . code
}
@ -337,7 +337,7 @@ func (s *stateObject) Code(db Database) []byte {
return code
}
func ( s * state Object) SetCode ( codeHash common . Hash , code [ ] byte ) {
func ( s * Object ) SetCode ( codeHash common . Hash , code [ ] byte ) {
prevcode := s . Code ( s . db . db )
s . db . journal . append ( codeChange {
account : & s . address ,
@ -347,13 +347,13 @@ func (s *stateObject) SetCode(codeHash common.Hash, code []byte) {
s . setCode ( codeHash , code )
}
func ( s * state Object) setCode ( codeHash common . Hash , code [ ] byte ) {
func ( s * Object ) setCode ( codeHash common . Hash , code [ ] byte ) {
s . code = code
s . data . CodeHash = codeHash [ : ]
s . dirtyCode = true
}
func ( s * state Object) SetNonce ( nonce uint64 ) {
func ( s * Object ) SetNonce ( nonce uint64 ) {
s . db . journal . append ( nonceChange {
account : & s . address ,
prev : s . data . Nonce ,
@ -361,25 +361,25 @@ func (s *stateObject) SetNonce(nonce uint64) {
s . setNonce ( nonce )
}
func ( s * state Object) setNonce ( nonce uint64 ) {
func ( s * Object ) setNonce ( nonce uint64 ) {
s . data . Nonce = nonce
}
func ( s * state Object) CodeHash ( ) [ ] byte {
func ( s * Object ) CodeHash ( ) [ ] byte {
return s . data . CodeHash
}
func ( s * state Object) Balance ( ) * big . Int {
func ( s * Object ) Balance ( ) * big . Int {
return s . data . Balance
}
func ( s * state Object) Nonce ( ) uint64 {
func ( s * Object ) Nonce ( ) uint64 {
return s . data . Nonce
}
// Never called, but must be present to allow state Object to be used
// Never called, but must be present to allow Object to be used
// as a vm.Account interface that also satisfies the vm.ContractRef
// interface. Interfaces are awesome.
func ( s * state Object) Value ( ) * big . Int {
panic ( "Value on state Object should never be called" )
func ( s * Object ) Value ( ) * big . Int {
panic ( "Value on Object should never be called" )
}