ethtypes

package
v1.23.1-libp2p-0.27.6 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2023 License: Apache-2.0, MIT Imports: 24 Imported by: 58

Documentation

Index

Constants

View Source
const (
	EthAddressLength = 20
	EthHashLength    = 32
)
View Source
const Eip1559TxType = 2
View Source
const EthBloomSize = 2048

Variables

View Source
var (
	EmptyEthBloom  = [EthBloomSize / 8]byte{}
	FullEthBloom   = [EthBloomSize / 8]byte{}
	EmptyEthHash   = EthHash{}
	EmptyUncleHash = must.One(ParseEthHash("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347")) // Keccak-256 of an RLP of an empty array
	EmptyRootHash  = must.One(ParseEthHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")) // Keccak-256 hash of the RLP of null
	EmptyEthInt    = EthUint64(0)
	EmptyEthNonce  = [8]byte{0, 0, 0, 0, 0, 0, 0, 0}
)
View Source
var ErrInvalidAddress = errors.New("invalid Filecoin Eth address")
View Source
var EthBigIntZero = EthBigInt{Int: big.Zero().Int}

Functions

func DecodeHexString

func DecodeHexString(s string) ([]byte, error)

func DecodeHexStringTrimSpace

func DecodeHexStringTrimSpace(s string) ([]byte, error)

func DecodeRLP

func DecodeRLP(data []byte) (interface{}, error)

func EncodeRLP

func EncodeRLP(val interface{}) ([]byte, error)

func EthAddressFromPubKey

func EthAddressFromPubKey(pubk []byte) ([]byte, error)

EthAddressFromPubKey returns the Ethereum address corresponding to an uncompressed secp256k1 public key.

func EthBloomSet

func EthBloomSet(f EthBytes, data []byte)

func IsEthAddress

func IsEthAddress(addr address.Address) bool

Types

type EthAddress

type EthAddress [EthAddressLength]byte

func CastEthAddress

func CastEthAddress(b []byte) (EthAddress, error)

CastEthAddress interprets bytes as an EthAddress, performing some basic checks.

func EthAddressFromFilecoinAddress

func EthAddressFromFilecoinAddress(addr address.Address) (EthAddress, error)

func GetContractEthAddressFromCode

func GetContractEthAddressFromCode(sender EthAddress, salt [32]byte, initcode []byte) (EthAddress, error)

func ParseEthAddress

func ParseEthAddress(s string) (EthAddress, error)

ParseEthAddress parses an Ethereum address from a hex string.

func (EthAddress) IsMaskedID

func (ea EthAddress) IsMaskedID() bool

func (EthAddress) MarshalJSON

func (ea EthAddress) MarshalJSON() ([]byte, error)

func (EthAddress) String

func (ea EthAddress) String() string

func (EthAddress) ToFilecoinAddress

func (ea EthAddress) ToFilecoinAddress() (address.Address, error)

func (*EthAddress) UnmarshalJSON

func (ea *EthAddress) UnmarshalJSON(b []byte) error

type EthAddressList

type EthAddressList []EthAddress

EthAddressSpec represents a list of addresses. The JSON decoding must treat a string as equivalent to an array with one value, for example "0x8888f1f195afa192cfee86069858" must be decoded as [ "0x8888f1f195afa192cfee86069858" ]

func (*EthAddressList) UnmarshalJSON

func (e *EthAddressList) UnmarshalJSON(b []byte) error

type EthBigInt

type EthBigInt big.Int

EthBigInt represents a large integer whose zero value serializes to "0x0".

func RecoverSignature

func RecoverSignature(sig typescrypto.Signature) (r, s, v EthBigInt, err error)

func (EthBigInt) MarshalJSON

func (e EthBigInt) MarshalJSON() ([]byte, error)

func (EthBigInt) String

func (e EthBigInt) String() string

func (*EthBigInt) UnmarshalJSON

func (e *EthBigInt) UnmarshalJSON(b []byte) error

type EthBlock

type EthBlock struct {
	Hash             EthHash    `json:"hash"`
	ParentHash       EthHash    `json:"parentHash"`
	Sha3Uncles       EthHash    `json:"sha3Uncles"`
	Miner            EthAddress `json:"miner"`
	StateRoot        EthHash    `json:"stateRoot"`
	TransactionsRoot EthHash    `json:"transactionsRoot"`
	ReceiptsRoot     EthHash    `json:"receiptsRoot"`
	LogsBloom        EthBytes   `json:"logsBloom"`
	Difficulty       EthUint64  `json:"difficulty"`
	TotalDifficulty  EthUint64  `json:"totalDifficulty"`
	Number           EthUint64  `json:"number"`
	GasLimit         EthUint64  `json:"gasLimit"`
	GasUsed          EthUint64  `json:"gasUsed"`
	Timestamp        EthUint64  `json:"timestamp"`
	Extradata        EthBytes   `json:"extraData"`
	MixHash          EthHash    `json:"mixHash"`
	Nonce            EthNonce   `json:"nonce"`
	BaseFeePerGas    EthBigInt  `json:"baseFeePerGas"`
	Size             EthUint64  `json:"size"`
	// can be []EthTx or []string depending on query params
	Transactions []interface{} `json:"transactions"`
	Uncles       []EthHash     `json:"uncles"`
}

func NewEthBlock

func NewEthBlock(hasTransactions bool) EthBlock

type EthBytes

type EthBytes []byte

EthBytes represent arbitrary bytes. A nil or empty slice serializes to "0x".

func (EthBytes) MarshalJSON

func (e EthBytes) MarshalJSON() ([]byte, error)

func (EthBytes) String

func (e EthBytes) String() string

func (*EthBytes) UnmarshalJSON

func (e *EthBytes) UnmarshalJSON(b []byte) error

type EthCall

type EthCall struct {
	From     *EthAddress `json:"from"`
	To       *EthAddress `json:"to"`
	Gas      EthUint64   `json:"gas"`
	GasPrice EthBigInt   `json:"gasPrice"`
	Value    EthBigInt   `json:"value"`
	Data     EthBytes    `json:"data"`
}

func (*EthCall) UnmarshalJSON

func (c *EthCall) UnmarshalJSON(b []byte) error

type EthFeeHistory

type EthFeeHistory struct {
	OldestBlock   EthUint64      `json:"oldestBlock"`
	BaseFeePerGas []EthBigInt    `json:"baseFeePerGas"`
	GasUsedRatio  []float64      `json:"gasUsedRatio"`
	Reward        *[][]EthBigInt `json:"reward,omitempty"`
}

type EthFeeHistoryParams

type EthFeeHistoryParams struct {
	BlkCount          EthUint64
	NewestBlkNum      string
	RewardPercentiles *[]float64
}

EthFeeHistoryParams handles raw jsonrpc params for eth_feeHistory

func (EthFeeHistoryParams) MarshalJSON

func (e EthFeeHistoryParams) MarshalJSON() ([]byte, error)

func (*EthFeeHistoryParams) UnmarshalJSON

func (e *EthFeeHistoryParams) UnmarshalJSON(b []byte) error

type EthFilterID

type EthFilterID EthHash

func (EthFilterID) MarshalJSON

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

func (EthFilterID) String

func (h EthFilterID) String() string

func (*EthFilterID) UnmarshalJSON

func (h *EthFilterID) UnmarshalJSON(b []byte) error

type EthFilterResult

type EthFilterResult struct {
	Results []interface{}
}

FilterResult represents the response from executing a filter: a list of block hashes, a list of transaction hashes or a list of logs This is a union type. Only one field will be populated. The JSON encoding must produce an array of the populated field.

func (EthFilterResult) MarshalJSON

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

func (*EthFilterResult) UnmarshalJSON

func (h *EthFilterResult) UnmarshalJSON(b []byte) error

type EthFilterSpec

type EthFilterSpec struct {
	// Interpreted as an epoch or one of "latest" for last mined block, "earliest" for first,
	// "pending" for not yet committed messages.
	// Optional, default: "latest".
	FromBlock *string `json:"fromBlock,omitempty"`

	// Interpreted as an epoch or one of "latest" for last mined block, "earliest" for first,
	// "pending" for not yet committed messages.
	// Optional, default: "latest".
	ToBlock *string `json:"toBlock,omitempty"`

	// Actor address or a list of addresses from which event logs should originate.
	// Optional, default nil.
	// The JSON decoding must treat a string as equivalent to an array with one value, for example
	// "0x8888f1f195afa192cfee86069858" must be decoded as [ "0x8888f1f195afa192cfee86069858" ]
	Address EthAddressList `json:"address"`

	// List of topics to be matched.
	// Optional, default: empty list
	Topics EthTopicSpec `json:"topics"`

	// Restricts event logs returned to those emitted from messages contained in this tipset.
	// If BlockHash is present in in the filter criteria, then neither FromBlock nor ToBlock are allowed.
	// Added in EIP-234
	BlockHash *EthHash `json:"blockHash,omitempty"`
}

type EthHash

type EthHash [EthHashLength]byte

func EthHashFromCid

func EthHashFromCid(c cid.Cid) (EthHash, error)

func EthHashFromTxBytes

func EthHashFromTxBytes(b []byte) EthHash

func ParseEthHash

func ParseEthHash(s string) (EthHash, error)

func (EthHash) MarshalJSON

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

func (EthHash) String

func (h EthHash) String() string

func (EthHash) ToCid

func (h EthHash) ToCid() cid.Cid

Should ONLY be used for blocks and Filecoin messages. Eth transactions expect a different hashing scheme.

func (*EthHash) UnmarshalJSON

func (h *EthHash) UnmarshalJSON(b []byte) error

type EthHashList

type EthHashList []EthHash

EthHashList represents a list of EthHashes. The JSON decoding treats string values as equivalent to arrays with one value.

func (*EthHashList) UnmarshalJSON

func (e *EthHashList) UnmarshalJSON(b []byte) error

type EthLog

type EthLog struct {
	// Address is the address of the actor that produced the event log.
	Address EthAddress `json:"address"`

	// Data is the value of the event log, excluding topics
	Data EthBytes `json:"data"`

	// List of topics associated with the event log.
	Topics []EthHash `json:"topics"`

	// Indicates whether the log was removed due to a chain reorganization.
	Removed bool `json:"removed"`

	// LogIndex is the index of the event log in the sequence of events produced by the message execution.
	// (this is the index in the events AMT on the message receipt)
	LogIndex EthUint64 `json:"logIndex"`

	// TransactionIndex is the index in the tipset of the transaction that produced the event log.
	// The index corresponds to the sequence of messages produced by ChainGetParentMessages
	TransactionIndex EthUint64 `json:"transactionIndex"`

	// TransactionHash is the hash of the RLP message that produced the event log.
	TransactionHash EthHash `json:"transactionHash"`

	// BlockHash is the hash of the tipset containing the message that produced the log.
	BlockHash EthHash `json:"blockHash"`

	// BlockNumber is the epoch of the tipset containing the message.
	BlockNumber EthUint64 `json:"blockNumber"`
}

EthLog represents the results of an event filter execution.

type EthNonce

type EthNonce [8]byte

func (EthNonce) MarshalJSON

func (n EthNonce) MarshalJSON() ([]byte, error)

func (EthNonce) String

func (n EthNonce) String() string

func (*EthNonce) UnmarshalJSON

func (n *EthNonce) UnmarshalJSON(b []byte) error

type EthSubscribeParams

type EthSubscribeParams struct {
	EventType string
	Params    *EthSubscriptionParams
}

EthSubscribeParams handles raw jsonrpc params for eth_subscribe

func (EthSubscribeParams) MarshalJSON

func (e EthSubscribeParams) MarshalJSON() ([]byte, error)

func (*EthSubscribeParams) UnmarshalJSON

func (e *EthSubscribeParams) UnmarshalJSON(b []byte) error

type EthSubscriptionID

type EthSubscriptionID EthHash

An opaque identifier generated by the Lotus node to refer to an active subscription.

func (EthSubscriptionID) MarshalJSON

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

func (EthSubscriptionID) String

func (h EthSubscriptionID) String() string

func (*EthSubscriptionID) UnmarshalJSON

func (h *EthSubscriptionID) UnmarshalJSON(b []byte) error

type EthSubscriptionParams

type EthSubscriptionParams struct {
	// List of topics to be matched.
	// Optional, default: empty list
	Topics EthTopicSpec `json:"topics,omitempty"`

	// Actor address or a list of addresses from which event logs should originate.
	// Optional, default nil.
	// The JSON decoding must treat a string as equivalent to an array with one value, for example
	// "0x8888f1f195afa192cfee86069858" must be decoded as [ "0x8888f1f195afa192cfee86069858" ]
	Address EthAddressList `json:"address"`
}

type EthSubscriptionResponse

type EthSubscriptionResponse struct {
	// The persistent identifier for the subscription which can be used to unsubscribe.
	SubscriptionID EthSubscriptionID `json:"subscription"`

	// The object matching the subscription. This may be a Block (tipset), a Transaction (message) or an EthLog
	Result interface{} `json:"result"`
}

type EthTopicSpec

type EthTopicSpec []EthHashList

TopicSpec represents a specification for matching by topic. An empty spec means all topics will be matched. Otherwise topics are matched conjunctively in the first dimension of the slice and disjunctively in the second dimension. Topics are matched in order. An event log with topics [A, B] will be matched by the following topic specs: [] "all" [[A]] "A in first position (and anything after)" [nil, [B] ] "anything in first position AND B in second position (and anything after)" [[A], [B]] "A in first position AND B in second position (and anything after)" [[A, B], [A, B]] "(A OR B) in first position AND (A OR B) in second position (and anything after)"

The JSON decoding must treat string values as equivalent to arrays with one value, for example { "A", [ "B", "C" ] } must be decoded as [ [ A ], [ B, C ] ]

type EthTx

type EthTx struct {
	ChainID              EthUint64   `json:"chainId"`
	Nonce                EthUint64   `json:"nonce"`
	Hash                 EthHash     `json:"hash"`
	BlockHash            *EthHash    `json:"blockHash"`
	BlockNumber          *EthUint64  `json:"blockNumber"`
	TransactionIndex     *EthUint64  `json:"transactionIndex"`
	From                 EthAddress  `json:"from"`
	To                   *EthAddress `json:"to"`
	Value                EthBigInt   `json:"value"`
	Type                 EthUint64   `json:"type"`
	Input                EthBytes    `json:"input"`
	Gas                  EthUint64   `json:"gas"`
	MaxFeePerGas         EthBigInt   `json:"maxFeePerGas"`
	MaxPriorityFeePerGas EthBigInt   `json:"maxPriorityFeePerGas"`
	AccessList           []EthHash   `json:"accessList"`
	V                    EthBigInt   `json:"v"`
	R                    EthBigInt   `json:"r"`
	S                    EthBigInt   `json:"s"`
}

func EthTxFromSignedEthMessage

func EthTxFromSignedEthMessage(smsg *types.SignedMessage) (EthTx, error)

EthTxFromSignedEthMessage does NOT populate: - BlockHash - BlockNumber - TransactionIndex - From - Hash

func (*EthTx) ToEthTxArgs

func (tx *EthTx) ToEthTxArgs() EthTxArgs

func (*EthTx) TxHash

func (tx *EthTx) TxHash() (EthHash, error)

type EthTxArgs

type EthTxArgs struct {
	ChainID              int         `json:"chainId"`
	Nonce                int         `json:"nonce"`
	To                   *EthAddress `json:"to"`
	Value                big.Int     `json:"value"`
	MaxFeePerGas         big.Int     `json:"maxFeePerGas"`
	MaxPriorityFeePerGas big.Int     `json:"maxPriorityFeePerGas"`
	GasLimit             int         `json:"gasLimit"`
	Input                []byte      `json:"input"`
	V                    big.Int     `json:"v"`
	R                    big.Int     `json:"r"`
	S                    big.Int     `json:"s"`
}

func EthTxArgsFromUnsignedEthMessage

func EthTxArgsFromUnsignedEthMessage(msg *types.Message) (EthTxArgs, error)

func ParseEthTxArgs

func ParseEthTxArgs(data []byte) (*EthTxArgs, error)

func (*EthTxArgs) HashedOriginalRlpMsg

func (tx *EthTxArgs) HashedOriginalRlpMsg() ([]byte, error)

func (*EthTxArgs) Sender

func (tx *EthTxArgs) Sender() (address.Address, error)

func (*EthTxArgs) Signature

func (tx *EthTxArgs) Signature() (*typescrypto.Signature, error)

func (*EthTxArgs) ToRlpSignedMsg

func (tx *EthTxArgs) ToRlpSignedMsg() ([]byte, error)

func (*EthTxArgs) ToRlpUnsignedMsg

func (tx *EthTxArgs) ToRlpUnsignedMsg() ([]byte, error)

func (*EthTxArgs) ToSignedMessage

func (tx *EthTxArgs) ToSignedMessage() (*types.SignedMessage, error)

func (*EthTxArgs) ToUnsignedMessage

func (tx *EthTxArgs) ToUnsignedMessage(from address.Address) (*types.Message, error)

func (*EthTxArgs) TxHash

func (tx *EthTxArgs) TxHash() (EthHash, error)

type EthUint64

type EthUint64 uint64

func EthUint64FromBytes

func EthUint64FromBytes(b []byte) (EthUint64, error)

Parse a uint64 from big-endian encoded bytes.

func EthUint64FromHex

func EthUint64FromHex(s string) (EthUint64, error)

func (EthUint64) Hex

func (e EthUint64) Hex() string

func (EthUint64) MarshalJSON

func (e EthUint64) MarshalJSON() ([]byte, error)

func (*EthUint64) UnmarshalJSON

func (e *EthUint64) UnmarshalJSON(b []byte) error

UnmarshalJSON should be able to parse these types of input: 1. a JSON string containing a hex-encoded uint64 starting with 0x 2. a JSON string containing an uint64 in decimal 3. a string containing an uint64 in decimal

Jump to

Keyboard shortcuts

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