eth

package
v2.0.0-rc.9 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Copyright (c) 2023-2024 Nibi, Inc.

Index

Constants

View Source
const (
	EthBaseDenom = appconst.BondDenom
	// EIP155ChainID_Testnet: Chain ID for a testnet Nibiru following the
	// format proposed by Vitalik in EIP155.
	EIP155ChainID_Testnet = "nibirutest_420-1"

	DefaultGasPrice = 20

	// ProtocolVersion: Latest supported version of the Ethereum protocol.
	// Matches the message types and expected APIs.
	// As of April, 2024, the highest protocol version on Ethereum mainnet is
	// "eth/68".
	// See https://github.com/ethereum/devp2p/blob/master/caps/eth.md#change-log
	// for the historical summary of each version.
	ProtocolVersion = 65
)

Variables

View Source
var (
	ErrInvalidLengthAccount        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowAccount          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupAccount = fmt.Errorf("proto: unexpected end of group")
)
View Source
var (
	// Bip44CoinType satisfies EIP84. See https://github.com/ethereum/EIPs/issues/84 for more info.
	Bip44CoinType uint32 = 60

	// BIP44HDPath is the default BIP44 HD path used on Ethereum.
	BIP44HDPath = ethaccounts.DefaultBaseDerivationPath.String()
)
View Source
var (
	ErrInvalidLengthIndexer        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowIndexer          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupIndexer = fmt.Errorf("proto: unexpected end of group")
)
View Source
var (
	// Implements a `collections.ValueEncoder` for the `[]byte` type
	ValueEncoderBytes collections.ValueEncoder[[]byte] = veBytes{}
	KeyEncoderBytes   collections.KeyEncoder[[]byte]   = keBytes{}

	// Implements a `collections.ValueEncoder` for an Ethereum address.
	ValueEncoderEthAddr collections.ValueEncoder[gethcommon.Address] = veEthAddr{}
	// keEthHash: Implements a `collections.KeyEncoder` for an Ethereum address.
	KeyEncoderEthAddr collections.KeyEncoder[gethcommon.Address] = keEthAddr{}

	// keEthHash: Implements a `collections.KeyEncoder` for an Ethereum hash.
	KeyEncoderEthHash collections.KeyEncoder[gethcommon.Hash] = keEthHash{}
)
View Source
var (
	ErrInvalidChainID = registerError("invalid Ethereum chain ID")
)

Module "sentinel" errors

Functions

func BlockGasLimit

func BlockGasLimit(ctx sdk.Context) (gasLimit uint64)

BlockGasLimit: Gas (limit) as defined by the block gas meter. Gas limit is derived from the consensus params if the block gas meter is nil.

func BloomFromHex

func BloomFromHex(bloomHex string) (gethcore.Bloom, error)

BloomFromHex converts a hex-encoded bloom filter to a gethcore.Bloom.

func BloomToHex

func BloomToHex(bloom gethcore.Bloom) string

BloomToHex returns the bloom filter as a string.

func BytesToHex

func BytesToHex(bz []byte) string

BytesToHex converts a byte array to a hexadecimal string

func EthAddrToNibiruAddr

func EthAddrToNibiruAddr(ethAddr gethcommon.Address) sdk.AccAddress

func EthTxHashToString

func EthTxHashToString(hash gethcommon.Hash) string

EthTxHashToString returns the EVM transaction hash as a string.

func IsEmptyHash

func IsEmptyHash(hash string) bool

IsEmptyHash returns true if the hash corresponds to an empty ethereum hex hash.

func IsValidChainID

func IsValidChainID(chainID string) bool

IsValidChainID returns false if the given chain identifier is incorrectly formatted.

func IsValidInt256

func IsValidInt256(i *big.Int) bool

IsValidInt256 check the bound of 256 bit number

func IsZeroAddress

func IsZeroAddress(address string) bool

IsZeroAddress returns true if the address corresponds to an empty ethereum hex address.

func NewInfiniteGasMeter

func NewInfiniteGasMeter() sdk.GasMeter

NewInfiniteGasMeter: Alias for an infinite gas meter ([NewInfiniteGasMeterWithLimitla)] with a tracked but unenforced gas limit.

func NewInfiniteGasMeterWithLimit

func NewInfiniteGasMeterWithLimit(limit sdk.Gas) sdk.GasMeter

NewInfiniteGasMeterWithLimit returns a reference to a new infiniteGasMeter.

func NibiruAddrToEthAddr

func NibiruAddrToEthAddr(nibiruAddr sdk.AccAddress) gethcommon.Address

func ParseEthChainID

func ParseEthChainID(chainID string) *big.Int

ParseEthChainID parses a string chain identifier's to an Ethereum-compatible chain-id in *big.Int format.

This function uses Nibiru's map of chain IDs defined in Nibiru/app/appconst rather than the regex of EIP155, which is implemented by ParseEthChainIDStrict.

func ParseEthChainIDStrict

func ParseEthChainIDStrict(chainID string) (*big.Int, error)

ParseEthChainIDStrict parses a string chain identifier's epoch to an Ethereum-compatible chain-id in *big.Int format. The function returns an error if the chain-id has an invalid format

func ProtoBaseAccount

func ProtoBaseAccount() authtypes.AccountI

ProtoBaseAccount: Implementation of `BaseAccount` for the `AccountI` interface used in the AccountKeeper from the Auth Module. ProtoBaseAccount is a drop-in replacement for the `auth.ProtoBaseAccount` from "cosmos-sdk/auth/types" extended to fit the the `EthAccountI` interface for Ethereum accounts.

func RegisterInterfaces

func RegisterInterfaces(registry codectypes.InterfaceRegistry)

RegisterInterfaces registers the tendermint concrete client-related implementations and interfaces.

func SafeInt64

func SafeInt64(value uint64) (int64, error)

SafeInt64 checks for overflows while casting a uint64 to int64 value.

func SafeNewIntFromBigInt

func SafeNewIntFromBigInt(i *big.Int) (sdkmath.Int, error)

SafeNewIntFromBigInt constructs Int from big.Int, return error if more than 256bits

func TmTxHashToString

func TmTxHashToString(tmTxHash []byte) string

TmTxHashToString returns the consensus transaction hash as a string. Transactions are hex-encoded and capitlized. Reference: Tx.String function from comet-bft/types/tx.go

func ValidateAddress

func ValidateAddress(address string) error

ValidateAddress returns an error if the provided string is either not a hex formatted string address

func ValidateNonZeroAddress

func ValidateNonZeroAddress(address string) error

ValidateNonZeroAddress returns an error if the provided string is not a hex formatted string address or is equal to zero

Types

type EIP55Addr

type EIP55Addr struct {
	gethcommon.Address
}

EIP55Addr is a wrapper around gethcommon.Address that provides JSON marshaling and unmarshalling as well as Protobuf serialization and deserialization. The constructors ensure that the input string is a valid 20 byte hex address.

func NewEIP55AddrFromStr

func NewEIP55AddrFromStr(input string) (EIP55Addr, error)

Checks input length, but not case-sensitive hex.

func (EIP55Addr) Marshal

func (h EIP55Addr) Marshal() ([]byte, error)

Marshal implements the gogo proto custom type interface. Ref: https://github.com/cosmos/gogoproto/blob/v1.5.0/custom_types.md

func (EIP55Addr) MarshalJSON

func (h EIP55Addr) MarshalJSON() ([]byte, error)

MarshalJSON returns the EIP55Addr as JSON bytes. Implements the gogo proto custom type interface. Ref: https://github.com/cosmos/gogoproto/blob/v1.5.0/custom_types.md

func (*EIP55Addr) MarshalTo

func (h *EIP55Addr) MarshalTo(data []byte) (n int, err error)

MarshalTo serializes a EIP55Addr directly into a pre-allocated byte slice ("data"). MarshalTo implements the gogo proto custom type interface. Implements the gogo proto custom type interface. Ref: https://github.com/cosmos/gogoproto/blob/v1.5.0/custom_types.md

func (EIP55Addr) Size

func (h EIP55Addr) Size() int

Size implements the gogo proto custom type interface. Ref: https://github.com/cosmos/gogoproto/blob/v1.5.0/custom_types.md

func (*EIP55Addr) Unmarshal

func (h *EIP55Addr) Unmarshal(data []byte) error

Unmarshal implements the gogo proto custom type interface. Ref: https://github.com/cosmos/gogoproto/blob/v1.5.0/custom_types.md

func (*EIP55Addr) UnmarshalJSON

func (h *EIP55Addr) UnmarshalJSON(bz []byte) error

UnmarshalJSON implements the gogo proto custom type interface. Ref: https://github.com/cosmos/gogoproto/blob/v1.5.0/custom_types.md

type EVMTxIndexer

type EVMTxIndexer interface {
	// LastIndexedBlock returns -1 if indexer db is empty
	LastIndexedBlock() (int64, error)
	IndexBlock(*tmtypes.Block, []*abci.ResponseDeliverTx) error

	// GetByTxHash returns nil if tx not found.
	GetByTxHash(common.Hash) (*TxResult, error)
	// GetByBlockAndIndex returns nil if tx not found.
	GetByBlockAndIndex(int64, int32) (*TxResult, error)
}

EVMTxIndexer defines the interface of custom eth tx indexer.

type ErrorGasOverflow

type ErrorGasOverflow struct {
	Descriptor string
}

ErrorGasOverflow defines an error thrown when an action results gas consumption unsigned integer overflow.

type ErrorNegativeGasConsumed

type ErrorNegativeGasConsumed struct {
	Descriptor string
}

ErrorNegativeGasConsumed defines an error thrown when the amount of gas refunded results in a negative gas consumed amount.

type EthAccType

type EthAccType = int8

EthAccType: Enum for Ethereum account types.

const (
	// EthAccType_EOA: For externally owned accounts (EOAs)
	EthAccType_EOA EthAccType = iota + 1
	// EthAccType_Contract: For smart contracts accounts.
	EthAccType_Contract
)

type EthAccount

type EthAccount struct {
	// base_account is an authtypes.BaseAccount
	*types.BaseAccount `` /* 136-byte string literal not displayed */
	// code_hash is the hash calculated from the code contents
	CodeHash string `protobuf:"bytes,2,opt,name=code_hash,json=codeHash,proto3" json:"code_hash,omitempty" yaml:"code_hash"`
}

EthAccount implements the authtypes.AccountI interface and embeds an authtypes.BaseAccount type. It is compatible with the auth AccountKeeper.

func (*EthAccount) Descriptor

func (*EthAccount) Descriptor() ([]byte, []int)

func (EthAccount) EthAddress

func (acc EthAccount) EthAddress() gethcommon.Address

EthAddress returns the account address ethereum format.

func (EthAccount) GetBaseAccount

func (acc EthAccount) GetBaseAccount() *authtypes.BaseAccount

func (EthAccount) GetCodeHash

func (acc EthAccount) GetCodeHash() gethcommon.Hash

func (*EthAccount) Marshal

func (m *EthAccount) Marshal() (dAtA []byte, err error)

func (*EthAccount) MarshalTo

func (m *EthAccount) MarshalTo(dAtA []byte) (int, error)

func (*EthAccount) MarshalToSizedBuffer

func (m *EthAccount) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*EthAccount) ProtoMessage

func (*EthAccount) ProtoMessage()

func (*EthAccount) Reset

func (m *EthAccount) Reset()

func (*EthAccount) SetCodeHash

func (acc *EthAccount) SetCodeHash(codeHash gethcommon.Hash) error

func (*EthAccount) Size

func (m *EthAccount) Size() (n int)

func (*EthAccount) String

func (m *EthAccount) String() string

func (EthAccount) Type

func (acc EthAccount) Type() EthAccType

Type returns the type of Ethereum Account (EOA or Contract)

func (*EthAccount) Unmarshal

func (m *EthAccount) Unmarshal(dAtA []byte) error

func (*EthAccount) XXX_DiscardUnknown

func (m *EthAccount) XXX_DiscardUnknown()

func (*EthAccount) XXX_Marshal

func (m *EthAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*EthAccount) XXX_Merge

func (m *EthAccount) XXX_Merge(src proto.Message)

func (*EthAccount) XXX_Size

func (m *EthAccount) XXX_Size() int

func (*EthAccount) XXX_Unmarshal

func (m *EthAccount) XXX_Unmarshal(b []byte) error

type EthAccountI

type EthAccountI interface {
	authtypes.AccountI
	// EthAddress returns the ethereum Address representation of the AccAddress
	EthAddress() gethcommon.Address
	// CodeHash is the keccak256 hash of the contract code (if any)
	GetCodeHash() gethcommon.Hash
	// SetCodeHash sets the code hash to the account fields
	SetCodeHash(code gethcommon.Hash) error
	// Type returns the type of Ethereum Account (EOA or Contract)
	Type() EthAccType
}

EthAccountI represents the interface of an EVM compatible account

type HDPathIterator

type HDPathIterator func() ethaccounts.DerivationPath

func NewHDPathIterator

func NewHDPathIterator(basePath string, ledgerIter bool) (HDPathIterator, error)

HDPathIterator receives a base path as a string and a boolean for the desired iterator type and returns a function that iterates over the base HD path, returning the string.

type InfiniteGasMeter

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

InfiniteGasMeter: A special impl of `sdk.GasMeter` that ignores any gas limits, allowing an unlimited amount of gas to be consumed. This is especially useful for scenarios where gas consumption needs to be monitored but not restricted, such as during testing or in parts of the chain where constraints are meant to be set differently.

func (*InfiniteGasMeter) ConsumeGas

func (g *InfiniteGasMeter) ConsumeGas(amount sdk.Gas, descriptor string)

ConsumeGas adds the given amount of gas to the gas consumed and panics if it overflows the limit or out of gas.

func (*InfiniteGasMeter) GasConsumed

func (g *InfiniteGasMeter) GasConsumed() sdk.Gas

GasConsumed returns the gas consumed from the GasMeter.

func (*InfiniteGasMeter) GasConsumedToLimit

func (g *InfiniteGasMeter) GasConsumedToLimit() sdk.Gas

GasConsumedToLimit returns the gas limit if gas consumed is past the limit, otherwise it returns the consumed gas.

Note that This function is used when recovering from a panic in "BlockGasMeter" when the consumed gas passes the limit.

func (*InfiniteGasMeter) GasRemaining

func (g *InfiniteGasMeter) GasRemaining() sdk.Gas

GasRemaining returns MaxUint64 since limit is not confined in infiniteGasMeter.

func (*InfiniteGasMeter) IsOutOfGas

func (g *InfiniteGasMeter) IsOutOfGas() bool

IsOutOfGas returns true if gas consumed is greater than or equal to gas limit, otherwise it returns false. In the case of the the InfiniteGasMeter, this always returns false for unrestricted gas consumption.

func (*InfiniteGasMeter) IsPastLimit

func (g *InfiniteGasMeter) IsPastLimit() bool

IsPastLimit returns true if gas consumed is past limit, otherwise it returns false. In the case of the the InfiniteGasMeter, this always returns false.

func (*InfiniteGasMeter) Limit

func (g *InfiniteGasMeter) Limit() sdk.Gas

Limit returns the gas limit of the GasMeter.

func (*InfiniteGasMeter) RefundGas

func (g *InfiniteGasMeter) RefundGas(amount sdk.Gas, descriptor string)

RefundGas will deduct the given amount from the gas consumed. If the amount is greater than the gas consumed, the function will panic.

Use case: This functionality enables refunding gas to the trasaction or block gas pools so that EVM-compatible chains can fully support the go-ethereum StateDb interface. See https://github.com/cosmos/cosmos-sdk/pull/9403 for reference.

func (*InfiniteGasMeter) String

func (g *InfiniteGasMeter) String() string

String returns the BasicGasMeter's gas limit and gas consumed.

type TxResult

type TxResult struct {
	// height of the blockchain
	Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"`
	// tx_index of the cosmos transaction
	TxIndex uint32 `protobuf:"varint,2,opt,name=tx_index,json=txIndex,proto3" json:"tx_index,omitempty"`
	// msg_index in a batch transaction
	MsgIndex uint32 `protobuf:"varint,3,opt,name=msg_index,json=msgIndex,proto3" json:"msg_index,omitempty"`
	// eth_tx_index is the index in the list of valid eth tx in the block,
	// aka. the transaction list returned by eth_getBlock api.
	EthTxIndex int32 `protobuf:"varint,4,opt,name=eth_tx_index,json=ethTxIndex,proto3" json:"eth_tx_index,omitempty"`
	// failed is true if the eth transaction did not go succeed
	Failed bool `protobuf:"varint,5,opt,name=failed,proto3" json:"failed,omitempty"`
	// gas_used by the transaction. If it exceeds the block gas limit,
	// it's set to gas limit, which is what's actually deducted by ante handler.
	GasUsed uint64 `protobuf:"varint,6,opt,name=gas_used,json=gasUsed,proto3" json:"gas_used,omitempty"`
	// cumulative_gas_used specifies the cumulated amount of gas used for all
	// processed messages within the current batch transaction.
	CumulativeGasUsed uint64 `protobuf:"varint,7,opt,name=cumulative_gas_used,json=cumulativeGasUsed,proto3" json:"cumulative_gas_used,omitempty"`
}

TxResult is the value stored in eth tx indexer

func (*TxResult) Descriptor

func (*TxResult) Descriptor() ([]byte, []int)

func (*TxResult) Marshal

func (m *TxResult) Marshal() (dAtA []byte, err error)

func (*TxResult) MarshalTo

func (m *TxResult) MarshalTo(dAtA []byte) (int, error)

func (*TxResult) MarshalToSizedBuffer

func (m *TxResult) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*TxResult) ProtoMessage

func (*TxResult) ProtoMessage()

func (*TxResult) Reset

func (m *TxResult) Reset()

func (*TxResult) Size

func (m *TxResult) Size() (n int)

func (*TxResult) String

func (m *TxResult) String() string

func (*TxResult) Unmarshal

func (m *TxResult) Unmarshal(dAtA []byte) error

func (*TxResult) XXX_DiscardUnknown

func (m *TxResult) XXX_DiscardUnknown()

func (*TxResult) XXX_Marshal

func (m *TxResult) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*TxResult) XXX_Merge

func (m *TxResult) XXX_Merge(src proto.Message)

func (*TxResult) XXX_Size

func (m *TxResult) XXX_Size() int

func (*TxResult) XXX_Unmarshal

func (m *TxResult) XXX_Unmarshal(b []byte) error

Directories

Path Synopsis
crypto
hd
rpc

Jump to

Keyboard shortcuts

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