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

     1  package types
     2  
     3  import (
     4  	ogTypes "github.com/annchain/OG/arefactor/og_interface"
     5  	"github.com/annchain/OG/common/math"
     6  )
     7  
     8  // StateDB is an OVM database for full state querying.
     9  type StateDB interface {
    10  	CreateAccount(ogTypes.Address)
    11  
    12  	SubBalance(ogTypes.Address, *math.BigInt)
    13  	AddBalance(ogTypes.Address, *math.BigInt)
    14  	// Retrieve the balance from the given address or 0 if object not found
    15  	GetBalance(ogTypes.Address) *math.BigInt
    16  
    17  	GetNonce(ogTypes.Address) uint64
    18  	SetNonce(ogTypes.Address, uint64)
    19  
    20  	GetCodeHash(ogTypes.Address) ogTypes.Hash
    21  	GetCode(ogTypes.Address) []byte
    22  	SetCode(ogTypes.Address, []byte)
    23  	GetCodeSize(ogTypes.Address) int
    24  
    25  	// AddRefund adds gas to the refund counter
    26  	AddRefund(uint64)
    27  	// SubRefund removes gas from the refund counter.
    28  	// This method will panic if the refund counter goes below zero
    29  	SubRefund(uint64)
    30  	// GetRefund returns the current value of the refund counter.
    31  	GetRefund() uint64
    32  
    33  	GetCommittedState(ogTypes.Address, ogTypes.Hash) ogTypes.Hash
    34  	// GetState retrieves a value from the given account's storage trie.
    35  	GetState(ogTypes.Address, ogTypes.Hash) ogTypes.Hash
    36  	SetState(ogTypes.Address, ogTypes.Hash, ogTypes.Hash)
    37  
    38  	// Suicide marks the given account as suicided.
    39  	// This clears the account balance.
    40  	//
    41  	// The account's state object is still available until the state is committed,
    42  	// getStateObject will return a non-nil account after Suicide.
    43  	Suicide(ogTypes.Address) bool
    44  	HasSuicided(ogTypes.Address) bool
    45  
    46  	// IsAddressExists reports whether the given account exists in state.
    47  	// Notably this should also return true for suicided accounts.
    48  	Exist(ogTypes.Address) bool
    49  	// Empty returns whether the given account is empty. Empty
    50  	// is defined according to EIP161 (balance = nonce = code = 0).
    51  	Empty(ogTypes.Address) bool
    52  
    53  	// RevertToSnapshot reverts all state changes made since the given revision.
    54  	RevertToSnapshot(int)
    55  	// Snapshot creates a new revision
    56  	Snapshot() int
    57  
    58  	AddLog(*Log)
    59  	AddPreimage(ogTypes.Hash, []byte)
    60  
    61  	ForEachStorage(ogTypes.Address, func(ogTypes.Hash, ogTypes.Hash) bool)
    62  	// for debug.
    63  	String() string
    64  
    65  	// GetStateObject(addr ogTypes.Address) StateObjectInterface
    66  	// SetStateObject(addr ogTypes.Address, stateObject StateObjectInterface)
    67  }
    68  
    69  //// StateDBDebug is a temp inferface for layerdb debug.
    70  //type StateDBDebug interface {
    71  //	CreateAccount(ogTypes.Address)
    72  //
    73  //	SubBalance(ogTypes.Address, *math.BigInt)
    74  //	AddBalance(ogTypes.Address, *math.BigInt)
    75  //	// Retrieve the balance from the given address or 0 if object not found
    76  //	GetBalance(ogTypes.Address) *math.BigInt
    77  //
    78  //	GetNonce(ogTypes.Address) uint64
    79  //	SetNonce(ogTypes.Address, uint64)
    80  //
    81  //	GetCodeHash(ogTypes.Address) ogTypes.Hash
    82  //	GetCode(ogTypes.Address) []byte
    83  //	SetCode(ogTypes.Address, []byte)
    84  //	GetCodeSize(ogTypes.Address) int
    85  //
    86  //	// AddRefund adds gas to the refund counter
    87  //	AddRefund(uint64)
    88  //	// SubRefund removes gas from the refund counter.
    89  //	// This method will panic if the refund counter goes below zero
    90  //	SubRefund(uint64)
    91  //	// GetRefund returns the current value of the refund counter.
    92  //	GetRefund() uint64
    93  //
    94  //	GetCommittedState(ogTypes.Address, ogTypes.Hash) ogTypes.Hash
    95  //	// GetState retrieves a value from the given account's storage trie.
    96  //	GetState(ogTypes.Address, ogTypes.Hash) ogTypes.Hash
    97  //	SetState(ogTypes.Address, ogTypes.Hash, ogTypes.Hash)
    98  //
    99  //	// Suicide marks the given account as suicided.
   100  //	// This clears the account balance.
   101  //	//
   102  //	// The account's state object is still available until the state is committed,
   103  //	// getStateObject will return a non-nil account after Suicide.
   104  //	Suicide(ogTypes.Address) bool
   105  //	HasSuicided(ogTypes.Address) bool
   106  //
   107  //	// IsAddressExists reports whether the given account exists in state.
   108  //	// Notably this should also return true for suicided accounts.
   109  //	Exist(ogTypes.Address) bool
   110  //	// Empty returns whether the given account is empty. Empty
   111  //	// is defined according to EIP161 (balance = nonce = code = 0).
   112  //	Empty(ogTypes.Address) bool
   113  //
   114  //	// RevertToSnapshot reverts all state changes made since the given revision.
   115  //	RevertToSnapshot(int)
   116  //	// Snapshot creates a new revision
   117  //	Snapshot() int
   118  //
   119  //	AddLog(*Log)
   120  //	AddPreimage(ogTypes.Hash, []byte)
   121  //
   122  //	ForEachStorage(ogTypes.Address, func(ogTypes.Hash, ogTypes.Hash) bool)
   123  //	// for debug.
   124  //	String() string
   125  //
   126  //	GetStateObject(addr ogTypes.Address) *StateObject
   127  //	SetStateObject(addr ogTypes.Address, stateObject *StateObject)
   128  //}