Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyGetTxHistoryOptions(opts ...GetTxHistoryOption) (*getTxHistoryOption, error)
- func ApplyGetVtxosOptions(opts ...GetVtxosOption) (*getVtxosOption, error)
- func ApplyPageOptions(opts ...PageOption) (*pageOption, error)
- func CoinSelect(boardingUtxos []Utxo, vtxos []Vtxo, outputs []Receiver, dust uint64, ...) ([]Utxo, []Vtxo, uint64, error)
- func EcPubkeyFromHex(pubkey string) (*btcec.PublicKey, error)
- func NetworkFromString(net string) arklib.Network
- func ParseBitcoinAddress(addr string, net chaincfg.Params) (bool, []byte, error)
- func ParseClosure(outpoint Outpoint, closure script.Closure, tapscripts []string) ([]byte, *arklib.TaprootMerkleProof, error)
- func ToBitcoinNetwork(net arklib.Network) chaincfg.Params
- type AcceptedOffchainTx
- type Address
- type Asset
- type AssetInfo
- type Batch
- type BatchEventChannel
- type BatchFailedEvent
- type BatchFinalizationEvent
- type BatchFinalizedEvent
- type BatchStartedEvent
- type ChainWithExpiry
- type Client
- type CommitmentTx
- type ConfirmedStatus
- type ConnectorsResponse
- type ControlAsset
- type DeprecatedSigner
- type DeprecatedSignerInfo
- type ExistingControlAsset
- type Explorer
- type ExplorerUtxo
- type FeeInfo
- type ForfeitTxsResponse
- type GetTxHistoryOption
- type GetVtxosOption
- func WithOutpoints(outpoints []Outpoint) GetVtxosOption
- func WithPendingOnly() GetVtxosOption
- func WithRecoverableOnly() GetVtxosOption
- func WithScripts(scripts []string) GetVtxosOption
- func WithSpendableOnly() GetVtxosOption
- func WithSpentOnly() GetVtxosOption
- func WithTimeRange(before, after int64) GetVtxosOption
- func WithVtxosPage(page *PageRequest) GetVtxosOption
- type Identity
- type Indexer
- type IndexerChainedTxType
- type Info
- type Input
- type KeyRef
- type NewControlAsset
- type OnchainAddressEvent
- type OnchainOutput
- type Outpoint
- type Output
- type PageOption
- type PageRequest
- type PageResponse
- type Receiver
- type ScriptEvent
- type ScriptEventData
- type ServerParams
- type SignFn
- type SpentStatus
- type StreamConnectionEvent
- type StreamConnectionState
- type StreamStartedEvent
- type SyncEvent
- type Transaction
- type TransactionEvent
- type TransactionKey
- type TreeNoncesAggregatedEvent
- type TreeNoncesEvent
- type TreeSignatureEvent
- type TreeSigningStartedEvent
- type TreeTxEvent
- type Tx
- type TxData
- type TxHistoryResponse
- type TxNode
- type TxNodes
- type TxNotification
- type TxType
- type Utxo
- type VirtualTxsResponse
- type Vtxo
- type VtxoChainResponse
- type VtxoTreeLeavesResponse
- type VtxoTreeResponse
- type VtxosResponse
Constants ¶
const (
GrpcClient = "grpc"
)
const (
SingleKeyIdentity = "singlekey"
)
Variables ¶
var (
ErrConnectionClosedByServer = fmt.Errorf("connection closed by server")
)
Functions ¶
func ApplyGetTxHistoryOptions ¶
func ApplyGetTxHistoryOptions(opts ...GetTxHistoryOption) (*getTxHistoryOption, error)
func ApplyGetVtxosOptions ¶
func ApplyGetVtxosOptions(opts ...GetVtxosOption) (*getVtxosOption, error)
func ApplyPageOptions ¶
func ApplyPageOptions(opts ...PageOption) (*pageOption, error)
func CoinSelect ¶
func CoinSelect( boardingUtxos []Utxo, vtxos []Vtxo, outputs []Receiver, dust uint64, feeEstimator *arkfee.Estimator, ) ([]Utxo, []Vtxo, uint64, error)
CoinSelect picks boarding utxos and vtxos to cover the BTC amount of the given outputs. When feeEstimator is non-nil it also accounts for the per-input and per-output fees, growing the target amount accordingly. If the computed change is below dust it is folded into the selection by adding one more input (preferring an offchain vtxo, then a boarding utxo) when one is available, otherwise the change is dropped to zero. Returns the selected boarding utxos, the selected vtxos, and the leftover change in sats.
func EcPubkeyFromHex ¶
EcPubkeyFromHex decodes a hex-encoded secp256k1 public key and parses it into a *btcec.PublicKey. The input may be compressed or uncompressed, as accepted by btcec.ParsePubKey. It returns an error if the string is not valid hex or does not encode a valid public key.
func NetworkFromString ¶
NetworkFromString resolves the textual network name reported by the server (mainnet, testnet, testnet4, signet, mutinynet, regtest) into the matching arklib.Network value. Unknown values fall back to arklib.Bitcoin (mainnet).
func ParseBitcoinAddress ¶
ParseBitcoinAddress attempts to decode addr as a Bitcoin address on the given network. Returns (true, output script, nil) on success, (false, nil, nil) when the address can't be decoded on that network (i.e. the caller can treat the input as "not an on-chain address"), and (false, nil, err) only when a successfully-decoded address fails to produce a PayToAddr script.
func ParseClosure ¶
func ParseClosure( outpoint Outpoint, closure script.Closure, tapscripts []string, ) ([]byte, *arklib.TaprootMerkleProof, error)
ParseClosure derives the on-chain pkScript and the taproot merkle proof that authorizes the given closure (typically the forfeit script) under the vtxo's tapscript tree. Used by Vtxo/Utxo to expose the signing leaf needed when adding the input to an intent proof or ark transaction. Returns errors scoped to outpoint so failures are traceable to a specific input.
Types ¶
type AcceptedOffchainTx ¶
type Address ¶
type Address struct {
// KeyID identifies which wallet key produced this address.
// Single-key wallets populate it with their fixed key handle; HD wallets can
// use the derivation path.
KeyID string
Tapscripts []string
Address string
// contains filtered or unexported fields
}
func (*Address) CollaborativeClosure ¶
type BatchEventChannel ¶
type BatchEventChannel struct {
Event any
Connection *StreamConnectionEvent
Err error
}
type BatchFailedEvent ¶
type BatchFinalizationEvent ¶
type BatchFinalizedEvent ¶
type BatchStartedEvent ¶
type ChainWithExpiry ¶
type ChainWithExpiry struct {
Txid string
ExpiresAt int64
Type IndexerChainedTxType
Spends []string
}
type Client ¶
type Client interface {
GetInfo(ctx context.Context) (*Info, error)
RegisterIntent(ctx context.Context, proof, message string) (string, error)
DeleteIntent(ctx context.Context, proof, message string) error
EstimateIntentFee(ctx context.Context, proof, message string) (int64, error)
ConfirmRegistration(ctx context.Context, intentID string) error
SubmitTreeNonces(
ctx context.Context, batchId, cosignerPubkey string, nonces tree.TreeNonces,
) error
SubmitTreeSignatures(
ctx context.Context, batchId, cosignerPubkey string, signatures tree.TreePartialSigs,
) error
SubmitSignedForfeitTxs(
ctx context.Context, signedForfeitTxs []string, signedCommitmentTx string,
) error
GetEventStream(ctx context.Context, topics []string) (<-chan BatchEventChannel, func(), error)
SubmitTx(ctx context.Context, signedArkTx string, checkpointTxs []string) (
arkTxid, finalArkTx string, signedCheckpointTxs []string, err error,
)
FinalizeTx(ctx context.Context, arkTxid string, finalCheckpointTxs []string) error
GetPendingTx(ctx context.Context, proof, message string) ([]AcceptedOffchainTx, error)
GetTransactionsStream(ctx context.Context) (<-chan TransactionEvent, func(), error)
ModifyStreamTopics(
ctx context.Context, addTopics, removeTopics []string,
) (addedTopics, removedTopics, allTopics []string, err error)
OverwriteStreamTopics(
ctx context.Context, topics []string,
) (addedTopics, removedTopics, allTopics []string, err error)
Close()
}
type CommitmentTx ¶
type ConfirmedStatus ¶
type ConnectorsResponse ¶
type ConnectorsResponse struct {
Tree []TxNode
Page *PageResponse
}
type ControlAsset ¶
type ControlAsset interface {
// contains filtered or unexported methods
}
ControlAsset represents the control asset configuration for issuing new assets. Use either NewControlAsset to create a new control asset, or ExistingControlAsset
type DeprecatedSigner ¶
type DeprecatedSignerInfo ¶
type ExistingControlAsset ¶
ExistingControlAsset references an existing control asset by its ID.
type Explorer ¶
type Explorer interface {
// Start must be used when using the explorer with tracking enabled.
Start()
// 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)
// GetBlockHeight returns the current block height.
GetBlockHeight() (int64, 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 the given addresses.
GetUtxos(addresses []string) ([]ExplorerUtxo, 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)
// GetConnectionCount returns the number of active WebSocket connections.
GetConnectionCount() int
// GetSubscribedAddresses returns a list of all currently subscribed addresses.
GetSubscribedAddresses() []string
// IsAddressSubscribed checks if a specific address is currently subscribed.
IsAddressSubscribed(address string) bool
// GetAddressesEvents returns a channel that receives onchain address events
// (new UTXOs, spent UTXOs, confirmed UTXOs) for all subscribed addresses.
GetAddressesEvents() <-chan 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 methods to interact with blockchain explorers (e.g., mempool.space, esplora). It supports both HTTP REST API calls and WebSocket connections for real-time address tracking. The implementation uses a connection pool architecture with multiple concurrent WebSocket connections to handle high-volume address subscriptions without overwhelming individual connections.
type ExplorerUtxo ¶
type ExplorerUtxo struct {
Txid string
Vout uint32
Amount uint64
Script string
Status ConfirmedStatus
}
ExplorerUtxo represents an unspent transaction output from the blockchain explorer.
func (ExplorerUtxo) ToUtxo ¶
func (u ExplorerUtxo) ToUtxo( delay arklib.RelativeLocktime, tapscripts []string, signingClosure script.Closure, ) Utxo
ToUtxo converts the explorer Utxo type to the client-lib Utxo one with the specified relative locktime delay (mandatory), tapscripts, and signing closure (optional).
type ForfeitTxsResponse ¶
type ForfeitTxsResponse struct {
Txids []string
Page *PageResponse
}
type GetTxHistoryOption ¶
type GetTxHistoryOption func(*getTxHistoryOption) error
GetTxHistoryOption is a functional option for GetTxHistory requests.
func WithEndTime ¶
func WithEndTime(endTime time.Time) GetTxHistoryOption
func WithStartTime ¶
func WithStartTime(startTime time.Time) GetTxHistoryOption
type GetVtxosOption ¶
type GetVtxosOption func(*getVtxosOption) error
GetVtxosOption is a functional option for GetVtxos requests.
func WithOutpoints ¶
func WithOutpoints(outpoints []Outpoint) GetVtxosOption
func WithPendingOnly ¶
func WithPendingOnly() GetVtxosOption
func WithRecoverableOnly ¶
func WithRecoverableOnly() GetVtxosOption
func WithScripts ¶
func WithScripts(scripts []string) GetVtxosOption
func WithSpendableOnly ¶
func WithSpendableOnly() GetVtxosOption
func WithSpentOnly ¶
func WithSpentOnly() GetVtxosOption
func WithTimeRange ¶
func WithTimeRange(before, after int64) GetVtxosOption
func WithVtxosPage ¶
func WithVtxosPage(page *PageRequest) GetVtxosOption
type Identity ¶
type Identity interface {
GetType() string
Create(
ctx context.Context, network arklib.Network, password, seed string,
) (autoGeneratedSeed string, err error)
Lock(ctx context.Context) (err error)
Unlock(ctx context.Context, password string) (alreadyUnlocked bool, err error)
IsLocked() bool
NextKeyId(ctx context.Context, id string) (string, error)
GetKeyIndex(ctx context.Context, id string) (index uint32, err error)
NewKey(ctx context.Context) (key *KeyRef, err error)
GetXpub(ctx context.Context) (xpub string, err error)
GetKey(ctx context.Context, id string) (key *KeyRef, err error)
ListKeys(ctx context.Context) (keys []KeyRef, err error)
SignTransaction(
ctx context.Context, tx string, keys map[string]string,
) (signedTx string, err error)
SignMessage(ctx context.Context, message []byte) (signature string, err error)
Dump(ctx context.Context) (seed string, err error)
}
type Indexer ¶
type Indexer interface {
GetCommitmentTx(ctx context.Context, txid string) (*CommitmentTx, error)
GetVtxoTree(
ctx context.Context, batchOutpoint Outpoint, opts ...PageOption,
) (*VtxoTreeResponse, error)
GetFullVtxoTree(
ctx context.Context, batchOutpoint Outpoint, opts ...PageOption,
) ([]tree.TxTreeNode, error)
GetVtxoTreeLeaves(
ctx context.Context, batchOutpoint Outpoint, opts ...PageOption,
) (*VtxoTreeLeavesResponse, error)
GetForfeitTxs(
ctx context.Context, txid string, opts ...PageOption,
) (*ForfeitTxsResponse, error)
GetConnectors(
ctx context.Context, txid string, opts ...PageOption,
) (*ConnectorsResponse, error)
GetVtxos(ctx context.Context, opts ...GetVtxosOption) (*VtxosResponse, error)
GetVtxoChain(
ctx context.Context, outpoint Outpoint, opts ...PageOption,
) (*VtxoChainResponse, error)
GetVirtualTxs(
ctx context.Context, txids []string, opts ...PageOption,
) (*VirtualTxsResponse, error)
GetBatchSweepTxs(ctx context.Context, batchOutpoint Outpoint) ([]string, error)
NewSubscription(
ctx context.Context, scripts []string,
) (string, <-chan ScriptEvent, func(), error)
UpdateSubscription(
ctx context.Context, subscriptionId string, scriptsToAdd, scriptsToRemove []string,
) error
GetAsset(ctx context.Context, assetID string) (*AssetInfo, error)
Close()
}
type IndexerChainedTxType ¶
type IndexerChainedTxType string
const ( IndexerChainedTxTypeUnspecified IndexerChainedTxType = "unspecified" IndexerChainedTxTypeCommitment IndexerChainedTxType = "commitment" IndexerChainedTxTypeArk IndexerChainedTxType = "ark" IndexerChainedTxTypeTree IndexerChainedTxType = "tree" IndexerChainedTxTypeCheckpoint IndexerChainedTxType = "checkpoint" )
type Info ¶
type Info struct {
Version string
SignerPubKey string
ForfeitPubKey string
UnilateralExitDelay int64
BoardingExitDelay int64
SessionDuration int64
Network string
Dust uint64
ForfeitAddress string
ScheduledSessionStartTime int64
ScheduledSessionEndTime int64
ScheduledSessionPeriod int64
ScheduledSessionDuration int64
ScheduledSessionFees FeeInfo
UtxoMinAmount int64
UtxoMaxAmount int64
VtxoMinAmount int64
VtxoMaxAmount int64
CheckpointTapscript string
MaxTxWeight int64
MaxOpReturnOutputs int64
Fees FeeInfo
DeprecatedSignerPubKeys []DeprecatedSignerInfo
ServiceStatus map[string]string
Digest string
}
func (Info) ServerParams ¶
func (i Info) ServerParams(serverUrl, explorerUrl string) (*ServerParams, error)
type NewControlAsset ¶
type NewControlAsset struct {
Amount uint64
}
NewControlAsset creates a new control asset with the specified amount.
type OnchainAddressEvent ¶
type OnchainAddressEvent struct {
Error error
SpentUtxos []OnchainOutput
NewUtxos []OnchainOutput
ConfirmedUtxos []OnchainOutput
Replacements map[string]string // replacedTxid -> replacementTxid
}
type OnchainOutput ¶
type PageOption ¶
type PageOption func(*pageOption) error
PageOption is a functional option for paginated requests.
func WithPage ¶
func WithPage(page *PageRequest) PageOption
type PageRequest ¶
type PageResponse ¶
type Receiver ¶
func (Receiver) ToArkFeeOutput ¶
type ScriptEvent ¶
type ScriptEvent struct {
Data *ScriptEventData
Connection *StreamConnectionEvent
Err error
}
type ScriptEventData ¶
type ServerParams ¶
type ServerParams struct {
ServerUrl string
SignerPubKey *btcec.PublicKey
ForfeitPubKey *btcec.PublicKey
Network arklib.Network
SessionDuration int64
UnilateralExitDelay arklib.RelativeLocktime
Dust uint64
BoardingExitDelay arklib.RelativeLocktime
ExplorerURL string
ForfeitAddress string
UtxoMinAmount int64
UtxoMaxAmount int64
VtxoMinAmount int64
VtxoMaxAmount int64
CheckpointTapscript string
Fees FeeInfo
DeprecatedSigners []DeprecatedSigner
}
func (ServerParams) AllSigners ¶
func (p ServerParams) AllSigners() map[string]*btcec.PublicKey
func (ServerParams) CheckpointExitPath ¶
func (p ServerParams) CheckpointExitPath() []byte
type SignFn ¶
SignFn signs the provided base64-encoded PSBT with the caller's identity and returns the signed PSBT base64.
type SpentStatus ¶
type StreamConnectionEvent ¶
type StreamConnectionState ¶
type StreamConnectionState string
const ( StreamConnectionStateDisconnected StreamConnectionState = "DISCONNECTED" StreamConnectionStateReconnected StreamConnectionState = "RECONNECTED" StreamConnectionStateReady StreamConnectionState = "READY" )
type StreamStartedEvent ¶
type StreamStartedEvent struct {
Id string
}
type Transaction ¶
type Transaction struct {
TransactionKey
Amount uint64
Type TxType
CreatedAt time.Time
Hex string
SettledBy string
AssetPacket asset.Packet
// Assets is the per-asset breakdown for this transaction, expressed as
// net amounts (gross inputs minus own change). Populated at construction
// by any code path that has the source vtxos in hand — notably
// funding.vtxosToTxs (for reconciled history) and the wallet-side
// send/batch handlers (for just-signed sends). Nil for pure-BTC
// transactions.
Assets []Asset
}
func (Transaction) String ¶
func (t Transaction) String() string
type TransactionEvent ¶
type TransactionEvent struct {
CommitmentTx *TxNotification
ArkTx *TxNotification
SweepTx *TxNotification
Connection *StreamConnectionEvent
Err error
}
type TransactionKey ¶
func (TransactionKey) String ¶
func (t TransactionKey) String() string
type TreeNoncesAggregatedEvent ¶
type TreeNoncesAggregatedEvent struct {
Id string
Nonces tree.TreeNonces
}
type TreeNoncesEvent ¶
type TreeSignatureEvent ¶
type TreeSigningStartedEvent ¶
type TreeTxEvent ¶
type TreeTxEvent struct {
Id string
Topic []string
BatchIndex int32
Node tree.TxTreeNode
}
type TxHistoryResponse ¶
type TxHistoryResponse struct {
History []Transaction
Page *PageResponse
}
type TxNotification ¶
type Utxo ¶
type Utxo struct {
Outpoint
Amount uint64
Script string
Delay arklib.RelativeLocktime
RedeemableAt time.Time
CreatedAt time.Time
Spent bool
SpentBy string
Tx string
Assets []Asset
Tapscripts []string
SigningClosure script.Closure
}
func (Utxo) IsConfirmed ¶
func (Utxo) ParseClosure ¶
func (u Utxo) ParseClosure() ([]byte, *arklib.TaprootMerkleProof, error)
func (Utxo) ToArkFeeInput ¶
func (u Utxo) ToArkFeeInput() arkfee.OnchainInput
type VirtualTxsResponse ¶
type VirtualTxsResponse struct {
Txs []string
Page *PageResponse
}
type Vtxo ¶
type Vtxo struct {
Outpoint
Script string
Amount uint64
CommitmentTxids []string
ExpiresAt time.Time
CreatedAt time.Time
Preconfirmed bool
Swept bool
Unrolled bool
Spent bool
SpentBy string
SettledBy string
ArkTxid string
Assets []Asset
Tapscripts []string
SigningClosure script.Closure
}
func CoinSelectAsset ¶
func CoinSelectAsset( vtxos []Vtxo, amount uint64, assetID string, withoutExpirySorting bool, ) ([]Vtxo, uint64, error)
CoinSelectAsset picks vtxos that, combined, hold at least `amount` units of the asset identified by assetID. Vtxos with no matching asset are filtered out up front. By default vtxos are sorted so that the ones nearest to expiry sit at the end of the slice, and the loop picks from the front — i.e. it preserves the soonest-to-expire balance for as long as possible. Pass withoutExpirySorting=true to consume the input order verbatim (useful when the caller has already ordered the vtxos). Returns the selected vtxos plus the leftover change in asset units.
func (Vtxo) IsRecoverable ¶
func (Vtxo) ParseClosure ¶
func (v Vtxo) ParseClosure() ([]byte, *arklib.TaprootMerkleProof, error)
func (Vtxo) ToArkFeeInput ¶
func (v Vtxo) ToArkFeeInput() arkfee.OffchainInput
type VtxoChainResponse ¶
type VtxoChainResponse struct {
Chain []ChainWithExpiry
Page *PageResponse
}
type VtxoTreeLeavesResponse ¶
type VtxoTreeLeavesResponse struct {
Leaves []Outpoint
Page *PageResponse
}
type VtxoTreeResponse ¶
type VtxoTreeResponse struct {
Tree []TxNode
Page *PageResponse
}
type VtxosResponse ¶
type VtxosResponse struct {
Vtxos []Vtxo
Page *PageResponse
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package explorer provides an explorer client with support for multiple concurrent WebSocket connections for addresses tracking.
|
Package explorer provides an explorer client with support for multiple concurrent WebSocket connections for addresses tracking. |
|
internal
|
|