github.com/onflow/flow-go@v0.33.17/fvm/evm/types/state.go (about) 1 package types 2 3 import ( 4 "math/big" 5 6 gethCommon "github.com/ethereum/go-ethereum/common" 7 gethTypes "github.com/ethereum/go-ethereum/core/types" 8 gethVM "github.com/ethereum/go-ethereum/core/vm" 9 ) 10 11 // StateDB acts as the main interface to the EVM runtime 12 type StateDB interface { 13 gethVM.StateDB 14 15 // Commit commits the changes 16 Commit() error 17 18 // Logs collects and prepares logs 19 Logs( 20 blockHash gethCommon.Hash, 21 blockNumber uint64, 22 txHash gethCommon.Hash, 23 txIndex uint, 24 ) []*gethTypes.Log 25 26 // returns a map of preimages 27 Preimages() map[gethCommon.Hash][]byte 28 } 29 30 // ReadOnlyView provides a readonly view of the state 31 type ReadOnlyView interface { 32 // Exist returns true if the address exist in the state 33 Exist(gethCommon.Address) (bool, error) 34 // IsCreated returns true if address has been created in this tx 35 IsCreated(gethCommon.Address) bool 36 // HasSelfDestructed returns true if an address has self destructed 37 // it also returns the balance of address before selfdestruction call 38 HasSelfDestructed(gethCommon.Address) (bool, *big.Int) 39 // GetBalance returns the balance of an address 40 GetBalance(gethCommon.Address) (*big.Int, error) 41 // GetNonce returns the nonce of an address 42 GetNonce(gethCommon.Address) (uint64, error) 43 // GetCode returns the code of an address 44 GetCode(gethCommon.Address) ([]byte, error) 45 // GetCodeHash returns the code hash of an address 46 GetCodeHash(gethCommon.Address) (gethCommon.Hash, error) 47 // GetCodeSize returns the code size of an address 48 GetCodeSize(gethCommon.Address) (int, error) 49 // GetState returns values for an slot in the main storage 50 GetState(SlotAddress) (gethCommon.Hash, error) 51 // GetTransientState returns values for an slot transient storage 52 GetTransientState(SlotAddress) gethCommon.Hash 53 // GetRefund returns the total amount of (gas) refund 54 GetRefund() uint64 55 // AddressInAccessList checks if an address is in the access list 56 AddressInAccessList(gethCommon.Address) bool 57 // SlotInAccessList checks if a slot is in the access list 58 SlotInAccessList(SlotAddress) (addressOk bool, slotOk bool) 59 } 60 61 // HotView captures a high-level mutable view of the state 62 type HotView interface { 63 ReadOnlyView 64 65 // CreateAccount creates a new account 66 CreateAccount(gethCommon.Address) error 67 // SelfDestruct set the flag for destruction of the account after execution 68 SelfDestruct(gethCommon.Address) error 69 70 // SubBalance subtracts the amount from the balance the given address 71 SubBalance(gethCommon.Address, *big.Int) error 72 // AddBalance adds the amount to the balance of the given address 73 AddBalance(gethCommon.Address, *big.Int) error 74 // SetNonce sets the nonce for the given address 75 SetNonce(gethCommon.Address, uint64) error 76 // SetCode sets the code for the given address 77 SetCode(gethCommon.Address, []byte) error 78 79 // SetState sets a value for the given slot in the main storage 80 SetState(SlotAddress, gethCommon.Hash) error 81 // SetTransientState sets a value for the given slot in the transient storage 82 SetTransientState(SlotAddress, gethCommon.Hash) 83 84 // AddRefund adds the amount to the total (gas) refund 85 AddRefund(uint64) error 86 // SubRefund subtracts the amount from the total (gas) refund 87 SubRefund(uint64) error 88 89 // AddAddressToAccessList adds an address to the per-transaction access list 90 AddAddressToAccessList(addr gethCommon.Address) (addressAdded bool) 91 // AddSlotToAccessList adds a slot to the per-transaction access list 92 AddSlotToAccessList(SlotAddress) (addressAdded, slotAdded bool) 93 94 // AddLog append a log to the log collection 95 AddLog(*gethTypes.Log) 96 // AddPreimage adds a preimage to the list of preimages (input -> hash mapping) 97 AddPreimage(gethCommon.Hash, []byte) 98 } 99 100 // BaseView is a low-level mutable view of the state 101 // baseview is usually updated at the commit calls to the higher level view 102 type BaseView interface { 103 ReadOnlyView 104 105 // Creates a new account 106 CreateAccount( 107 addr gethCommon.Address, 108 balance *big.Int, 109 nonce uint64, 110 code []byte, 111 codeHash gethCommon.Hash, 112 ) error 113 114 // UpdateAccount updates a account 115 UpdateAccount( 116 addr gethCommon.Address, 117 balance *big.Int, 118 nonce uint64, 119 code []byte, 120 codeHash gethCommon.Hash, 121 ) error 122 123 // DeleteAccount deletes an account 124 DeleteAccount(addr gethCommon.Address) error 125 126 // UpdateSlot updates the value for the given slot in the main storage 127 UpdateSlot( 128 slot SlotAddress, 129 value gethCommon.Hash, 130 ) error 131 132 // Commit commits the changes 133 Commit() error 134 } 135 136 // SlotAddress captures an address to a storage slot 137 type SlotAddress struct { 138 Address gethCommon.Address 139 Key gethCommon.Hash 140 }