wasm

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanTransfer

func CanTransfer(db types.StateDB, addr, token 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(ref *types.Header, chain ChainContext) func(n uint64) common.Hash

GetHashFn returns a GetHashFunc which retrieves header hashes by number

func IsWasmContract

func IsWasmContract(code []byte) bool

IsWasmContract check contract's id

func Transfer

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

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

func UnsafeTransfer

func UnsafeTransfer(db types.StateDB, recipient, token common.Address, amount *big.Int)

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

Types

type AccountRef

type AccountRef common.Address

AccountRef implements ContractRef.

Account references are used during EVM initialisation and it's primary use is to fetch addresses. Removing this object proves difficult because of the cached jump destinations which are fetched from the parent contract (i.e. the caller), which is a ContractRef.

func (AccountRef) Address

func (ar AccountRef) Address() common.Address

Address casts AccountRef to a Address

type CanTransferFunc

type CanTransferFunc func(types.StateDB, common.Address, common.Address, *big.Int) bool

CanTransferFunc is the signature of a transfer guard function

type ChainContext

type ChainContext interface {
	// GetHeader returns the hash corresponding to their hash.
	GetHeader(uint64) *types.Header
}

ChainContext supports retrieving headers from the current blockchain to be used during transaction processing.

type Config

type Config struct {
}

type Context

type Context struct {
	// CanTransfer returns whether the account contains
	// sufficient ether to transfer the value
	CanTransfer CanTransferFunc
	// Transfer transfers ether from one account to the other
	Transfer TransferFunc
	// GetHash returns the hash corresponding to n
	UnsafeTransfer UnsafeTransferFunc
	GetHash        GetHashFunc

	// Message information
	Token    common.Address // Provides the tx token type
	Origin   common.Address // Provides information for ORIGIN
	GasPrice *big.Int       // Provides information for GASPRICE

	// Block information
	Coinbase    common.Address // Provides information for COINBASE
	GasLimit    uint64         // Provides information for GASLIMIT
	BlockNumber *big.Int       // Provides information for NUMBER
	Time        *big.Int       // Provides information for TIME
	Difficulty  *big.Int       // Provides information for DIFFICULTY

	WasmGasRate uint64
}

Context provides the EVM with auxiliary information. Once provided it shouldn't be modified.

func NewWASMContext

func NewWASMContext(header *types.Header, chain ChainContext, author *common.Address, gasRate uint64) Context

NewWASMContext creates a new context for use in the WASM.

type Contract

type Contract struct {
	// CallerAddress is the result of the caller which initialised this
	// contract. However when the "call method" is delegated this value
	// needs to be initialised to that of the caller's caller.
	CallerAddress common.Address

	Code     []byte
	CodeHash common.Hash
	CodeAddr *common.Address
	Input    []byte

	Gas uint64

	ByteCodeGas uint64

	Args []byte

	DelegateCall bool
	CreateCall   bool
	// contains filtered or unexported fields
}

Contract represents an ethereum contract in the state database. It contains the the contract code, calling arguments. Contract implements ContractRef

func NewContract

func NewContract(caller ContractRef, object ContractRef, value *big.Int, gas uint64) *Contract

NewContract returns a new contract environment for the execution of EVM.

func (*Contract) Address

func (c *Contract) Address() common.Address

Address returns the contracts address

func (*Contract) AsDelegate

func (c *Contract) AsDelegate() *Contract

AsDelegate sets the contract to be a delegate call and returns the current contract (for chaining calls)

func (*Contract) Caller

func (c *Contract) Caller() common.Address

Caller returns the caller of the contract.

Caller will recursively call caller when the contract is a delegate call, including that of caller's caller.

func (*Contract) SetCallCode

func (c *Contract) SetCallCode(addr *common.Address, hash common.Hash, code []byte)

SetCallCode sets the code of the contract and address of the backing data object

func (*Contract) SetCode

func (c *Contract) SetCode(hash common.Hash, code []byte)

SetCode sets the code to the contract

func (*Contract) UseGas

func (c *Contract) UseGas(gas uint64) (ok bool)

UseGas attempts the use gas and subtracts it and returns true on success

func (*Contract) Value

func (c *Contract) Value() *big.Int

Value returns the contracts value (sent to it from it's caller)

type ContractRef

type ContractRef interface {
	Address() common.Address
}

ContractRef is a reference to the contract's backing object

type GetHashFunc

type GetHashFunc func(uint64) common.Hash

GetHashFunc returns the nth block hash in the blockchain and is used by the BLOCKHASH EVM op code.

type TCBlockHash

type TCBlockHash struct{}

func (*TCBlockHash) Call

func (t *TCBlockHash) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCBlockHash) Gas

func (t *TCBlockHash) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCCallContract

type TCCallContract struct{}

func (*TCCallContract) Call

func (t *TCCallContract) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCCallContract) Gas

func (t *TCCallContract) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCCheckSign

type TCCheckSign struct{}

func (*TCCheckSign) Call

func (t *TCCheckSign) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCCheckSign) Gas

func (t *TCCheckSign) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCContractStorageGet

type TCContractStorageGet struct{}

func (*TCContractStorageGet) Call

func (t *TCContractStorageGet) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCContractStorageGet) Gas

func (t *TCContractStorageGet) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCContractStoragePureGet

type TCContractStoragePureGet struct{}

func (*TCContractStoragePureGet) Call

func (t *TCContractStoragePureGet) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCContractStoragePureGet) Gas

func (t *TCContractStoragePureGet) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCEcrecover

type TCEcrecover struct{}

func (*TCEcrecover) Call

func (t *TCEcrecover) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCEcrecover) Gas

func (t *TCEcrecover) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCGetBalance

type TCGetBalance struct{}

func (*TCGetBalance) Call

func (t *TCGetBalance) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCGetBalance) Gas

func (t *TCGetBalance) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCGetCoinbase

type TCGetCoinbase struct{}

func (*TCGetCoinbase) Call

func (t *TCGetCoinbase) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCGetCoinbase) Gas

func (t *TCGetCoinbase) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCGetGasLimit

type TCGetGasLimit struct{}

func (*TCGetGasLimit) Call

func (t *TCGetGasLimit) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCGetGasLimit) Gas

func (t *TCGetGasLimit) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCGetMsgTokenValue

type TCGetMsgTokenValue struct{}

func (*TCGetMsgTokenValue) Call

func (t *TCGetMsgTokenValue) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCGetMsgTokenValue) Gas

func (t *TCGetMsgTokenValue) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCGetMsgValue

type TCGetMsgValue struct{}

func (*TCGetMsgValue) Call

func (t *TCGetMsgValue) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCGetMsgValue) Gas

func (t *TCGetMsgValue) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCGetNumber

type TCGetNumber struct{}

func (*TCGetNumber) Call

func (t *TCGetNumber) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCGetNumber) Gas

func (t *TCGetNumber) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCGetTimestamp

type TCGetTimestamp struct{}

func (*TCGetTimestamp) Call

func (t *TCGetTimestamp) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCGetTimestamp) Gas

func (t *TCGetTimestamp) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCGetTxGasPrice

type TCGetTxGasPrice struct{}

func (*TCGetTxGasPrice) Call

func (t *TCGetTxGasPrice) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCGetTxGasPrice) Gas

func (t *TCGetTxGasPrice) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCGetTxOrigin

type TCGetTxOrigin struct{}

func (*TCGetTxOrigin) Call

func (t *TCGetTxOrigin) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCGetTxOrigin) Gas

func (t *TCGetTxOrigin) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCIssue

type TCIssue struct{}

func (*TCIssue) Call

func (t *TCIssue) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCIssue) Gas

func (t *TCIssue) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCLog0

type TCLog0 struct{}

func (*TCLog0) Call

func (t *TCLog0) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCLog0) Gas

func (t *TCLog0) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCLog1

type TCLog1 struct{}

func (*TCLog1) Call

func (t *TCLog1) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCLog1) Gas

func (t *TCLog1) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCLog2

type TCLog2 struct{}

func (*TCLog2) Call

func (t *TCLog2) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCLog2) Gas

func (t *TCLog2) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCLog3

type TCLog3 struct{}

func (*TCLog3) Call

func (t *TCLog3) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCLog3) Gas

func (t *TCLog3) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCLog4

type TCLog4 struct{}

func (*TCLog4) Call

func (t *TCLog4) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCLog4) Gas

func (t *TCLog4) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCNotify

type TCNotify struct{}

func (*TCNotify) Call

func (t *TCNotify) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCNotify) Gas

func (t *TCNotify) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCNow

type TCNow struct{}

func (*TCNow) Call

func (t *TCNow) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCNow) Gas

func (t *TCNow) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCSelfDestruct

type TCSelfDestruct struct{}

func (*TCSelfDestruct) Call

func (t *TCSelfDestruct) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCSelfDestruct) Gas

func (t *TCSelfDestruct) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCStorageDel

type TCStorageDel struct{}

func (*TCStorageDel) Call

func (t *TCStorageDel) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCStorageDel) Gas

func (t *TCStorageDel) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCStorageGet

type TCStorageGet struct{}

func (*TCStorageGet) Call

func (t *TCStorageGet) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCStorageGet) Gas

func (t *TCStorageGet) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCStoragePureGet

type TCStoragePureGet struct{}

func (*TCStoragePureGet) Call

func (t *TCStoragePureGet) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCStoragePureGet) Gas

func (t *TCStoragePureGet) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCStoragePureSetBytes

type TCStoragePureSetBytes struct{}

func (*TCStoragePureSetBytes) Call

func (t *TCStoragePureSetBytes) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCStoragePureSetBytes) Gas

func (t *TCStoragePureSetBytes) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCStoragePureSetString

type TCStoragePureSetString struct{}

func (*TCStoragePureSetString) Call

func (t *TCStoragePureSetString) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCStoragePureSetString) Gas

func (t *TCStoragePureSetString) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCStorageSet

type TCStorageSet struct{}

func (*TCStorageSet) Call

func (t *TCStorageSet) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCStorageSet) Gas

func (t *TCStorageSet) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCStorageSetBytes

type TCStorageSetBytes struct{}

func (*TCStorageSetBytes) Call

func (t *TCStorageSetBytes) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCStorageSetBytes) Gas

func (t *TCStorageSetBytes) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCTokenAddress

type TCTokenAddress struct{}

func (*TCTokenAddress) Call

func (t *TCTokenAddress) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCTokenAddress) Gas

func (t *TCTokenAddress) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCTokenBalance

type TCTokenBalance struct{}

func (*TCTokenBalance) Call

func (t *TCTokenBalance) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCTokenBalance) Gas

func (t *TCTokenBalance) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCTransfer

type TCTransfer struct{}

func (*TCTransfer) Call

func (t *TCTransfer) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCTransfer) Gas

func (t *TCTransfer) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TCTransferToken

type TCTransferToken struct{}

func (*TCTransferToken) Call

func (t *TCTransferToken) Call(index int64, ops interface{}, args []uint64) (uint64, error)

func (*TCTransferToken) Gas

func (t *TCTransferToken) Gas(index int64, ops interface{}, args []uint64) (uint64, error)

type TransferFunc

type TransferFunc func(types.StateDB, common.Address, common.Address, common.Address, *big.Int)

TransferFunc is the signature of a transfer function

type UnsafeTransferFunc

type UnsafeTransferFunc func(types.StateDB, common.Address, common.Address, *big.Int)

type WASM

type WASM struct {
	// Context provides auxiliary blockchain related information
	Context
	// StateDB gives access to the underlying state
	StateDB types.StateDB
	// Issued marked that WASM has called tcIssue and may be reverted because of that
	Issued chan bool
	// contains filtered or unexported fields
}

func NewWASM

func NewWASM(c types.Context, statedb types.StateDB, vmc types.VmConfig) *WASM

NewWASM returns a new WASM. The returned WASM is not thread safe and should only ever be used *once*.

func (*WASM) AddOtx

func (wasm *WASM) AddOtx(br types.BalanceRecord)

func (*WASM) Call

func (wasm *WASM) Call(c types.ContractRef, addr, token common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, byteCodeGas uint64, err error)

Call executes the contract associated with the addr with the given input as parameters. It also handles any necessary value transfer required and takes the necessary steps to create accounts and reverses the state in case of an execution error or failed value transfer.

func (*WASM) CallCode

func (wasm *WASM) CallCode(c types.ContractRef, addr common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, byteCodeGas uint64, err error)

CallCode executes the contract associated with the addr with the given input as parameters. It also handles any necessary value transfer required and takes the necessary steps to create accounts and reverses the state in case of an execution error or failed value transfer.

CallCode differs from Call in the sense that it executes the given address' code with the caller as context.

func (*WASM) Cancel

func (wasm *WASM) Cancel()

Cancel cancels any running WASM operation. This may be called concurrently and it's safe to be called multiple times.

func (*WASM) Create

func (wasm *WASM) Create(c types.ContractRef, data []byte, gas uint64, value *big.Int) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error)

Create creates a new contract using code as deployment code.

func (*WASM) DelegateCall

func (wasm *WASM) DelegateCall(c types.ContractRef, addr common.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, byteCodeGas uint64, err error)

DelegateCall executes the contract associated with the addr with the given input as parameters. It reverses the state in case of an execution error.

DelegateCall differs from CallCode in the sense that it executes the given address' code with the caller as context and the caller is set to the caller of the caller.

func (*WASM) GasRate

func (wasm *WASM) GasRate() uint64

func (*WASM) GetBlockNumber

func (wasm *WASM) GetBlockNumber() *big.Int

func (*WASM) GetCode

func (wasm *WASM) GetCode(bz []byte) []byte

func (*WASM) GetCoinbase

func (wasm *WASM) GetCoinbase() common.Address

Coinbase

func (*WASM) GetOTxs

func (wasm *WASM) GetOTxs() []types.BalanceRecord

func (*WASM) GetStateDB

func (wasm *WASM) GetStateDB() types.StateDB

StateDB

func (*WASM) GetTime

func (wasm *WASM) GetTime() *big.Int

Time

func (*WASM) GetUTXOChangeRate added in v0.1.3

func (wasm *WASM) GetUTXOChangeRate(addr common.Address) (int64, error)

func (*WASM) GetUTXOChangeRatePure added in v0.1.3

func (wasm *WASM) GetUTXOChangeRatePure(addr common.Address) (uint8, error)

func (*WASM) RefundAllFee added in v0.1.1

func (wasm *WASM) RefundAllFee() uint64

func (*WASM) RefundFee added in v0.1.1

func (wasm *WASM) RefundFee() uint64

func (*WASM) Reset

func (wasm *WASM) Reset(msg types.Message)

reset func (wasm *WASM) Reset(origin common.Address, gasPrice *big.Int, nonce uint64) {

func (*WASM) SetToken

func (wasm *WASM) SetToken(token common.Address)

Token

func (*WASM) StaticCall

func (wasm *WASM) StaticCall(c types.ContractRef, addr common.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, byteCodeGas uint64, err error)

StaticCall executes the contract associated with the addr with the given input as parameters while disallowing any modifications to the state during the call. Opcodes that attempt to perform such modifications will result in exceptions instead of performing the modifications.

func (*WASM) UTXOCall

func (wasm *WASM) UTXOCall(c types.ContractRef, addr, token common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, byteCodeGas uint64, err error)

func (*WASM) Upgrade

func (wasm *WASM) Upgrade(caller types.ContractRef, contractAddr common.Address, code []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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