Documentation ¶
Index ¶
- Constants
- Variables
- func CanTransfer(db vm.StateDB, fromHash common.Address, balance *big.Int) bool
- func ExecuteContract(ctx context.Context, sm protocol.StateManager, execution *action.Execution, ...) ([]byte, *action.Receipt, error)
- func MakeTransfer(db vm.StateDB, fromHash, toHash common.Address, amount *big.Int)
- func ReadContractStorage(ctx context.Context, sm protocol.StateManager, contract address.Address, ...) ([]byte, error)
- func SimulateExecution(ctx context.Context, sm protocol.StateManager, caller address.Address, ...) ([]byte, *action.Receipt, error)
- type Contract
- type DepositGasWithSGD
- type GetBlockHash
- type Params
- type SGDRegistry
- type StateDBAdapter
- func (stateDB *StateDBAdapter) AddAddressToAccessList(addr common.Address)
- func (stateDB *StateDBAdapter) AddBalance(evmAddr common.Address, amount *big.Int)
- func (stateDB *StateDBAdapter) AddLog(evmLog *types.Log)
- func (stateDB *StateDBAdapter) AddPreimage(hash common.Hash, preimage []byte)
- func (stateDB *StateDBAdapter) AddRefund(gas uint64)
- func (stateDB *StateDBAdapter) AddSlotToAccessList(addr common.Address, slot common.Hash)
- func (stateDB *StateDBAdapter) AddressInAccessList(addr common.Address) bool
- func (stateDB *StateDBAdapter) CommitContracts() error
- func (stateDB *StateDBAdapter) CreateAccount(evmAddr common.Address)
- func (stateDB *StateDBAdapter) Empty(evmAddr common.Address) bool
- func (stateDB *StateDBAdapter) Error() error
- func (stateDB *StateDBAdapter) Exist(evmAddr common.Address) bool
- func (stateDB *StateDBAdapter) ForEachStorage(addr common.Address, cb func(common.Hash, common.Hash) bool) error
- func (stateDB *StateDBAdapter) GetBalance(evmAddr common.Address) *big.Int
- func (stateDB *StateDBAdapter) GetCode(evmAddr common.Address) []byte
- func (stateDB *StateDBAdapter) GetCodeHash(evmAddr common.Address) common.Hash
- func (stateDB *StateDBAdapter) GetCodeSize(evmAddr common.Address) int
- func (stateDB *StateDBAdapter) GetCommittedState(evmAddr common.Address, k common.Hash) common.Hash
- func (stateDB *StateDBAdapter) GetNonce(evmAddr common.Address) uint64
- func (stateDB *StateDBAdapter) GetRefund() uint64
- func (stateDB *StateDBAdapter) GetState(evmAddr common.Address, k common.Hash) common.Hash
- func (stateDB *StateDBAdapter) HasSuicided(evmAddr common.Address) bool
- func (stateDB *StateDBAdapter) IsNewAccount(evmAddr common.Address) bool
- func (stateDB *StateDBAdapter) Logs() []*action.Log
- func (stateDB *StateDBAdapter) PrepareAccessList(sender common.Address, dst *common.Address, precompiles []common.Address, ...)
- func (stateDB *StateDBAdapter) RevertToSnapshot(snapshot int)
- func (stateDB *StateDBAdapter) SetCode(evmAddr common.Address, code []byte)
- func (stateDB *StateDBAdapter) SetNonce(evmAddr common.Address, nonce uint64)
- func (stateDB *StateDBAdapter) SetState(evmAddr common.Address, k, v common.Hash)
- func (stateDB *StateDBAdapter) SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool)
- func (stateDB *StateDBAdapter) Snapshot() int
- func (stateDB *StateDBAdapter) SubBalance(evmAddr common.Address, amount *big.Int)
- func (stateDB *StateDBAdapter) SubRefund(gas uint64)
- func (stateDB *StateDBAdapter) Suicide(evmAddr common.Address) bool
- func (stateDB *StateDBAdapter) TransactionLogs() []*action.TransactionLog
- type StateDBAdapterOption
- func AsyncContractTrieOption() StateDBAdapterOption
- func DisableSortCachedContractsOption() StateDBAdapterOption
- func FixSnapshotOrderOption() StateDBAdapterOption
- func LegacyNonceAccountOption() StateDBAdapterOption
- func ManualCorrectGasRefundOption() StateDBAdapterOption
- func NotCheckPutStateErrorOption() StateDBAdapterOption
- func NotFixTopicCopyBugOption() StateDBAdapterOption
- func RevertLogOption() StateDBAdapterOption
- func UseConfirmedNonceOption() StateDBAdapterOption
Constants ¶
const ( // CodeKVNameSpace is the bucket name for code CodeKVNameSpace = "Code" // ContractKVNameSpace is the bucket name for contract data storage ContractKVNameSpace = "Contract" // PreimageKVNameSpace is the bucket name for preimage data storage PreimageKVNameSpace = "Preimage" )
Variables ¶
var ( // ErrInconsistentNonce is the error that the nonce is different from executor's nonce ErrInconsistentNonce = errors.New("Nonce is not identical to executor nonce") )
Functions ¶
func CanTransfer ¶
CanTransfer checks whether the from account has enough balance
func ExecuteContract ¶
func ExecuteContract( ctx context.Context, sm protocol.StateManager, execution *action.Execution, getBlockHash GetBlockHash, depositGasFunc DepositGasWithSGD, sgd SGDRegistry, ) ([]byte, *action.Receipt, error)
ExecuteContract processes a transfer which contains a contract
func MakeTransfer ¶
MakeTransfer transfers account
func ReadContractStorage ¶ added in v1.6.1
func ReadContractStorage( ctx context.Context, sm protocol.StateManager, contract address.Address, key []byte, ) ([]byte, error)
ReadContractStorage reads contract's storage
func SimulateExecution ¶ added in v1.0.0
func SimulateExecution( ctx context.Context, sm protocol.StateManager, caller address.Address, ex *action.Execution, getBlockHash GetBlockHash, ) ([]byte, *action.Receipt, error)
SimulateExecution simulates the execution in evm
Types ¶
type Contract ¶
type Contract interface { GetCommittedState(hash.Hash256) ([]byte, error) GetState(hash.Hash256) ([]byte, error) SetState(hash.Hash256, []byte) error GetCode() ([]byte, error) SetCode(hash.Hash256, []byte) SelfState() *state.Account Commit() error LoadRoot() error Iterator() (trie.Iterator, error) Snapshot() Contract }
Contract is a special type of account with code and storage trie.
type DepositGasWithSGD ¶ added in v1.11.0
type DepositGasWithSGD func(context.Context, protocol.StateManager, address.Address, *big.Int, *big.Int) (*action.TransactionLog, error)
DepositGasWithSGD deposits gas with Sharing of Gas-fee with DApps
type GetBlockHash ¶ added in v0.11.0
GetBlockHash gets block hash by height
type Params ¶
type Params struct {
// contains filtered or unexported fields
}
Params is the context and parameters
type SGDRegistry ¶ added in v1.11.0
type SGDRegistry interface {
CheckContract(context.Context, string, uint64) (address.Address, uint64, bool, error)
}
SGDRegistry is the interface for handling Sharing of Gas-fee with DApps
type StateDBAdapter ¶
type StateDBAdapter struct {
// contains filtered or unexported fields
}
StateDBAdapter represents the state db adapter for evm to access iotx blockchain
func NewStateDBAdapter ¶
func NewStateDBAdapter( sm protocol.StateManager, blockHeight uint64, executionHash hash.Hash256, opts ...StateDBAdapterOption, ) (*StateDBAdapter, error)
NewStateDBAdapter creates a new state db with iotex blockchain
func (*StateDBAdapter) AddAddressToAccessList ¶ added in v1.4.0
func (stateDB *StateDBAdapter) AddAddressToAccessList(addr common.Address)
AddAddressToAccessList adds the given address to the access list. This operation is safe to perform even if the feature/fork is not active yet
func (*StateDBAdapter) AddBalance ¶
func (stateDB *StateDBAdapter) AddBalance(evmAddr common.Address, amount *big.Int)
AddBalance adds balance to account
func (*StateDBAdapter) AddLog ¶
func (stateDB *StateDBAdapter) AddLog(evmLog *types.Log)
AddLog adds log whose transaction amount is larger than 0
func (*StateDBAdapter) AddPreimage ¶
func (stateDB *StateDBAdapter) AddPreimage(hash common.Hash, preimage []byte)
AddPreimage adds the preimage of a hash
func (*StateDBAdapter) AddRefund ¶
func (stateDB *StateDBAdapter) AddRefund(gas uint64)
AddRefund adds refund
func (*StateDBAdapter) AddSlotToAccessList ¶ added in v1.4.0
func (stateDB *StateDBAdapter) AddSlotToAccessList(addr common.Address, slot common.Hash)
AddSlotToAccessList adds the given (address,slot) to the access list. This operation is safe to perform even if the feature/fork is not active yet
func (*StateDBAdapter) AddressInAccessList ¶ added in v1.4.0
func (stateDB *StateDBAdapter) AddressInAccessList(addr common.Address) bool
AddressInAccessList returns true if the given address is in the access list
func (*StateDBAdapter) CommitContracts ¶ added in v0.5.0
func (stateDB *StateDBAdapter) CommitContracts() error
CommitContracts commits contract code to db and update pending contract account changes to trie
func (*StateDBAdapter) CreateAccount ¶
func (stateDB *StateDBAdapter) CreateAccount(evmAddr common.Address)
CreateAccount creates an account in iotx blockchain
func (*StateDBAdapter) Empty ¶
func (stateDB *StateDBAdapter) Empty(evmAddr common.Address) bool
Empty returns true if the the contract is empty
func (*StateDBAdapter) Error ¶
func (stateDB *StateDBAdapter) Error() error
Error returns the first stored error during evm contract execution
func (*StateDBAdapter) Exist ¶
func (stateDB *StateDBAdapter) Exist(evmAddr common.Address) bool
Exist checks the existence of an address
func (*StateDBAdapter) ForEachStorage ¶
func (stateDB *StateDBAdapter) ForEachStorage(addr common.Address, cb func(common.Hash, common.Hash) bool) error
ForEachStorage loops each storage
func (*StateDBAdapter) GetBalance ¶
func (stateDB *StateDBAdapter) GetBalance(evmAddr common.Address) *big.Int
GetBalance gets the balance of account
func (*StateDBAdapter) GetCode ¶
func (stateDB *StateDBAdapter) GetCode(evmAddr common.Address) []byte
GetCode returns contract's code
func (*StateDBAdapter) GetCodeHash ¶
func (stateDB *StateDBAdapter) GetCodeHash(evmAddr common.Address) common.Hash
GetCodeHash returns contract's code hash
func (*StateDBAdapter) GetCodeSize ¶
func (stateDB *StateDBAdapter) GetCodeSize(evmAddr common.Address) int
GetCodeSize gets the code size saved in hash
func (*StateDBAdapter) GetCommittedState ¶ added in v0.8.1
GetCommittedState gets committed state
func (*StateDBAdapter) GetNonce ¶
func (stateDB *StateDBAdapter) GetNonce(evmAddr common.Address) uint64
GetNonce gets the nonce of account
func (*StateDBAdapter) GetRefund ¶
func (stateDB *StateDBAdapter) GetRefund() uint64
GetRefund gets refund
func (*StateDBAdapter) HasSuicided ¶
func (stateDB *StateDBAdapter) HasSuicided(evmAddr common.Address) bool
HasSuicided returns whether the contract has been killed
func (*StateDBAdapter) IsNewAccount ¶ added in v1.9.0
func (stateDB *StateDBAdapter) IsNewAccount(evmAddr common.Address) bool
IsNewAccount returns true if this is a new account
func (*StateDBAdapter) Logs ¶
func (stateDB *StateDBAdapter) Logs() []*action.Log
Logs returns the logs
func (*StateDBAdapter) PrepareAccessList ¶ added in v1.4.0
func (stateDB *StateDBAdapter) PrepareAccessList(sender common.Address, dst *common.Address, precompiles []common.Address, list types.AccessList)
PrepareAccessList handles the preparatory steps for executing a state transition with regards to both EIP-2929 and EIP-2930:
- Add sender to access list (2929) - Add destination to access list (2929) - Add precompiles to access list (2929) - Add the contents of the optional tx access list (2930)
This method should only be called if Berlin/2929+2930 is applicable at the current number.
func (*StateDBAdapter) RevertToSnapshot ¶
func (stateDB *StateDBAdapter) RevertToSnapshot(snapshot int)
RevertToSnapshot reverts the state factory to the state at a given snapshot
func (*StateDBAdapter) SetCode ¶
func (stateDB *StateDBAdapter) SetCode(evmAddr common.Address, code []byte)
SetCode sets contract's code
func (*StateDBAdapter) SetNonce ¶
func (stateDB *StateDBAdapter) SetNonce(evmAddr common.Address, nonce uint64)
SetNonce sets the nonce of account
func (*StateDBAdapter) SetState ¶
func (stateDB *StateDBAdapter) SetState(evmAddr common.Address, k, v common.Hash)
SetState sets state
func (*StateDBAdapter) SlotInAccessList ¶ added in v1.4.0
func (stateDB *StateDBAdapter) SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool)
SlotInAccessList returns true if the given (address, slot)-tuple is in the access list
func (*StateDBAdapter) Snapshot ¶
func (stateDB *StateDBAdapter) Snapshot() int
Snapshot returns the snapshot id
func (*StateDBAdapter) SubBalance ¶
func (stateDB *StateDBAdapter) SubBalance(evmAddr common.Address, amount *big.Int)
SubBalance subtracts balance from account
func (*StateDBAdapter) SubRefund ¶ added in v0.8.1
func (stateDB *StateDBAdapter) SubRefund(gas uint64)
SubRefund subtracts refund
func (*StateDBAdapter) Suicide ¶
func (stateDB *StateDBAdapter) Suicide(evmAddr common.Address) bool
Suicide kills the contract
func (*StateDBAdapter) TransactionLogs ¶ added in v1.1.0
func (stateDB *StateDBAdapter) TransactionLogs() []*action.TransactionLog
TransactionLogs returns the transaction logs
type StateDBAdapterOption ¶ added in v1.2.0
type StateDBAdapterOption func(*StateDBAdapter) error
StateDBAdapterOption set StateDBAdapter construction param
func AsyncContractTrieOption ¶ added in v1.6.3
func AsyncContractTrieOption() StateDBAdapterOption
AsyncContractTrieOption set asyncContractTrie as true
func DisableSortCachedContractsOption ¶ added in v1.9.0
func DisableSortCachedContractsOption() StateDBAdapterOption
DisableSortCachedContractsOption set disable sort cached contracts as true
func FixSnapshotOrderOption ¶ added in v1.6.3
func FixSnapshotOrderOption() StateDBAdapterOption
FixSnapshotOrderOption set fixSnapshotOrder as true
func LegacyNonceAccountOption ¶ added in v1.9.0
func LegacyNonceAccountOption() StateDBAdapterOption
LegacyNonceAccountOption set legacyNonceAccount as true
func ManualCorrectGasRefundOption ¶ added in v1.9.0
func ManualCorrectGasRefundOption() StateDBAdapterOption
ManualCorrectGasRefundOption set manualCorrectGasRefund as true
func NotCheckPutStateErrorOption ¶ added in v1.9.0
func NotCheckPutStateErrorOption() StateDBAdapterOption
NotCheckPutStateErrorOption set notCheckPutStateError as true
func NotFixTopicCopyBugOption ¶ added in v1.6.3
func NotFixTopicCopyBugOption() StateDBAdapterOption
NotFixTopicCopyBugOption set notFixTopicCopyBug as true
func RevertLogOption ¶ added in v1.7.0
func RevertLogOption() StateDBAdapterOption
RevertLogOption set revertLog as true
func UseConfirmedNonceOption ¶ added in v1.9.0
func UseConfirmedNonceOption() StateDBAdapterOption
UseConfirmedNonceOption set usePendingNonce as true