base

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package base provides core utilities for interacting with the blockchain, including transaction setup, contract calls, and error handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FailedTx

func FailedTx(err error) (string, error)

FailedTx returns an empty string and the given error. It is intended to be used to signal that a transaction has failed.

func GenCallError

func GenCallError(
	kind string,
	buildError func(any) error,
	unpackError func(raw []byte) (any, error),
) func(field string, err error) error

GenCallError generates a call error handler that wraps contract call errors with additional context.

func SuccessTx

func SuccessTx(hash string) (string, error)

SuccessTx returns the given hash and a nil error. It is intended to be used to signal that a transaction has succeeded.

Types

type CallError

type CallError struct {
	Kind   string // The kind of call, e.g., "call", "deploy", etc.
	Method string
	Err    error
}

CallError represents an error that occurred during a contract call

func WrapCallError

func WrapCallError(kind, field string, err error) *CallError

WrapCallError wraps an error with contract call context information

func (*CallError) Error

func (e *CallError) Error() string

func (*CallError) Unwrap

func (e *CallError) Unwrap() error

Unwrap returns the underlying error

type IBaseInteractions

type IBaseInteractions interface {
	VerifyTransaction(ctx context.Context, to common.Address, data []byte, value int64) error
}

IBaseInteractions defines the interface for verifying transactions.

type Interactions

type Interactions struct {
	Ctx     context.Context
	Client  simulated.Client
	Address common.Address

	TxOptsFn transaction.TxOptsBuilderFunc
	// contains filtered or unexported fields
}

Interactions holds the context, client, sender address, private key, disperse contract, and explorer URL.

func NewBaseInteractions

func NewBaseInteractions(
	client simulated.Client,
	pk *ecdsa.PrivateKey,
	explorer *string,
	safe bool,
	txOptsFn ...transaction.TxOptsBuilderFunc,
) *Interactions

NewBaseInteractions creates a new instance of BaseInteractions for blockchain interaction.

func (*Interactions) BaseCallSetup

func (i *Interactions) BaseCallSetup() *bind.CallOpts

BaseCallSetup returns the call options for read-only contract operations.

func (*Interactions) BaseTxSetup

func (i *Interactions) BaseTxSetup() (*bind.TransactOpts, error)

BaseTxSetup sets up transaction options (nonce, gas price, chain ID, etc.) for sending a transaction.

func (*Interactions) CatchTx

func (i *Interactions) CatchTx(tx *ethTypes.Transaction, err error) (string, error)

CatchTx waits for a transaction to be mined and returns its hash or an error message.

func (*Interactions) CheckSignatures

func (i *Interactions) CheckSignatures(contractAddress common.Address, signatures []hex.Signature) error

CheckSignatures checks if a contract supports specific function signatures.

func (*Interactions) Disperse

func (i *Interactions) Disperse(addresses []common.Address, totalValue uint) (string, error)

Disperse uses the disperse contract to send funds to multiple addresses.

func (*Interactions) Safe

func (i *Interactions) Safe() bool

Safe returns whether the interactions are in safe mode

func (*Interactions) SendAllFunds

func (i *Interactions) SendAllFunds(to common.Address) (*ethTypes.Transaction, error)

SendAllFunds transfers the entire balance to a designated address after fee estimation.

func (*Interactions) SetDisperse

func (i *Interactions) SetDisperse(_ string) error

SetDisperse initializes the disperse contract for multi-address fund transfers.

func (*Interactions) TransferETH

func (i *Interactions) TransferETH(to common.Address, value *big.Int) (*ethTypes.Transaction, error)

TransferETH transfers Ether to the specified address, ensuring sufficient balance and proper fee estimation.

func (*Interactions) VerifyTransaction

func (i *Interactions) VerifyTransaction(ctx context.Context, to common.Address, data []byte, value int64) error

VerifyTransaction simulates a contract call to verify transaction validity.

type Session

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

Session holds call options and bound contract instance for contract interactions

func (*Session) CallOpts

func (s *Session) CallOpts() *bind.CallOpts

CallOpts returns the call options for contract calls

func (*Session) Instance

func (s *Session) Instance() *bind.BoundContract

Instance returns the bound contract instance

Jump to

Keyboard shortcuts

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