github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/core/vm/interface.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:36</date> 10 //</624450082535641088> 11 12 13 package vm 14 15 import ( 16 "math/big" 17 18 "github.com/ethereum/go-ethereum/common" 19 "github.com/ethereum/go-ethereum/core/types" 20 ) 21 22 //StateDB是用于完整状态查询的EVM数据库。 23 type StateDB interface { 24 CreateAccount(common.Address) 25 26 SubBalance(common.Address, *big.Int) 27 AddBalance(common.Address, *big.Int) 28 GetBalance(common.Address) *big.Int 29 30 GetNonce(common.Address) uint64 31 SetNonce(common.Address, uint64) 32 33 GetCodeHash(common.Address) common.Hash 34 GetCode(common.Address) []byte 35 SetCode(common.Address, []byte) 36 GetCodeSize(common.Address) int 37 38 AddRefund(uint64) 39 SubRefund(uint64) 40 GetRefund() uint64 41 42 GetCommittedState(common.Address, common.Hash) common.Hash 43 GetState(common.Address, common.Hash) common.Hash 44 SetState(common.Address, common.Hash, common.Hash) 45 46 Suicide(common.Address) bool 47 HasSuicided(common.Address) bool 48 49 //exist报告给定帐户是否处于状态。 50 //值得注意的是,对于自杀账户来说,这也应该是正确的。 51 Exist(common.Address) bool 52 //empty返回给定帐户是否为空。空的 53 //根据EIP161定义(balance=nonce=code=0)。 54 Empty(common.Address) bool 55 56 RevertToSnapshot(int) 57 Snapshot() int 58 59 AddLog(*types.Log) 60 AddPreimage(common.Hash, []byte) 61 62 ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) 63 } 64 65 //CallContext为EVM调用约定提供基本接口。EVM 66 //取决于为执行子调用和初始化新的EVM合同而实现的上下文。 67 type CallContext interface { 68 //调用另一个合同 69 Call(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) 70 //采用他人的合同代码并在我们自己的上下文中执行 71 CallCode(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) 72 //与callcode相同,但发送方和值从父作用域传播到子作用域 73 DelegateCall(env *EVM, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error) 74 //创建新合同 75 Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error) 76 } 77