types

package
v0.0.0-...-9687111 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2020 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModuleName string name of module
	ModuleName = "evm"

	// EvmStoreKey key for ethereum storage data
	EvmStoreKey = "evmstore"
	// EvmCodeKey key for ethereum code data
	EvmCodeKey = "evmcode"
	// EvmBlockKey key for ethereum block data
	EvmBlockKey = "evmblock"

	// RouterKey uses module name for routing
	RouterKey = ModuleName
)
View Source
const (
	TypeEthereumTxMsg  = "ethereum_tx"
	RouteEthereumTxMsg = RouterKey
)

message type and route constants

View Source
const (
	// TypeEmintMsg defines the type string of Emint message
	TypeEmintMsg = "emint_tx"
)

Variables

View Source
var ModuleCdc = codec.New()

ModuleCdc defines the codec to be used by evm module

Functions

func DecodeReturnData

func DecodeReturnData(bytes []byte) (addr ethcmn.Address, bloom ethtypes.Bloom, ret []byte, err error)

DecodeReturnData decodes the byte slice of values to their respective types

func EncodeReturnData

func EncodeReturnData(addr ethcmn.Address, bloom ethtypes.Bloom, evmRet []byte) []byte

EncodeReturnData takes all of the necessary data from the EVM execution and returns the data as a byte slice

func GenerateChainConfig

func GenerateChainConfig(chainID *big.Int) *params.ChainConfig

GenerateChainConfig returns an Ethereum chainconfig for EVM state transitions

func GenerateEthAddress

func GenerateEthAddress() ethcmn.Address

GenerateEthAddress generates an Ethereum address.

func RegisterAmino

func RegisterAmino(cdc *codec.Codec)

RegisterAmino registers all crypto related types in the given (amino) codec.

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec registers concrete types and interfaces on the given codec.

func TxDecoder

func TxDecoder(cdc *codec.Codec) sdk.TxDecoder

TxDecoder returns an sdk.TxDecoder that can decode both auth.StdTx and EthereumTxMsg transactions.

func ValidateSigner

func ValidateSigner(signBytes, sig []byte, signer ethcmn.Address) error

ValidateSigner attempts to validate a signer for a given slice of bytes over which a signature and signer is given. An error is returned if address derived from the signature and bytes signed does not match the given signer.

Types

type CommitStateDB

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

CommitStateDB implements the Geth state.StateDB interface. Instead of using a trie and database for querying and persistence, the Keeper uses KVStores and an account mapper is used to facilitate state transitions.

TODO: This implementation is subject to change in regards to its statefull manner. In otherwords, how this relates to the keeper in this module.

func NewCommitStateDB

func NewCommitStateDB(ctx sdk.Context, ak auth.AccountKeeper, storageKey, codeKey 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 (*CommitStateDB) AddBalance

func (csdb *CommitStateDB) AddBalance(addr ethcmn.Address, amount *big.Int)

AddBalance adds amount to the account associated with addr.

func (*CommitStateDB) AddLog

func (csdb *CommitStateDB) AddLog(log *ethtypes.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 ethcmn.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() ethcmn.Hash

BlockHash returns the current block hash set by Prepare.

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 ethcmn.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.

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 ethcmn.Address)

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) Database

func (csdb *CommitStateDB) Database() ethstate.Database

Database retrieves the low level database supporting the lower level trie ops. It is not used in Ethermint, so it returns nil.

func (*CommitStateDB) Empty

func (csdb *CommitStateDB) Empty(addr ethcmn.Address) 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 ethcmn.Address) bool

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

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 ethcmn.Address, cb func(key, value ethcmn.Hash) bool) error

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

func (*CommitStateDB) GetBalance

func (csdb *CommitStateDB) GetBalance(addr ethcmn.Address) *big.Int

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

func (*CommitStateDB) GetCode

func (csdb *CommitStateDB) GetCode(addr ethcmn.Address) []byte

GetCode returns the code for a given account.

func (*CommitStateDB) GetCodeHash

func (csdb *CommitStateDB) GetCodeHash(addr ethcmn.Address) ethcmn.Hash

GetCodeHash returns the code hash for a given account.

func (*CommitStateDB) GetCodeSize

func (csdb *CommitStateDB) GetCodeSize(addr ethcmn.Address) int

GetCodeSize returns the code size for a given account.

func (*CommitStateDB) GetCommittedState

func (csdb *CommitStateDB) GetCommittedState(addr ethcmn.Address, hash ethcmn.Hash) ethcmn.Hash

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

func (*CommitStateDB) GetLogs

func (csdb *CommitStateDB) GetLogs(hash ethcmn.Hash) []*ethtypes.Log

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

func (*CommitStateDB) GetNonce

func (csdb *CommitStateDB) GetNonce(addr ethcmn.Address) uint64

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

func (*CommitStateDB) GetOrNewStateObject

func (csdb *CommitStateDB) GetOrNewStateObject(addr ethcmn.Address) 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 ethcmn.Address, hash ethcmn.Hash) ethcmn.Hash

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

func (*CommitStateDB) HasSuicided

func (csdb *CommitStateDB) HasSuicided(addr ethcmn.Address) bool

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

func (*CommitStateDB) IntermediateRoot

func (csdb *CommitStateDB) IntermediateRoot(deleteEmptyObjects bool) ethcmn.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() []*ethtypes.Log

Logs returns all the current logs in the state.

func (*CommitStateDB) Preimages

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

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

func (*CommitStateDB) Prepare

func (csdb *CommitStateDB) Prepare(thash, bhash ethcmn.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) RawDump

func (csdb *CommitStateDB) RawDump() ethstate.Dump

RawDump returns a raw state dump.

TODO: Implement if we need it, especially for the RPC API.

func (*CommitStateDB) Reset

func (csdb *CommitStateDB) Reset(_ ethcmn.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 ethcmn.Address, amount *big.Int)

SetBalance sets the balance of an account.

func (*CommitStateDB) SetCode

func (csdb *CommitStateDB) SetCode(addr ethcmn.Address, code []byte)

SetCode sets the code for a given account.

func (*CommitStateDB) SetNonce

func (csdb *CommitStateDB) SetNonce(addr ethcmn.Address, nonce uint64)

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

func (*CommitStateDB) SetState

func (csdb *CommitStateDB) SetState(addr ethcmn.Address, key, value ethcmn.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) StorageTrie

func (csdb *CommitStateDB) StorageTrie(addr ethcmn.Address) ethstate.Trie

StorageTrie returns nil as the state in Ethermint does not use a direct storage trie.

func (*CommitStateDB) SubBalance

func (csdb *CommitStateDB) SubBalance(addr ethcmn.Address, 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 ethcmn.Address) 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

type EmintMsg

type EmintMsg struct {
	AccountNonce uint64          `json:"nonce"`
	Price        sdk.Int         `json:"gasPrice"`
	GasLimit     uint64          `json:"gas"`
	Recipient    *sdk.AccAddress `json:"to" rlp:"nil"` // nil means contract creation
	Amount       sdk.Int         `json:"value"`
	Payload      []byte          `json:"input"`

	// From address (formerly derived from signature)
	From sdk.AccAddress `json:"from"`
}

EmintMsg implements a cosmos equivalent structure for Ethereum transactions

func NewEmintMsg

func NewEmintMsg(
	nonce uint64, to *sdk.AccAddress, amount sdk.Int,
	gasLimit uint64, gasPrice sdk.Int, payload []byte, from sdk.AccAddress,
) EmintMsg

NewEmintMsg returns a reference to a new Ethermint transaction

func (EmintMsg) GetSignBytes

func (msg EmintMsg) GetSignBytes() []byte

GetSignBytes encodes the message for signing

func (EmintMsg) GetSigners

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

GetSigners defines whose signature is required

func (EmintMsg) Route

func (msg EmintMsg) Route() string

Route should return the name of the module

func (EmintMsg) To

func (msg EmintMsg) To() *ethcmn.Address

To returns the recipient address of the transaction. It returns nil if the transaction is a contract creation.

func (EmintMsg) Type

func (msg EmintMsg) Type() string

Type returns the action of the message

func (EmintMsg) ValidateBasic

func (msg EmintMsg) ValidateBasic() error

ValidateBasic runs stateless checks on the message

type EncodableTxData

type EncodableTxData struct {
	AccountNonce uint64          `json:"nonce"`
	Price        string          `json:"gasPrice"`
	GasLimit     uint64          `json:"gas"`
	Recipient    *ethcmn.Address `json:"to" rlp:"nil"` // nil means contract creation
	Amount       string          `json:"value"`
	Payload      []byte          `json:"input"`

	// signature values
	V string `json:"v"`
	R string `json:"r"`
	S string `json:"s"`

	// hash is only used when marshaling to JSON
	Hash *ethcmn.Hash `json:"hash" rlp:"-"`
}

EncodableTxData implements the Ethereum transaction data structure. It is used solely as intended in Ethereum abiding by the protocol.

type EthereumTxMsg

type EthereumTxMsg struct {
	Data TxData
	// contains filtered or unexported fields
}

EthereumTxMsg encapsulates an Ethereum transaction as an SDK message.

func NewEthereumTxMsg

func NewEthereumTxMsg(
	nonce uint64, to *ethcmn.Address, amount *big.Int,
	gasLimit uint64, gasPrice *big.Int, payload []byte,
) *EthereumTxMsg

NewEthereumTxMsg returns a reference to a new Ethereum transaction message.

func NewEthereumTxMsgContract

func NewEthereumTxMsgContract(
	nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, payload []byte,
) *EthereumTxMsg

NewEthereumTxMsgContract returns a reference to a new Ethereum transaction message designated for contract creation.

func (*EthereumTxMsg) ChainID

func (msg *EthereumTxMsg) ChainID() *big.Int

ChainID returns which chain id this transaction was signed for (if at all)

func (EthereumTxMsg) Cost

func (msg EthereumTxMsg) Cost() *big.Int

Cost returns amount + gasprice * gaslimit.

func (*EthereumTxMsg) DecodeRLP

func (msg *EthereumTxMsg) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements the rlp.Decoder interface.

func (*EthereumTxMsg) EncodeRLP

func (msg *EthereumTxMsg) EncodeRLP(w io.Writer) error

EncodeRLP implements the rlp.Encoder interface.

func (EthereumTxMsg) Fee

func (msg EthereumTxMsg) Fee() *big.Int

Fee returns gasprice * gaslimit.

func (EthereumTxMsg) GetMsgs

func (msg EthereumTxMsg) GetMsgs() []sdk.Msg

GetMsgs returns a single EthereumTxMsg as an sdk.Msg.

func (EthereumTxMsg) GetSignBytes

func (msg EthereumTxMsg) GetSignBytes() []byte

GetSignBytes returns the Amino bytes of an Ethereum transaction message used for signing.

NOTE: This method cannot be used as a chain ID is needed to create valid bytes to sign over. Use 'RLPSignBytes' instead.

func (EthereumTxMsg) GetSigners

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

GetSigners returns the expected signers for an Ethereum transaction message. For such a message, there should exist only a single 'signer'.

NOTE: This method cannot be used as a chain ID is needed to recover the signer from the signature. Use 'VerifySig' instead.

func (*EthereumTxMsg) Hash

func (msg *EthereumTxMsg) Hash() ethcmn.Hash

Hash hashes the RLP encoding of a transaction.

func (EthereumTxMsg) RLPSignBytes

func (msg EthereumTxMsg) RLPSignBytes(chainID *big.Int) ethcmn.Hash

RLPSignBytes returns the RLP hash of an Ethereum transaction message with a given chainID used for signing.

func (EthereumTxMsg) Route

func (msg EthereumTxMsg) Route() string

Route returns the route value of an EthereumTxMsg.

func (*EthereumTxMsg) Sign

func (msg *EthereumTxMsg) Sign(chainID *big.Int, priv *ecdsa.PrivateKey)

Sign calculates a secp256k1 ECDSA signature and signs the transaction. It takes a private key and chainID to sign an Ethereum transaction according to EIP155 standard. It mutates the transaction as it populates the V, R, S fields of the Transaction's Signature.

func (EthereumTxMsg) To

func (msg EthereumTxMsg) To() *ethcmn.Address

To returns the recipient address of the transaction. It returns nil if the transaction is a contract creation.

func (EthereumTxMsg) Type

func (msg EthereumTxMsg) Type() string

Type returns the type value of an EthereumTxMsg.

func (EthereumTxMsg) ValidateBasic

func (msg EthereumTxMsg) ValidateBasic() error

ValidateBasic implements the sdk.Msg interface. It performs basic validation checks of a Transaction. If returns an sdk.Error if validation fails.

func (*EthereumTxMsg) VerifySig

func (msg *EthereumTxMsg) VerifySig(chainID *big.Int) (ethcmn.Address, error)

VerifySig attempts to verify a Transaction's signature for a given chainID. A derived address is returned upon success or an error if recovery fails.

type QueryAccount

type QueryAccount struct {
	Balance  string `json:"balance"`
	CodeHash []byte `json:"codeHash"`
	Nonce    uint64 `json:"nonce"`
}

QueryAccount is response type for querying Ethereum state objects

type QueryBloomFilter

type QueryBloomFilter struct {
	Bloom ethtypes.Bloom `json:"bloom"`
}

QueryBloomFilter is response type for tx logs query

func (QueryBloomFilter) String

func (q QueryBloomFilter) String() string

type QueryETHLogs

type QueryETHLogs struct {
	Logs []*ethtypes.Log `json:"logs"`
}

QueryETHLogs is response type for tx logs query

func (QueryETHLogs) String

func (q QueryETHLogs) String() string

type QueryResBalance

type QueryResBalance struct {
	Balance string `json:"balance"`
}

QueryResBalance is response type for balance query

func (QueryResBalance) String

func (q QueryResBalance) String() string

type QueryResBlockNumber

type QueryResBlockNumber struct {
	Number int64 `json:"blockNumber"`
}

QueryResBlockNumber is response type for block number query

func (QueryResBlockNumber) String

func (q QueryResBlockNumber) String() string

type QueryResCode

type QueryResCode struct {
	Code []byte
}

QueryResCode is response type for code query

func (QueryResCode) String

func (q QueryResCode) String() string

type QueryResNonce

type QueryResNonce struct {
	Nonce uint64 `json:"nonce"`
}

QueryResNonce is response type for Nonce query

func (QueryResNonce) String

func (q QueryResNonce) String() string

type QueryResProtocolVersion

type QueryResProtocolVersion struct {
	Version string `json:"version"`
}

QueryResProtocolVersion is response type for protocol version query

func (QueryResProtocolVersion) String

func (q QueryResProtocolVersion) String() string

type QueryResStorage

type QueryResStorage struct {
	Value []byte `json:"value"`
}

QueryResStorage is response type for storage query

func (QueryResStorage) String

func (q QueryResStorage) String() string

type StateObject

type StateObject interface {
	GetCommittedState(db ethstate.Database, key ethcmn.Hash) ethcmn.Hash
	GetState(db ethstate.Database, key ethcmn.Hash) ethcmn.Hash
	SetState(db ethstate.Database, key, value ethcmn.Hash)

	Code(db ethstate.Database) []byte
	SetCode(codeHash ethcmn.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() ethcmn.Address

	SetNonce(nonce uint64)
	Nonce() uint64
}

StateObject interface for interacting with state object

type StateTransition

type StateTransition struct {
	Sender       common.Address
	AccountNonce uint64
	Price        *big.Int
	GasLimit     uint64
	Recipient    *common.Address
	Amount       *big.Int
	Payload      []byte
	Csdb         *CommitStateDB
	ChainID      *big.Int
	THash        *common.Hash
	Simulate     bool
}

StateTransition defines data to transitionDB in evm

func (StateTransition) TransitionCSDB

func (st StateTransition) TransitionCSDB(ctx sdk.Context) (*big.Int, sdk.Result, error)

TransitionCSDB performs an evm state transition from a transaction

type TxData

type TxData struct {
	AccountNonce uint64          `json:"nonce"`
	Price        *big.Int        `json:"gasPrice"`
	GasLimit     uint64          `json:"gas"`
	Recipient    *ethcmn.Address `json:"to" rlp:"nil"` // nil means contract creation
	Amount       *big.Int        `json:"value"`
	Payload      []byte          `json:"input"`

	// signature values
	V *big.Int `json:"v"`
	R *big.Int `json:"r"`
	S *big.Int `json:"s"`

	// hash is only used when marshaling to JSON
	Hash *ethcmn.Hash `json:"hash" rlp:"-"`
}

TxData implements the Ethereum transaction data structure. It is used solely as intended in Ethereum abiding by the protocol.

func (TxData) MarshalAmino

func (td TxData) MarshalAmino() (string, error)

MarshalAmino defines custom encoding scheme for TxData

func (*TxData) UnmarshalAmino

func (td *TxData) UnmarshalAmino(text string) (err error)

UnmarshalAmino defines custom decoding scheme for TxData

Jump to

Keyboard shortcuts

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