github.com/aidoskuneen/adk-node@v0.0.0-20220315131952-2e32567cb7f4/core/vm/interface.go (about)

     1  // Copyright 2021 The adkgo Authors
     2  // This file is part of the adkgo library (adapted for adkgo from go--ethereum v1.10.8).
     3  //
     4  // the adkgo library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // the adkgo library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the adkgo library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package vm
    18  
    19  import (
    20  	"math/big"
    21  
    22  	"github.com/aidoskuneen/adk-node/common"
    23  	"github.com/aidoskuneen/adk-node/core/types"
    24  )
    25  
    26  // StateDB is an EVM database for full state querying.
    27  type StateDB interface {
    28  	CreateAccount(common.Address)
    29  
    30      GetHash() common.Hash
    31  	
    32  	GetInternalCounter() int
    33  	
    34  	SubBalance(common.Address, *big.Int)
    35  	AddBalance(common.Address, *big.Int)
    36  	GetBalance(common.Address) *big.Int
    37  
    38  	GetNonce(common.Address) uint64
    39  	SetNonce(common.Address, uint64)
    40  
    41  	GetCodeHash(common.Address) common.Hash
    42  	GetCode(common.Address) []byte
    43  	SetCode(common.Address, []byte)
    44  	GetCodeSize(common.Address) int
    45  
    46  	AddRefund(uint64)
    47  	SubRefund(uint64)
    48  	GetRefund() uint64
    49  
    50  	GetCommittedState(common.Address, common.Hash) common.Hash
    51  	GetState(common.Address, common.Hash) common.Hash
    52  	SetState(common.Address, common.Hash, common.Hash)
    53  
    54  	Suicide(common.Address) bool
    55  	HasSuicided(common.Address) bool
    56  
    57  	// Exist reports whether the given account exists in state.
    58  	// Notably this should also return true for suicided accounts.
    59  	Exist(common.Address) bool
    60  	// Empty returns whether the given account is empty. Empty
    61  	// is defined according to EIP161 (balance = nonce = code = 0).
    62  	Empty(common.Address) bool
    63  
    64  	PrepareAccessList(sender common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList)
    65  	AddressInAccessList(addr common.Address) bool
    66  	SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool)
    67  	// AddAddressToAccessList adds the given address to the access list. This operation is safe to perform
    68  	// even if the feature/fork is not active yet
    69  	AddAddressToAccessList(addr common.Address)
    70  	// AddSlotToAccessList adds the given (address,slot) to the access list. This operation is safe to perform
    71  	// even if the feature/fork is not active yet
    72  	AddSlotToAccessList(addr common.Address, slot common.Hash)
    73  
    74  	RevertToSnapshot(int)
    75  	Snapshot() int
    76  
    77  	AddLog(*types.Log)
    78  	AddPreimage(common.Hash, []byte)
    79  
    80  	ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) error
    81  }
    82  
    83  // CallContext provides a basic interface for the EVM calling conventions. The EVM
    84  // depends on this context being implemented for doing subcalls and initialising new EVM contracts.
    85  type CallContext interface {
    86  	// Call another contract
    87  	Call(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
    88  	// Take another's contract code and execute within our own context
    89  	CallCode(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
    90  	// Same as CallCode except sender and value is propagated from parent to child scope
    91  	DelegateCall(env *EVM, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error)
    92  	// Create a new contract
    93  	Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error)
    94  }