wallet

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package wallet provides Ethereum wallet management for transaction signing.

Index

Constants

View Source
const MaxBatchSize = 10

MaxBatchSize bounds how many transactions one batch submits at a time. Larger requests are split into consecutive chunks: a long run of pre-signed nonces is more exposed to another instance taking one of them, and every displaced nonce stalls the ones behind it until it is refilled.

Variables

This section is empty.

Functions

This section is empty.

Types

type TxRequest added in v0.0.3

type TxRequest struct {
	To       common.Address
	Value    *big.Int
	Data     []byte
	GasLimit uint64
}

TxRequest is one transaction of a batch submission.

type TxResult added in v0.0.3

type TxResult struct {
	Index   int
	Receipt *types.Receipt
	Err     error
}

TxResult is the outcome of one batch request. Index is the request's position in the input slice, so results stay matchable regardless of completion order.

type Wallet

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

Wallet manages an Ethereum wallet for transaction operations.

The wallet is safe to use when multiple independent buildoor instances share the same funding key: each transaction sources a fresh on-chain nonce, txMu serializes this process's own submissions, and SendAndConfirm resolves cross-process nonce conflicts (refetch + retry) and detects its tx being displaced by another instance.

func NewWallet

func NewWallet(
	privkeyHex string,
	rpcClient *execution.Client,
	log logrus.FieldLogger,
) (*Wallet, error)

NewWallet creates a new wallet from a hex-encoded private key.

func (*Wallet) Address

func (w *Wallet) Address() common.Address

Address returns the wallet's Ethereum address.

func (*Wallet) Await

func (w *Wallet) Await(
	ctx context.Context,
	txHash common.Hash,
	timeout time.Duration,
) (*types.Receipt, error)

Await waits for a transaction to be confirmed.

func (*Wallet) BuildAndSend

func (w *Wallet) BuildAndSend(
	ctx context.Context,
	to common.Address,
	value *big.Int,
	data []byte,
	gasLimit uint64,
) (*types.Transaction, error)

BuildAndSend builds, signs, and sends a transaction.

func (*Wallet) BuildTransaction

func (w *Wallet) BuildTransaction(
	ctx context.Context,
	to common.Address,
	value *big.Int,
	data []byte,
	gasLimit uint64,
) (*types.Transaction, error)

BuildTransaction creates a new unsigned transaction with a freshly read nonce.

func (*Wallet) GetBalance

func (w *Wallet) GetBalance(ctx context.Context) (*big.Int, error)

GetBalance fetches the current balance from the chain.

func (*Wallet) GetNonce

func (w *Wallet) GetNonce(ctx context.Context) (uint64, error)

GetNonce fetches the current nonce from the chain.

func (*Wallet) GetRPCClient

func (w *Wallet) GetRPCClient() *execution.Client

GetRPCClient returns the underlying concrete RPC client.

func (*Wallet) SendAndConfirm

func (w *Wallet) SendAndConfirm(
	ctx context.Context,
	to common.Address,
	value *big.Int,
	data []byte,
	gasLimit uint64,
	timeout time.Duration,
) (*types.Receipt, error)

SendAndConfirm builds, signs, sends, and confirms a transaction in a way that is safe when several buildoor instances share this funding key.

Each attempt sources a fresh on-chain nonce. Crucially, it never parses the send error string (which varies per execution client). Instead it decides what to do by observing node state: whether our specific transaction is known to the node, and where the account's pending nonce sits relative to the nonce we used.

  • our tx is known (pending/mined) -> wait for its receipt
  • our tx is unknown and the pending nonce has moved past ours -> another tx (likely another instance) took our slot; resubmit with a fresh nonce
  • our tx is unknown, the nonce is still free, and the send errored -> genuine failure; surface it

txMu serializes this process's own submissions so concurrent lifecycle operations (e.g. the startup deposit and a balance top-up) never collide with each other.

func (*Wallet) SendBatchAndConfirm added in v0.0.3

func (w *Wallet) SendBatchAndConfirm(
	ctx context.Context, requests []TxRequest, timeout time.Duration,
) []TxResult

SendBatchAndConfirm submits several transactions from this wallet at once and confirms each independently. It returns one result per request, in request order; a failure of one request never fails the others.

Batching matters because every lifecycle transaction is serialized on the same funding key: depositing a fleet of builder keys one confirmed transaction at a time takes a block per key. The batch signs consecutive nonces in one go and sends them together, so they land in the same block or two.

Each transaction is still resolved on its own, because sharing the funding key with other buildoor instances means any single nonce can be taken by a foreign transaction. A displaced transaction is rebuilt with a fresh nonce and retried in a later round, while the ones that landed are left alone.

func (*Wallet) SendTransaction

func (w *Wallet) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction sends a signed transaction.

func (*Wallet) SignTransaction

func (w *Wallet) SignTransaction(tx *types.Transaction) (*types.Transaction, error)

SignTransaction signs a transaction with the wallet's private key.

func (*Wallet) Sync

func (w *Wallet) Sync(ctx context.Context) error

Sync synchronizes the wallet state with the chain.

Jump to

Keyboard shortcuts

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