types

package
v0.0.0-...-3f32f9b Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2019 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeEthereumTxMsg  = "ethereum_tx"
	RouteEthereumTxMsg = "evm"
)

message type and route constants

Variables

This section is empty.

Functions

func GenerateEthAddress

func GenerateEthAddress() ethcmn.Address

GenerateAddress generates an Ethereum address.

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

Register 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, error)

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) 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() ethstate.StateDB

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

func (csdb *CommitStateDB) Finalize(deleteEmptyObjects bool)

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

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) ethstate.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(root 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.

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) 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() sdk.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 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.

Jump to

Keyboard shortcuts

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