walletclient

package module
v0.0.0-...-67ae438 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package explorer provides a simplified blockchain explorer client interface with only the methods that are actually used in production code.

This interface removes debugging, monitoring, and example-only methods to provide a cleaner, more focused API.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNonFinalBIP68 is returned when a transaction spending a CSV-locked output is not final.
	ErrNonFinalBIP68 = errors.New("non-final BIP68 sequence")
)

Local error definitions

Functions

func NewExplorerClient

func NewExplorerClient(addr string) (*explorerClient, error)

gRPC client for nbxplorer explorer service

Types

type BlockTimestamp

type BlockTimestamp struct {
	Height uint32
	Time   int64
}

BlockTimestamp represents a block timestamp

type Explorer

type Explorer interface {
	// GetTxHex retrieves the raw transaction hex for a given transaction ID.
	GetTxHex(txid string) (string, error)

	// Broadcast broadcasts one or more raw transactions to the network.
	// Returns the transaction ID of the first transaction on success.
	Broadcast(txs ...string) (string, error)

	// GetTxs retrieves all transactions associated with a given address.
	GetTxs(addr string) ([]tx, error)

	// GetTxOutspends returns the spent status of all outputs for a given transaction.
	GetTxOutspends(tx string) ([]spentStatus, error)

	// GetUtxos retrieves all unspent transaction outputs (UTXOs) for a given address.
	GetUtxos(addr string) ([]Utxo, error)

	// GetRedeemedVtxosBalance calculates the redeemed virtual UTXO balance for an address
	// considering the unilateral exit delay.
	GetRedeemedVtxosBalance(
		addr string, unilateralExitDelay arklib.RelativeLocktime,
	) (uint64, map[int64]uint64, error)

	// GetTxBlockTime returns whether a transaction is confirmed and its block time.
	GetTxBlockTime(
		txid string,
	) (confirmed bool, blocktime int64, err error)

	// BaseUrl returns the base URL of the explorer service.
	BaseUrl() string

	// GetFeeRate retrieves the current recommended fee rate in sat/vB.
	GetFeeRate() (float64, error)

	// GetAddressesEvents returns a channel that receives onchain address events
	// (new UTXOs, spent UTXOs, confirmed UTXOs) for all subscribed addresses.
	GetAddressesEvents() <-chan types.OnchainAddressEvent

	// SubscribeForAddresses subscribes to address updates via WebSocket connections.
	// Addresses are automatically distributed across multiple connections using hash-based routing.
	// Subscriptions are batched to prevent overwhelming individual connections.
	// Duplicate subscriptions are automatically prevented via instance-scoped deduplication.
	SubscribeForAddresses(addresses []string) error

	// UnsubscribeForAddresses removes address subscriptions and updates the WebSocket connections.
	UnsubscribeForAddresses(addresses []string) error

	// Stop gracefully shuts down the explorer, closing all WebSocket connections and channels.
	Stop()
}

Explorer provides the core methods to interact with blockchain explorers. This is a simplified version of the Explorer interface that only includes methods that are actually used in production code.

type Outpoint

type Outpoint struct {
	Txid string
	VOut uint32
}

type RBFTxn

type RBFTxn struct {
	TxId       string
	ReplacedBy string
}

type RbfTxId

type RbfTxId struct {
	TxId string `json:"txid"`
}

type TxInput

type TxInput interface {
	GetTxid() string
	GetIndex() uint32
	GetScript() string
	GetValue() uint64
}

TxInput interface defines transaction input methods

type Utxo

type Utxo struct {
	Txid   string `json:"txid"`
	Vout   uint32 `json:"vout"`
	Amount uint64 `json:"value"`
	Asset  string `json:"asset,omitempty"`
	Status struct {
		Confirmed bool  `json:"confirmed"`
		BlockTime int64 `json:"block_time"`
	} `json:"status"`
	Script string
}

type VtxoWithValue

type VtxoWithValue struct {
	Outpoint Outpoint
	Value    uint64
}

VtxoWithValue represents a VTXO with its value

type Wallet

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

func New

func New(addr string) (*Wallet, *arklib.Network, error)

gRPC client for nbxplorer wallet service

func (*Wallet) BroadcastTransaction

func (w *Wallet) BroadcastTransaction(
	ctx context.Context, txs ...string,
) (string, error)

func (*Wallet) Close

func (w *Wallet) Close()

func (*Wallet) ConnectorsAccountBalance

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

func (*Wallet) Create

func (w *Wallet) Create(ctx context.Context, seed, password string) error

func (*Wallet) DeriveAddresses

func (w *Wallet) DeriveAddresses(ctx context.Context, num int) ([]string, error)

func (*Wallet) DeriveConnectorAddress

func (w *Wallet) DeriveConnectorAddress(ctx context.Context) (string, error)

func (*Wallet) EstimateFees

func (w *Wallet) EstimateFees(ctx context.Context, psbt string) (uint64, error)

func (*Wallet) FeeRate

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

func (*Wallet) GenSeed

func (w *Wallet) GenSeed(ctx context.Context) (string, error)

func (*Wallet) GetCurrentBlockTime

func (w *Wallet) GetCurrentBlockTime(
	ctx context.Context,
) (*BlockTimestamp, error)

func (*Wallet) GetDustAmount

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

func (*Wallet) GetForfeitPubkey

func (w *Wallet) GetForfeitPubkey(ctx context.Context) (*btcec.PublicKey, error)

func (*Wallet) GetNetwork

func (w *Wallet) GetNetwork(ctx context.Context) (*arklib.Network, error)

func (*Wallet) GetNotificationChannel

func (w *Wallet) GetNotificationChannel(
	ctx context.Context,
) <-chan map[string][]VtxoWithValue

func (*Wallet) GetOutpointStatus

func (w *Wallet) GetOutpointStatus(
	ctx context.Context,
	outpoint Outpoint,
) (spent bool, err error)

func (*Wallet) GetReadyUpdate

func (w *Wallet) GetReadyUpdate(ctx context.Context) (<-chan struct{}, error)

func (*Wallet) GetTransaction

func (w *Wallet) GetTransaction(ctx context.Context, txid string) (string, error)

func (*Wallet) IsTransactionConfirmed

func (w *Wallet) IsTransactionConfirmed(
	ctx context.Context, txid string,
) (bool, int64, int64, error)

func (*Wallet) ListConnectorUtxos

func (w *Wallet) ListConnectorUtxos(
	ctx context.Context, connectorAddress string,
) ([]TxInput, error)

func (*Wallet) LoadSignerKey

func (w *Wallet) LoadSignerKey(ctx context.Context, prvkey string) error

func (*Wallet) Lock

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

func (*Wallet) LockConnectorUtxos

func (w *Wallet) LockConnectorUtxos(
	ctx context.Context, utxos []Outpoint,
) error

func (*Wallet) MainAccountBalance

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

func (*Wallet) Restore

func (w *Wallet) Restore(ctx context.Context, seed, password string) error

func (*Wallet) SelectUtxos

func (w *Wallet) SelectUtxos(
	ctx context.Context, asset string, amount uint64, confirmedOnly bool,
) ([]TxInput, uint64, error)

func (*Wallet) SignMessage

func (w *Wallet) SignMessage(ctx context.Context, message []byte) ([]byte, error)

func (*Wallet) SignTransaction

func (w *Wallet) SignTransaction(
	ctx context.Context, partialTx string, extractRawTx bool,
) (string, error)

func (*Wallet) SignTransactionTapscript

func (w *Wallet) SignTransactionTapscript(
	ctx context.Context, partialTx string, inputIndexes []int,
) (string, error)

func (*Wallet) Status

func (w *Wallet) Status(ctx context.Context) (WalletStatus, error)

func (*Wallet) Unlock

func (w *Wallet) Unlock(ctx context.Context, password string) error

func (*Wallet) UnwatchScripts

func (w *Wallet) UnwatchScripts(ctx context.Context, scripts []string) error

func (*Wallet) VerifyMessageSignature

func (w *Wallet) VerifyMessageSignature(
	ctx context.Context, message, signature []byte,
) (bool, error)

func (*Wallet) WatchScripts

func (w *Wallet) WatchScripts(ctx context.Context, scripts []string) error

func (*Wallet) Withdraw

func (w *Wallet) Withdraw(
	ctx context.Context, address string, amount uint64, all bool,
) (string, error)

type WalletStatus

type WalletStatus interface {
	IsInitialized() bool
	IsUnlocked() bool
	IsSynced() bool
}

WalletStatus interface defines wallet status methods

Jump to

Keyboard shortcuts

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