github.com/annchain/OG@v0.0.9/vm/types/state_object.go (about)

     1  package types
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/annchain/OG/arefactor/og/types"
     6  	"math/big"
     7  )
     8  
     9  type Storage map[types.Hash]types.Hash
    10  
    11  type StateObject struct {
    12  	Balance     *big.Int
    13  	Nonce       uint64
    14  	Code        []byte
    15  	CodeHash    types.Hash
    16  	Suicided    bool
    17  	Version     int
    18  	dirtyStates Storage
    19  	DirtyCode   bool
    20  	DirtySO     bool
    21  }
    22  
    23  func (s *StateObject) String() string {
    24  	return fmt.Sprintf("Balance %s Nonce %d CodeLen: %d CodeHash: %s States: %d Version: %d", s.Balance, s.Nonce, len(s.Code), s.CodeHash.String(), len(s.dirtyStates), s.Version)
    25  }
    26  
    27  func (s *StateObject) Empty() bool {
    28  	return s.DirtySO == false && len(s.dirtyStates) != 0
    29  }
    30  func (s *StateObject) Copy() (d *StateObject) {
    31  	d = NewStateObject()
    32  	d.Balance = s.Balance
    33  	d.Nonce = s.Nonce
    34  	d.Code = s.Code
    35  	d.CodeHash = s.CodeHash
    36  	d.Suicided = s.Suicided
    37  	d.DirtySO = false
    38  	d.dirtyStates = make(map[types.Hash]types.Hash)
    39  	for k, v := range s.dirtyStates {
    40  		d.dirtyStates[types.BytesToHash(k.Bytes[:])] = types.BytesToHash(v.Bytes[:])
    41  	}
    42  
    43  	d.Version = s.Version + 1
    44  	return d
    45  }
    46  
    47  func NewStateObject() *StateObject {
    48  	return &StateObject{
    49  		Balance:     big.NewInt(0),
    50  		dirtyStates: make(map[types.Hash]types.Hash),
    51  	}
    52  }
    53  
    54  func NewStorage() Storage {
    55  	a := make(map[types.Hash]types.Hash)
    56  	return a
    57  }