types

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const (
	EventTypeContractCreated = "contract_created"
	EventTypeContractCalled  = "contract_called"

	AttributeKeyAddress    = "address"
	AttributeValueCategory = "vm"
)
View Source
const (
	ModuleName   = protocol.VMModuleName
	StoreKey     = ModuleName
	QuerierRoute = ModuleName
	RouterKey    = ModuleName
)
View Source
const (
	TypeMsgContractCreate = "contract_create"
	TypeMsgContractCall   = "contract_call"
)
View Source
const (
	QueryParameters = "params"
	QueryState      = "state"
	QueryCode       = "code"
	QueryStorage    = "storage"
	QueryTxLogs     = "logs"
	EstimateGas     = "estimate_gas"
	QueryCall       = "call"
)

Variables

View Source
var (
	ErrNoPayload                = sdkerrors.New(ModuleName, 1, "no payload")
	ErrOutOfGas                 = sdkerrors.New(ModuleName, 2, "out of gas")
	ErrCodeStoreOutOfGas        = sdkerrors.New(ModuleName, 3, "contract creation code storage out of gas")
	ErrDepth                    = sdkerrors.New(ModuleName, 4, "max call depth exceeded")
	ErrTraceLimitReached        = sdkerrors.New(ModuleName, 5, "the number of logs reached the specified limit")
	ErrNoCompatibleInterpreter  = sdkerrors.New(ModuleName, 6, "no compatible interpreter")
	ErrEmptyInputs              = sdkerrors.New(ModuleName, 7, "empty input")
	ErrInsufficientBalance      = sdkerrors.New(ModuleName, 8, "insufficient balance for transfer")
	ErrContractAddressCollision = sdkerrors.New(ModuleName, 9, "contract address collision")
	ErrNoCodeExist              = sdkerrors.New(ModuleName, 10, "no code exists")
	ErrMaxCodeSizeExceeded      = sdkerrors.New(ModuleName, 11, "evm: max code size exceeded")
	ErrWriteProtection          = sdkerrors.New(ModuleName, 12, "vm: write protection")
	ErrReturnDataOutOfBounds    = sdkerrors.New(ModuleName, 13, "evm: return data out of bounds")
	ErrExecutionReverted        = sdkerrors.New(ModuleName, 14, "evm: execution reverted")
	ErrInvalidJump              = sdkerrors.New(ModuleName, 15, "evm: invalid jump destination")
	ErrGasUintOverflow          = sdkerrors.New(ModuleName, 16, "gas uint64 overflow")
	ErrWrongCtx                 = sdkerrors.New(ModuleName, 17, "must be simulate mode when gas limit is 0")
)
View Source
var (
	KeyPrefixLogs      = []byte{0x01}
	KeyPrefixLogsIndex = []byte{0x02}
	KeyPrefixCode      = []byte{0x03}
	KeyPrefixStorage   = []byte{0x04}
)

KVStore key prefixes

View Source
var (
	KeyMaxCodeSize                 = []byte("MaxCodeSize")
	KeyMaxCallCreateDepth          = []byte("MaxCallCreateDepth")
	KeyVMOpGasParams               = []byte("VMOpGasParams")
	KeyVMContractCreationGasParams = []byte("VMContractCreationGasParams")

	DefaultVMOpGasParams = [256]uint64{}/* 256 elements not displayed */

)

nolint

View Source
var (
	LogIndexKey = []byte("logIndexKey")
)
View Source
var ModuleCdc *codec.Codec

ModuleCdc - generic sealed codec to be used throughout this module

Functions

func AddressStoragePrefix

func AddressStoragePrefix(address sdk.Address) []byte

AddressStoragePrefix returns a prefix to iterate over a given account storage.

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec - register the sdk message type

func ValidateGenesis

func ValidateGenesis(data GenesisState) error

Types

type AccountKeeper

type AccountKeeper interface {
	NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) exported.Account
	RemoveAccount(ctx sdk.Context, acc exported.Account)
	GetAccount(ctx sdk.Context, addr sdk.AccAddress) exported.Account
	SetAccount(ctx sdk.Context, acc exported.Account)
}

AccountKeeper defines the expected account keeper used for vm

type BankKeeper

type BankKeeper interface {
	SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
}

BankKeeper defines the expected bank keeper used for vm

type CommitStateDB

type CommitStateDB struct {
	// contains filtered or unexported fields
}

func NewCommitStateDB

func NewCommitStateDB(ak auth.AccountKeeper, storageKey sdk.StoreKey) *CommitStateDB

NewCommitStateDB returns a reference to a newly initialized CommitStateDB which implements Geth's state.StateDB interface.

CONTRACT: Stores used for state must be cache-wrapped as the ordering of the key/value space matters in determining the merkle root. func NewCommitStateDB(ctx sdk.Context, ak auth.AccountKeeper, storageKey, codeKey sdk.StoreKey) *CommitStateDB {

func NewStateDB

func NewStateDB(db *CommitStateDB) *CommitStateDB

func (*CommitStateDB) AddBalance

func (csdb *CommitStateDB) AddBalance(addr sdk.AccAddress, amount *big.Int)

AddBalance adds amount to the account associated with addr.

func (*CommitStateDB) AddLog

func (csdb *CommitStateDB) AddLog(log *Log)

AddLog adds a new log to the state and sets the log metadata from the state.

func (*CommitStateDB) AddPreimage

func (csdb *CommitStateDB) AddPreimage(hash sdk.Hash, preimage []byte)

AddPreimage records a SHA3 preimage seen by the VM.

func (*CommitStateDB) AddRefund

func (csdb *CommitStateDB) AddRefund(gas uint64)

AddRefund adds gas to the refund counter.

func (*CommitStateDB) BlockHash

func (csdb *CommitStateDB) BlockHash() sdk.Hash

BlockHash returns the current block hash set by Prepare.

func (*CommitStateDB) ClearLogs

func (csdb *CommitStateDB) ClearLogs()

func (*CommitStateDB) ClearStateObjects

func (csdb *CommitStateDB) ClearStateObjects()

ClearStateObjects clears cache of state objects to handle account changes outside of the EVM

func (*CommitStateDB) Commit

func (csdb *CommitStateDB) Commit(deleteEmptyObjects bool) (root sdk.Hash, err error)

Commit writes the state to the appropriate KVStores. For each state object in the cache, it will either be removed, or have it's code set and/or it's state (storage) updated. In addition, the state object (account) itself will be written. Finally, the root hash (version) will be returned. nolint

func (*CommitStateDB) ContractCalledEvent added in v1.0.2

func (csdb *CommitStateDB) ContractCalledEvent(addr sdk.AccAddress)

ContractCalledEvent emit event of contract called nolint

func (*CommitStateDB) ContractCreatedEvent

func (csdb *CommitStateDB) ContractCreatedEvent(addr sdk.AccAddress)

ContractCreatedEvent emit event of contract created nolint

func (*CommitStateDB) Copy

func (csdb *CommitStateDB) Copy() *CommitStateDB

Copy creates a deep, independent copy of the state.

NOTE: Snapshots of the copied state cannot be applied to the copy.

func (*CommitStateDB) CreateAccount

func (csdb *CommitStateDB) CreateAccount(addr sdk.AccAddress)

CreateAccount explicitly creates a state object. If a state object with the address already exists the balance is carried over to the new account.

CreateAccount is called during the EVM CREATE operation. The situation might arise that a contract does the following:

  1. sends funds to sha(account ++ (nonce + 1))
  2. tx_create(sha(account ++ nonce)) (note that this gets the address of 1)

Carrying over the balance ensures that Ether doesn't disappear.

func (*CommitStateDB) Empty

func (csdb *CommitStateDB) Empty(addr sdk.AccAddress) bool

Empty returns whether the state object is either non-existent or empty according to the EIP161 specification (balance = nonce = code = 0).

func (*CommitStateDB) Error

func (csdb *CommitStateDB) Error() error

Error returns the first non-nil error the StateDB encountered.

func (*CommitStateDB) Exist

func (csdb *CommitStateDB) Exist(addr sdk.AccAddress) bool

Exist reports whether the given account address exists in the state. Notably, this also returns true for suicided accounts.

func (*CommitStateDB) ExportState

func (csdb *CommitStateDB) ExportState() (s GenesisState)

ExportState used to export vm state to genesis file

func (*CommitStateDB) ExportStateObjects

func (csdb *CommitStateDB) ExportStateObjects(params QueryStateParams) (sos SOs)

func (*CommitStateDB) Finalise

func (csdb *CommitStateDB) Finalise(deleteEmptyObjects bool)

Finalise finalizes the state objects (accounts) state by setting their state, removing the csdb destructed objects and clearing the journal as well as the refunds.

func (*CommitStateDB) ForEachStorage

func (csdb *CommitStateDB) ForEachStorage(addr sdk.AccAddress, cb func(key, value sdk.Hash) bool) error

ForEachStorage iterates over each storage items, all invokes the provided callback on each key, value pair .

func (*CommitStateDB) GetAllHotContractAddrs

func (csdb *CommitStateDB) GetAllHotContractAddrs() (accs []sdk.AccAddress)

for simulation

func (*CommitStateDB) GetBalance

func (csdb *CommitStateDB) GetBalance(addr sdk.AccAddress) *big.Int

GetBalance retrieves the balance from the given address or 0 if object not found.

func (*CommitStateDB) GetCode

func (csdb *CommitStateDB) GetCode(addr sdk.AccAddress) []byte

GetCode returns the code for a given account.

func (*CommitStateDB) GetCodeHash

func (csdb *CommitStateDB) GetCodeHash(addr sdk.AccAddress) sdk.Hash

GetCodeHash returns the code hash for a given account.

func (*CommitStateDB) GetCodeSize

func (csdb *CommitStateDB) GetCodeSize(addr sdk.AccAddress) int

GetCodeSize returns the code size for a given account.

func (*CommitStateDB) GetCommittedState

func (csdb *CommitStateDB) GetCommittedState(addr sdk.AccAddress, hash sdk.Hash) sdk.Hash

GetCommittedState retrieves a value from the given account's committed storage.

func (*CommitStateDB) GetLogs

func (csdb *CommitStateDB) GetLogs(hash sdk.Hash) (logs []*Log)

GetLogs returns the current logs for a given hash in the state.

func (*CommitStateDB) GetNonce

func (csdb *CommitStateDB) GetNonce(addr sdk.AccAddress) uint64

GetNonce returns the nonce (sequence number) for a given account.

func (*CommitStateDB) GetOrNewStateObject

func (csdb *CommitStateDB) GetOrNewStateObject(addr sdk.AccAddress) StateObject

GetOrNewStateObject retrieves a state object or create a new state object if nil.

func (*CommitStateDB) GetRefund

func (csdb *CommitStateDB) GetRefund() uint64

GetRefund returns the current value of the refund counter.

func (*CommitStateDB) GetState

func (csdb *CommitStateDB) GetState(addr sdk.AccAddress, hash sdk.Hash) sdk.Hash

GetState retrieves a value from the given account's storage store.

func (*CommitStateDB) HasSuicided

func (csdb *CommitStateDB) HasSuicided(addr sdk.AccAddress) bool

HasSuicided returns if the given account for the specified address has been killed.

func (*CommitStateDB) ImportState

func (csdb *CommitStateDB) ImportState(s GenesisState)

ImportState used to import vm state from genesis file

func (*CommitStateDB) IntermediateRoot

func (csdb *CommitStateDB) IntermediateRoot(deleteEmptyObjects bool) sdk.Hash

IntermediateRoot returns the current root hash of the state. It is called in between transactions to get the root hash that goes into transaction receipts.

NOTE: The SDK has not concept or method of getting any intermediate merkle root as commitment of the merkle-ized tree doesn't happen until the BaseApps' EndBlocker.

func (*CommitStateDB) Logs

func (csdb *CommitStateDB) Logs() []*Log

Logs returns all the current logs in the state.

func (*CommitStateDB) Preimages

func (csdb *CommitStateDB) Preimages() map[sdk.Hash][]byte

Preimages returns a list of SHA3 preimages that have been submitted.

func (*CommitStateDB) Prepare

func (csdb *CommitStateDB) Prepare(thash, bhash sdk.Hash, txi int)

Prepare sets the current transaction hash and index and block hash which is used when the EVM emits new state logs.

func (*CommitStateDB) Reset

func (csdb *CommitStateDB) Reset(_ sdk.Hash) error

Reset clears out all ephemeral state objects from the state db, but keeps the underlying account mapper and store keys to avoid reloading data for the next operations.

func (*CommitStateDB) RevertToSnapshot

func (csdb *CommitStateDB) RevertToSnapshot(revID int)

RevertToSnapshot reverts all state changes made since the given revision.

func (*CommitStateDB) SetBalance

func (csdb *CommitStateDB) SetBalance(addr sdk.AccAddress, amount *big.Int)

SetBalance sets the balance of an account.

func (*CommitStateDB) SetCode

func (csdb *CommitStateDB) SetCode(addr sdk.AccAddress, code []byte)

SetCode sets the code for a given account.

func (*CommitStateDB) SetNonce

func (csdb *CommitStateDB) SetNonce(addr sdk.AccAddress, nonce uint64)

SetNonce sets the nonce (sequence number) of an account.

func (*CommitStateDB) SetState

func (csdb *CommitStateDB) SetState(addr sdk.AccAddress, key, value sdk.Hash)

SetState sets the storage state with a key, value pair for an account.

func (*CommitStateDB) Snapshot

func (csdb *CommitStateDB) Snapshot() int

Snapshot returns an identifier for the current revision of the state.

func (*CommitStateDB) SubBalance

func (csdb *CommitStateDB) SubBalance(addr sdk.AccAddress, amount *big.Int)

SubBalance subtracts amount from the account associated with addr.

func (*CommitStateDB) SubRefund

func (csdb *CommitStateDB) SubRefund(gas uint64)

SubRefund removes gas from the refund counter. It will panic if the refund counter goes below zero.

func (*CommitStateDB) Suicide

func (csdb *CommitStateDB) Suicide(addr sdk.AccAddress) bool

Suicide marks the given account as suicided and clears the account balance.

The account's state object is still available until the state is committed, getStateObject will return a non-nil account after Suicide.

func (*CommitStateDB) TxIndex

func (csdb *CommitStateDB) TxIndex() int

TxIndex returns the current transaction index set by Prepare.

func (*CommitStateDB) UpdateAccounts

func (csdb *CommitStateDB) UpdateAccounts()

UpdateAccounts updates the nonce and coin balances of accounts

func (*CommitStateDB) WithContext

func (csdb *CommitStateDB) WithContext(ctx sdk.Context) *CommitStateDB

WithContext returns a Database with an updated sdk context

func (*CommitStateDB) WithTxHash

func (csdb *CommitStateDB) WithTxHash(txHash []byte) *CommitStateDB

type GenesisState

type GenesisState struct {
	Params  Params              `json:"params"`
	Storage []Storage           `json:"storage"`
	Codes   map[string]sdk.Code `json:"codes"`
	VMLogs  VMLogs              `json:"vm_logs"`
}

GenesisState vm genesis state, include params, vm storage, vm codes, vm logs

func DefaultGenesisState

func DefaultGenesisState() GenesisState

func NewGenesisState

func NewGenesisState(params Params) GenesisState

func (GenesisState) Equal

func (a GenesisState) Equal(b GenesisState) bool

Equal judge GenesisState equal

func (GenesisState) EqualWithoutParams

func (a GenesisState) EqualWithoutParams(b GenesisState) bool

EqualWithoutParams judge GenesisState equal without compare GenesisState.Params

type Log

type Log struct {
	// address of the contract that generated the event
	Address sdk.AccAddress `json:"address" yaml:"address"`
	// list of topics provided by the contract.
	Topics []sdk.Hash `json:"topics" yaml:"topics"`
	// supplied by the contract, usually ABI-encoded
	Data hexutil.Bytes `json:"data" yaml:"data"`

	BlockNumber uint64   `json:"blockNumber" yaml:"blockNumber"`
	TxHash      sdk.Hash `json:"transactionHash" yaml:"transactionHash"`
	TxIndex     uint     `json:"transactionIndex" yaml:"transactionIndex"`
	BlockHash   sdk.Hash `json:"blockHash" yaml:"blockHash"`
	Index       uint64   `json:"logIndex" yaml:"logIndex"`

	Removed bool `json:"removed" yaml:"removed"`
}

type MsgContract

type MsgContract struct {
	From    sdk.AccAddress `json:"from" yaml:"from"`
	To      sdk.AccAddress `json:"to" yaml:"to"`
	Payload hexutil.Bytes  `json:"payload" yaml:"payload"`
	Amount  sdk.Coin       `json:"amount" yaml:"amount"`
}

func NewMsgContract

func NewMsgContract(from, to sdk.AccAddress, payload []byte, amount sdk.Coin) MsgContract

func (MsgContract) GetSignBytes

func (msg MsgContract) GetSignBytes() []byte

func (MsgContract) GetSigners

func (msg MsgContract) GetSigners() []sdk.AccAddress

func (MsgContract) Route

func (msg MsgContract) Route() string

func (MsgContract) Type

func (msg MsgContract) Type() string

func (MsgContract) ValidateBasic

func (msg MsgContract) ValidateBasic() error

type MsgContractQuery

type MsgContractQuery MsgContract

func NewMsgContractQuery

func NewMsgContractQuery(from, to sdk.AccAddress, payload []byte, amount sdk.Coin) MsgContractQuery

type Params

type Params struct {
	MaxCodeSize                 uint64                      `json:"max_code_size" yaml:"max_code_size"`
	MaxCallCreateDepth          uint64                      `json:"max_call_create_depth" yaml:"max_call_create_depth"`
	VMOpGasParams               [256]uint64                 `json:"vm_op_gas_params" yaml:"vm_op_gas_params"`
	VMContractCreationGasParams VMContractCreationGasParams `json:"vm_contract_creation_gas_params" yaml:"vm_contract_creation_gas_params"`
}

func DefaultParams

func DefaultParams() Params

func NewParams

func NewParams(maxCodeSize, callCreateDepth uint64, vmOpGasParams [256]uint64, vmContractCreationGasParams VMContractCreationGasParams) Params

NewParams return Params

func (*Params) ParamSetPairs

func (p *Params) ParamSetPairs() params.ParamSetPairs

func (Params) String

func (p Params) String() string

type QueryLogsResult

type QueryLogsResult struct {
	Logs []*Log `json:"logs"`
}

QueryLogsResult - for query logs

func (QueryLogsResult) String

func (q QueryLogsResult) String() string

type QueryStateParams

type QueryStateParams struct {
	ShowCode     bool `json:"show_code" yaml:"show_code"`
	ContractOnly bool `json:"contract_only" yaml:"contract_only"`
}

QueryStateParams - for query vm db state

type QueryStorageResult

type QueryStorageResult struct {
	Value sdk.Hash `json:"value"`
}

QueryStorageResult - for query storage

func (QueryStorageResult) String

func (q QueryStorageResult) String() string

type SO

type SO struct {
	Address       sdk.AccAddress    `json:"address" yaml:"address"`
	BaseAccount   types.BaseAccount `json:"base_account" yaml:"base_account"`
	OriginStorage sdk.Storage       `json:"origin_storage" yaml:"origin_storage"`
	DirtyStorage  sdk.Storage       `json:"dirty_storage" yaml:"dirty_storage"`
	DirtyCode     bool              `json:"dirty_code" yaml:"dirty_code"`
	Suicided      bool              `json:"suicided" yaml:"suicided"`
	Deleted       bool              `json:"deleted" yaml:"deleted"`
	Code          sdk.Code          `json:"code" yaml:"code"`
}

type SOs

type SOs []SO

type SimulationResult

type SimulationResult struct {
	Gas uint64
	Res string
}

SimulationResult - for Gas Estimate

func (SimulationResult) String

func (r SimulationResult) String() string

type StateObject

type StateObject interface {
	GetCommittedState(key sdk.Hash) sdk.Hash
	GetState(key sdk.Hash) sdk.Hash
	SetState(key, value sdk.Hash)

	Code() []byte
	SetCode(codeHash sdk.Hash, code []byte)
	CodeHash() []byte

	AddBalance(amount *big.Int)
	SubBalance(amount *big.Int)
	SetBalance(amount *big.Int)

	Balance() *big.Int
	ReturnGas(gas *big.Int)
	Address() sdk.Address

	SetNonce(nonce uint64)
	Nonce() uint64
}

StateObject interface for interacting with state object

type Storage

type Storage struct {
	Key   hexutil.Bytes `json:"k"`
	Value hexutil.Bytes `json:"v"`
}

Storage vm storage of k, v pairs

type VMContractCreationGasParams

type VMContractCreationGasParams struct {
	Gas        uint64 `json:"gas" yaml:"gas"`
	GasPerByte uint64 `json:"gas_per_byte" yaml:"gas_per_byte"`
}

VMContractCreationGasParams contract creation gas params

type VMLogs

type VMLogs struct {
	Logs     map[string]string `json:"logs"`
	LogIndex int64             `json:"log_index"`
}

VMLogs vm logs, include log index, logs which conclude k(txHash), v(logs) pairs

type VMQueryResult

type VMQueryResult struct {
	Gas    uint64
	Result []interface{}
}

VMQueryResult

func (VMQueryResult) String

func (r VMQueryResult) String() string

Jump to

Keyboard shortcuts

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