ethcoder

package
v1.27.2 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: LGPL-3.0, MIT Imports: 19 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultMerkleTreeOptions = Options{

	SortLeaves: true,
	SortPairs:  true,
}

Functions

func AbiCoder

func AbiCoder(argTypes []string, argValues []interface{}) ([]byte, error)

func AbiCoderHex

func AbiCoderHex(argTypes []string, argValues []interface{}) (string, error)

func AbiDecodeExpr

func AbiDecodeExpr(expr string, input []byte, argValues []interface{}) error

func AbiDecodeExprAndStringify

func AbiDecodeExprAndStringify(expr string, input []byte) ([]string, error)

func AbiDecoder

func AbiDecoder(argTypes []string, input []byte, argValues []interface{}) error

func AbiDecoderWithReturnedValues

func AbiDecoderWithReturnedValues(argTypes []string, input []byte) ([]interface{}, error)

func AbiEncodeMethodCalldata

func AbiEncodeMethodCalldata(methodExpr string, argValues []interface{}) ([]byte, error)

func AbiEncodeMethodCalldataFromStringValues

func AbiEncodeMethodCalldataFromStringValues(methodExpr string, argStringValues []string) ([]byte, error)

func AbiMarshalStringValues

func AbiMarshalStringValues(argTypes []string, input []byte) ([]string, error)

func AbiUnmarshalStringValues

func AbiUnmarshalStringValues(argTypes []string, stringValues []string) ([]interface{}, error)

AbiDecodeStringValues will take an array of ethereum types and string values, and decode the string values to runtime objects.

func AddressPadding

func AddressPadding(input string) string

func BytesToBytes32

func BytesToBytes32(slice []byte) [32]byte

func EventTopicHash added in v1.24.11

func EventTopicHash(event string) (ethkit.Hash, string, error)

EventTopicHash returns the keccak256 hash of the event signature

e.g. "Transfer(address indexed from, address indexed to, uint256 value)" will return 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef

func FunctionSignature

func FunctionSignature(functionExpr string) string

func HexDecode

func HexDecode(h string) ([]byte, error)

func HexDecodeBigIntArray

func HexDecodeBigIntArray(bigNumsHex []string) ([]*big.Int, error)

func HexDecodeBytes32

func HexDecodeBytes32(h string) ([32]byte, error)

func HexEncode

func HexEncode(h []byte) string

func HexEncodeBigIntArray

func HexEncodeBigIntArray(bigNums []*big.Int) ([]string, error)

func HexTrimLeadingZeros

func HexTrimLeadingZeros(hex string) (string, error)

func Keccak256

func Keccak256(input []byte) []byte

func Keccak256Hash added in v1.17.0

func Keccak256Hash(input []byte) common.Hash

func MustHexDecode

func MustHexDecode(h string) []byte

func MustNewArrayTypeTuple added in v1.4.1

func MustNewArrayTypeTuple(components []abi.ArgumentMarshaling) abi.Type

func MustNewType added in v1.4.1

func MustNewType(str string) abi.Type

func PadZeros

func PadZeros(array []byte, totalLength int) ([]byte, error)

func ParseMethodABI

func ParseMethodABI(methodExpr, returnsExpr string) (*abi.ABI, string, error)

ParseMethodABI will return an `abi.ABI` object from the short-hand method string expression, for example, methodExpr: `balanceOf(address)` returnsExpr: `uint256`

func SHA3 added in v1.17.0

func SHA3(input []byte) common.Hash

func SolidityPack

func SolidityPack(argTypes []string, argValues []interface{}) ([]byte, error)

func SolidityPackHex

func SolidityPackHex(argTypes []string, argValues []interface{}) (string, error)

func StringifyValues

func StringifyValues(values []interface{}) ([]string, error)

func ValidateEventSig added in v1.26.3

func ValidateEventSig(eventSig string) (bool, error)

Types

type EventDecoder added in v1.26.5

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

func NewEventDecoder added in v1.26.5

func NewEventDecoder() *EventDecoder

func (*EventDecoder) DecodeLog added in v1.26.5

func (d *EventDecoder) DecodeLog(log types.Log) (EventDef, []interface{}, bool, error)

func (*EventDecoder) DecodeLogAsHex added in v1.26.5

func (d *EventDecoder) DecodeLogAsHex(log types.Log) (EventDef, []string, bool, error)

func (*EventDecoder) EventDefList added in v1.27.2

func (d *EventDecoder) EventDefList() []EventDef

func (*EventDecoder) RegisterContractABI added in v1.26.5

func (d *EventDecoder) RegisterContractABI(contractABI abi.ABI, eventNames ...string) error

func (*EventDecoder) RegisterContractABIJSON added in v1.26.5

func (d *EventDecoder) RegisterContractABIJSON(contractABIJSON string, eventNames ...string) error

func (*EventDecoder) RegisterEventSig added in v1.26.5

func (d *EventDecoder) RegisterEventSig(eventSig ...string) error

func (*EventDecoder) TopicsList added in v1.27.2

func (d *EventDecoder) TopicsList() []string

func (*EventDecoder) TopicsMap added in v1.27.2

func (d *EventDecoder) TopicsMap() map[string]struct{}

type EventDef added in v1.26.2

type EventDef struct {
	TopicHash  string   `json:"topicHash"`  // the event topic hash, ie. 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
	Name       string   `json:"name"`       // the event name, ie. Transfer
	Sig        string   `json:"sig"`        // the event sig, ie. Transfer(address,address,uint256)
	ArgTypes   []string `json:"argTypes"`   // the event arg types, ie. [address, address, uint256]
	ArgNames   []string `json:"argNames"`   // the event arg names, ie. [from, to, value] or ["","",""]
	ArgIndexed []bool   `json:"argIndexed"` // the event arg indexed flag, ie. [true, false, true]
	NumIndexed int      `json:"-"`
}

func DecodeTransactionLogByContractABI added in v1.26.2

func DecodeTransactionLogByContractABI(txnLog types.Log, contractABI abi.ABI) (EventDef, []interface{}, bool, error)

func DecodeTransactionLogByContractABIAsHex added in v1.26.5

func DecodeTransactionLogByContractABIAsHex(txnLog types.Log, contractABI abi.ABI) (EventDef, []string, bool, error)

func DecodeTransactionLogByContractABIJSON added in v1.26.2

func DecodeTransactionLogByContractABIJSON(txnLog types.Log, contractABIJSON string) (EventDef, []interface{}, bool, error)

..

func DecodeTransactionLogByEventSig added in v1.26.2

func DecodeTransactionLogByEventSig(txnLog types.Log, eventSig string) (EventDef, []interface{}, bool, error)

func DecodeTransactionLogByEventSigAsHex added in v1.26.5

func DecodeTransactionLogByEventSigAsHex(txnLog types.Log, eventSig string) (EventDef, []string, bool, error)

func ParseEventDef added in v1.26.2

func ParseEventDef(event string) (EventDef, error)

func (EventDef) String added in v1.27.1

func (e EventDef) String() string

type MerkleTree added in v1.26.0

type MerkleTree[TLeaf any] struct {
	// contains filtered or unexported fields
}

func NewMerkleTree added in v1.26.0

func NewMerkleTree[TLeaf any](leaves []TLeaf, hashFn *func(TLeaf) ([]byte, error), options *Options) *MerkleTree[TLeaf]

func (*MerkleTree[TLeaf]) GetHexProof added in v1.26.0

func (mt *MerkleTree[TLeaf]) GetHexProof(leaf TLeaf) [][]byte

func (*MerkleTree[TLeaf]) GetProof added in v1.26.0

func (mt *MerkleTree[TLeaf]) GetProof(leaf TLeaf) ([]Proof, error)

func (*MerkleTree[TLeaf]) GetRoot added in v1.26.0

func (mt *MerkleTree[TLeaf]) GetRoot() []byte

func (*MerkleTree[TLeaf]) Verify added in v1.26.0

func (mt *MerkleTree[TLeaf]) Verify(proof []Proof, leaf TLeaf, root []byte) (bool, error)

type Options added in v1.26.0

type Options struct {
	SortLeaves bool
	SortPairs  bool
}

type Proof added in v1.26.0

type Proof struct {
	IsLeft bool
	Data   []byte
}

type TypedData

type TypedData struct {
	Types       TypedDataTypes         `json:"types"`
	PrimaryType string                 `json:"primaryType"`
	Domain      TypedDataDomain        `json:"domain"`
	Message     map[string]interface{} `json:"message"`
}

func (*TypedData) EncodeDigest

func (t *TypedData) EncodeDigest() ([]byte, error)

func (*TypedData) HashStruct added in v1.3.4

func (t *TypedData) HashStruct(primaryType string, data map[string]interface{}) ([]byte, error)

type TypedDataArgument

type TypedDataArgument struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type TypedDataDomain

type TypedDataDomain struct {
	Name              string          `json:"name,omitempty"`
	Version           string          `json:"version,omitempty"`
	ChainID           *big.Int        `json:"chainId,omitempty"`
	VerifyingContract *common.Address `json:"verifyingContract,omitempty"`
	Salt              *[32]byte       `json:"salt,omitempty"`
}

func (TypedDataDomain) Map

func (t TypedDataDomain) Map() map[string]interface{}

type TypedDataTypes

type TypedDataTypes map[string][]TypedDataArgument

func (TypedDataTypes) EncodeType

func (t TypedDataTypes) EncodeType(primaryType string) (string, error)

func (TypedDataTypes) TypeHash

func (t TypedDataTypes) TypeHash(primaryType string) ([]byte, error)

Jump to

Keyboard shortcuts

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