github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/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 12:09:35</date>
    10  //</624342622126739456>
    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  	GetRefund() uint64
    40  
    41  	GetState(common.Address, common.Hash) common.Hash
    42  	SetState(common.Address, common.Hash, common.Hash)
    43  
    44  	Suicide(common.Address) bool
    45  	HasSuicided(common.Address) bool
    46  
    47  //exist报告给定帐户是否处于状态。
    48  //值得注意的是,对于自杀账户来说,这也应该是正确的。
    49  	Exist(common.Address) bool
    50  //empty返回给定帐户是否为空。空的
    51  //根据EIP161定义(balance=nonce=code=0)。
    52  	Empty(common.Address) bool
    53  
    54  	RevertToSnapshot(int)
    55  	Snapshot() int
    56  
    57  	AddLog(*types.Log)
    58  	AddPreimage(common.Hash, []byte)
    59  
    60  	ForEachStorage(common.Address, func(common.Hash, common.Hash) bool)
    61  }
    62  
    63  //CallContext为EVM调用约定提供基本接口。EVM EVM
    64  //取决于为执行子调用和初始化新的EVM合同而实现的上下文。
    65  type CallContext interface {
    66  //调用另一个合同
    67  	Call(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
    68  //采用他人的合同代码并在我们自己的上下文中执行
    69  	CallCode(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
    70  //与callcode相同,但发送方和值从父作用域传播到子作用域
    71  	DelegateCall(env *EVM, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error)
    72  //创建新合同
    73  	Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error)
    74  }
    75