cvm

package
v0.0.0-...-a826b38 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanTransfer

func CanTransfer(db vm.StateDB, addr common.Address, amount *big.Int) bool

CanTransfer checks wether there are enough funds in the address' account to make a transfer. This does not take the necessary gas in to account to make the transfer valid.

func GetHashFn

func GetHashFn() func(n uint64) common.Hash

GetHashFn returns a GetHashFunc which retrieves header hashes by number 获取块号码对于的块hash

func NewEVMContext

func NewEVMContext(from common.Address, blockNum, timeStamp, difficulty int64) vm.Context

NewEVMContext creates a new context for use in the EVM.

func Transfer

func Transfer(db vm.StateDB, sender, recipient common.Address, amount *big.Int)

Transfer subtracts amount from sender and adds amount to recipient using the given Db

Types

type AccountState

type AccountState struct {
	Accounts map[common.Address]*accountObject `json:"accounts,omitempty"`
}

AccountState 实现vm的StateDB的接口 用于进行测试

func NewAccountStateDb

func NewAccountStateDb() *AccountState

NewAccountStateDb new instance

func TryLoadFromDisk

func TryLoadFromDisk() (*AccountState, error)

TryLoadFromDisk 尝试从磁盘加载AccountState

func (*AccountState) AddBalance

func (accSt *AccountState) AddBalance(addr common.Address, amount *big.Int)

AddBalance 增加某个账户的余额

func (*AccountState) AddLog

func (accSt *AccountState) AddLog(log *types.Log)

AddLog 添加事件触发日志

func (*AccountState) AddPreimage

func (accSt *AccountState) AddPreimage(common.Hash, []byte)

AddPreimage 暂时没搞清楚这个是干嘛用的

func (*AccountState) AddRefund

func (accSt *AccountState) AddRefund(uint64)

AddRefund 暂时先忽略补偿

func (*AccountState) Commit

func (accSt *AccountState) Commit() error

Commit 进行持久换存储

func (*AccountState) CreateAccount

func (accSt *AccountState) CreateAccount(addr common.Address)

CreateAccount 创建一个新的合约账户

func (*AccountState) Empty

func (accSt *AccountState) Empty(addr common.Address) bool

Empty 是否是空账户

func (*AccountState) Exist

func (accSt *AccountState) Exist(addr common.Address) bool

Exist 检查账户是否存在

func (*AccountState) ForEachStorage

func (accSt *AccountState) ForEachStorage(common.Address, func(common.Hash, common.Hash) bool)

ForEachStorage 暂时没发现vm调用这个接口

func (*AccountState) GetBalance

func (accSt *AccountState) GetBalance(addr common.Address) *big.Int

GetBalance 获取某个账户的余额

func (*AccountState) GetCode

func (accSt *AccountState) GetCode(addr common.Address) []byte

GetCode 获取智能合约的代码

func (*AccountState) GetCodeHash

func (accSt *AccountState) GetCodeHash(addr common.Address) common.Hash

GetCodeHash 获取代码的hash值

func (*AccountState) GetCodeSize

func (accSt *AccountState) GetCodeSize(addr common.Address) int

GetCodeSize 获取code的大小

func (*AccountState) GetNonce

func (accSt *AccountState) GetNonce(addr common.Address) uint64

GetNonce 获取nonce

func (*AccountState) GetRefund

func (accSt *AccountState) GetRefund() uint64

GetRefund ...

func (*AccountState) GetState

func (accSt *AccountState) GetState(addr common.Address, key common.Hash) common.Hash

GetState 和SetState 是用于保存合约执行时 存储的变量是否发生变化 evm对变量存储的改变消耗的gas是有区别的

func (*AccountState) HasSuicided

func (accSt *AccountState) HasSuicided(common.Address) bool

HasSuicided ...

func (*AccountState) RevertToSnapshot

func (accSt *AccountState) RevertToSnapshot(int)

RevertToSnapshot ...

func (*AccountState) SetCode

func (accSt *AccountState) SetCode(addr common.Address, code []byte)

SetCode 设置智能合约的code

func (*AccountState) SetNonce

func (accSt *AccountState) SetNonce(addr common.Address, nonce uint64)

SetNonce 设置nonce

func (*AccountState) SetState

func (accSt *AccountState) SetState(addr common.Address, key common.Hash, value common.Hash)

SetState 设置变量的状态

func (*AccountState) Snapshot

func (accSt *AccountState) Snapshot() int

Snapshot ...

func (*AccountState) SubBalance

func (accSt *AccountState) SubBalance(addr common.Address, amount *big.Int)

SubBalance 减去某个账户的余额

func (*AccountState) Suicide

func (accSt *AccountState) Suicide(common.Address) bool

Suicide 暂时禁止自杀

Directories

Path Synopsis
Package abi implements the Ethereum ABI (Application Binary Interface).
Package abi implements the Ethereum ABI (Application Binary Interface).
Package common contains various helper functions.
Package common contains various helper functions.
bitutil
Package bitutil implements fast bitwise operations.
Package bitutil implements fast bitwise operations.
compiler
Package compiler wraps the Solidity compiler executable (solc).
Package compiler wraps the Solidity compiler executable (solc).
hexutil
Package hexutil implements hex encoding with 0x prefix.
Package hexutil implements hex encoding with 0x prefix.
math
Package math provides integer math utilities.
Package math provides integer math utilities.
vm
Package vm implements the Ethereum Virtual Machine.
Package vm implements the Ethereum Virtual Machine.
runtime
Package runtime provides a basic execution model for executing EVM code.
Package runtime provides a basic execution model for executing EVM code.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL