w3utils

package module
v0.0.0-...-0875c3a Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: BSD-3-Clause Imports: 6 Imported by: 1

README

w3utils

w3utils provides frequently used utilities for building Go Web3 back-end services.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnpackFailed   = errors.New("failed to unpack log data")
	ErrTypeAssertion  = errors.New("failed to assert type")
	ErrFieldNotFound  = errors.New("field not found")
	ErrNoSuchABIEvent = errors.Wrap(ErrFieldNotFound, "no such ABI event")
)

Functions

func AccrueEvents

func AccrueEvents(contractABI abi.ABI, eventKeys ...string) []abi.Event

AccrueEvents uses |eventKeys| to find corresponding `abi.Event` in |contractABI|. If eventKeys has length of 0, AccrueEvents returns all |contractABI.Events| events.

func CollectEventHashes

func CollectEventHashes(events []abi.Event) []common.Hash

CollectEventHashes returns a slice containing all event hashes (ID) from |events|.

func ExtractFieldFromUnpacked

func ExtractFieldFromUnpacked[T any](unpacked map[string]interface{}, field string) (T, error)

func UnpackLogDataIntoMap

func UnpackLogDataIntoMap(
	contractABI abi.ABI,
	eventKey string,
	logData []byte,
) (
	map[string]interface{},
	error,
)

UnpackLogDataIntoMap uses contract's ABI to parse the data bytes into map of key-value pair

Types

type Contract

type Contract struct {
	Name           string         `json:"name"`    // Arbitrary contract name
	Address        common.Address `json:"address"` // Deployment address
	ContractABI    abi.ABI        `json:"-"`       // Contract's parsed abi.ABI
	ContractEvents []abi.Event    `json:"events"`  // Contract's arbitrary interesting events
}

Contract is a utility struct that provides just-enough contract-specific information for small Go backend services.

func NewContract

func NewContract(
	name string,
	jsonABI string,
	addrString string,
	eventKeys ...string,
) Contract

NewContract constructs a new Contract based on arguments. If eventKeys length is 0, the Contract returned will have all of its events from |jsonABI|.

Directories

Path Synopsis
contracts

Jump to

Keyboard shortcuts

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