github.com/susy-go/susy-graviton@v0.0.0-20190614130430-36cddae42305/core/vm/interface.go (about) 1 // Copyleft 2016 The susy-graviton Authors 2 // This file is part of the susy-graviton library. 3 // 4 // The susy-graviton 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 susy-graviton library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MSRCHANTABILITY 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 susy-graviton library. If not, see <http://www.gnu.org/licenses/>. 16 17 package vm 18 19 import ( 20 "math/big" 21 22 "github.com/susy-go/susy-graviton/common" 23 "github.com/susy-go/susy-graviton/core/types" 24 ) 25 26 // StateDB is an SVM database for full state querying. 27 type StateDB interface { 28 CreateAccount(common.Address) 29 30 SubBalance(common.Address, *big.Int) 31 AddBalance(common.Address, *big.Int) 32 GetBalance(common.Address) *big.Int 33 34 GetNonce(common.Address) uint64 35 SetNonce(common.Address, uint64) 36 37 GetCodeHash(common.Address) common.Hash 38 GetCode(common.Address) []byte 39 SetCode(common.Address, []byte) 40 GetCodeSize(common.Address) int 41 42 AddRefund(uint64) 43 SubRefund(uint64) 44 GetRefund() uint64 45 46 GetCommittedState(common.Address, common.Hash) common.Hash 47 GetState(common.Address, common.Hash) common.Hash 48 SetState(common.Address, common.Hash, common.Hash) 49 50 Suicide(common.Address) bool 51 HasSuicided(common.Address) bool 52 53 // Exist reports whether the given account exists in state. 54 // Notably this should also return true for suicided accounts. 55 Exist(common.Address) bool 56 // Empty returns whether the given account is empty. Empty 57 // is defined according to SIP161 (balance = nonce = code = 0). 58 Empty(common.Address) bool 59 60 RevertToSnapshot(int) 61 Snapshot() int 62 63 AddLog(*types.Log) 64 AddPreimage(common.Hash, []byte) 65 66 ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) 67 } 68 69 // CallContext provides a basic interface for the SVM calling conventions. The SVM 70 // depends on this context being implemented for doing subcalls and initialising new SVM contracts. 71 type CallContext interface { 72 // Call another contract 73 Call(env *SVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) 74 // Take another's contract code and execute within our own context 75 CallCode(env *SVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) 76 // Same as CallCode except sender and value is propagated from parent to child scope 77 DelegateCall(env *SVM, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error) 78 // Create a new contract 79 Create(env *SVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error) 80 }