github.com/corverroos/quorum@v21.1.0+incompatible/core/vm/interface.go (about)

     1  // Copyright 2016 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum 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 go-ethereum 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 go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  //go:generate mockgen -source interface.go -destination mock_interface.go -package vm
    18  
    19  package vm
    20  
    21  import (
    22  	"math/big"
    23  
    24  	"github.com/ethereum/go-ethereum/common"
    25  	"github.com/ethereum/go-ethereum/core/state"
    26  	"github.com/ethereum/go-ethereum/core/types"
    27  )
    28  
    29  type AccountExtraDataStateGetter interface {
    30  	// Return nil for public contract
    31  	GetPrivacyMetadata(addr common.Address) (*state.PrivacyMetadata, error)
    32  	GetManagedParties(addr common.Address) ([]string, error)
    33  }
    34  
    35  type AccountExtraDataStateSetter interface {
    36  	SetPrivacyMetadata(addr common.Address, pm *state.PrivacyMetadata)
    37  	SetManagedParties(addr common.Address, managedParties []string)
    38  }
    39  
    40  // Quorum uses a cut-down StateDB, MinimalApiState. We leave the methods in StateDB commented out so they'll produce a
    41  // conflict when upstream changes.
    42  type MinimalApiState interface {
    43  	AccountExtraDataStateGetter
    44  
    45  	GetBalance(addr common.Address) *big.Int
    46  	SetBalance(addr common.Address, balance *big.Int)
    47  	GetCode(addr common.Address) []byte
    48  	GetState(a common.Address, b common.Hash) common.Hash
    49  	GetNonce(addr common.Address) uint64
    50  	SetNonce(addr common.Address, nonce uint64)
    51  	SetCode(common.Address, []byte)
    52  
    53  	// RLP-encoded of the state object in a given address
    54  	// Throw error if no state object is found
    55  	GetRLPEncodedStateObject(addr common.Address) ([]byte, error)
    56  	GetProof(common.Address) ([][]byte, error)
    57  	GetStorageProof(common.Address, common.Hash) ([][]byte, error)
    58  	StorageTrie(addr common.Address) state.Trie
    59  	Error() error
    60  	GetCodeHash(common.Address) common.Hash
    61  	SetState(common.Address, common.Hash, common.Hash)
    62  	SetStorage(addr common.Address, storage map[common.Hash]common.Hash)
    63  }
    64  
    65  // StateDB is an EVM database for full state querying.
    66  type StateDB interface {
    67  	MinimalApiState
    68  	AccountExtraDataStateSetter
    69  
    70  	CreateAccount(common.Address)
    71  
    72  	SubBalance(common.Address, *big.Int)
    73  	AddBalance(common.Address, *big.Int)
    74  	//GetBalance(common.Address) *big.Int
    75  
    76  	//GetNonce(common.Address) uint64
    77  	//SetNonce(common.Address, uint64)
    78  
    79  	//GetCodeHash(common.Address) common.Hash
    80  	//GetCode(common.Address) []byte
    81  	//SetCode(common.Address, []byte)
    82  	GetCodeSize(common.Address) int
    83  
    84  	AddRefund(uint64)
    85  	SubRefund(uint64)
    86  	GetRefund() uint64
    87  
    88  	GetCommittedState(common.Address, common.Hash) common.Hash
    89  	//GetState(common.Address, common.Hash) common.Hash
    90  	//SetState(common.Address, common.Hash, common.Hash)
    91  
    92  	Suicide(common.Address) bool
    93  	HasSuicided(common.Address) bool
    94  
    95  	// Exist reports whether the given account exists in state.
    96  	// Notably this should also return true for suicided accounts.
    97  	Exist(common.Address) bool
    98  	// Empty returns whether the given account is empty. Empty
    99  	// is defined according to EIP161 (balance = nonce = code = 0).
   100  	Empty(common.Address) bool
   101  
   102  	RevertToSnapshot(int)
   103  	Snapshot() int
   104  
   105  	AddLog(*types.Log)
   106  	AddPreimage(common.Hash, []byte)
   107  
   108  	ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) error
   109  }
   110  
   111  // CallContext provides a basic interface for the EVM calling conventions. The EVM
   112  // depends on this context being implemented for doing subcalls and initialising new EVM contracts.
   113  type CallContext interface {
   114  	// Call another contract
   115  	Call(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
   116  	// Take another's contract code and execute within our own context
   117  	CallCode(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
   118  	// Same as CallCode except sender and value is propagated from parent to child scope
   119  	DelegateCall(env *EVM, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error)
   120  	// Create a new contract
   121  	Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error)
   122  }