esplora

package
v0.0.0-...-581a61f Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package esplora provides a minimal typed client for the Esplora HTTP API (Elements/Liquid variant). Only the endpoints needed by Anchor are implemented.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetInfo

type AssetInfo struct {
	AssetID      string         `json:"asset_id"`
	IssuanceTxIn *AssetIssuance `json:"issuance_txin"`
	Status       TxStatus       `json:"status"`
}

AssetInfo holds Elements asset metadata from the Esplora API.

type AssetIssuance

type AssetIssuance struct {
	TxID string `json:"txid"`
	Vin  int    `json:"vin"`
}

AssetIssuance identifies the issuance input for an asset.

type Block

type Block struct {
	ID                string `json:"id"`
	Height            int    `json:"height"`
	Version           int    `json:"version"`
	Timestamp         int64  `json:"timestamp"`
	MedianTime        int64  `json:"mediantime"`
	TxCount           int    `json:"tx_count"`
	Size              int    `json:"size"`
	Weight            int    `json:"weight"`
	PreviousBlockHash string `json:"previousblockhash"`
}

Block is a block summary from the blocks endpoint.

type Client

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

Client is an Esplora HTTP API client.

func New

func New(baseURL string) *Client

New creates an Esplora client for the given base URL (e.g. "http://10.1.10.5:5500").

func (*Client) GetAddressMempoolTxs

func (c *Client) GetAddressMempoolTxs(addr string) ([]Tx, error)

GetAddressMempoolTxs returns unconfirmed transactions for an address (max 50).

func (*Client) GetAddressTxs

func (c *Client) GetAddressTxs(addr string, afterTxID string) ([]Tx, error)

GetAddressTxs returns up to 25 confirmed transactions for an address, plus up to 50 unconfirmed. For paging confirmed txs, pass the last txid seen as afterTxID; pass "" for the first page.

func (*Client) GetAddressUTXOs

func (c *Client) GetAddressUTXOs(addr string) ([]UTXO, error)

GetAddressUTXOs returns unspent outputs for an address.

func (*Client) GetAsset

func (c *Client) GetAsset(assetID string) (*AssetInfo, error)

GetAsset fetches asset metadata by asset ID, including the issuance transaction.

func (*Client) GetBlockTxs

func (c *Client) GetBlockTxs(blockHash string, startIndex int) ([]Tx, error)

GetBlockTxs returns up to 25 transactions from a block, starting at startIndex. startIndex must be a multiple of 25.

func (*Client) GetBlocks

func (c *Client) GetBlocks(startHeight int) ([]Block, error)

GetBlocks returns 10 block summaries starting at the given height (descending). Pass -1 to start from the tip.

func (*Client) GetTx

func (c *Client) GetTx(txid string) (*Tx, error)

GetTx fetches a transaction by txid.

func (*Client) Ping

func (c *Client) Ping() (int, error)

Ping checks connectivity by fetching the chain tip height. Returns the current block height or an error.

type Issuance

type Issuance struct {
	AssetID      string `json:"asset_id"`
	IsReissuance bool   `json:"is_reissuance"`
	ContractHash string `json:"contract_hash"`
	AssetEntropy string `json:"asset_entropy"`
	AssetAmount  uint64 `json:"assetamount"`
	TokenAmount  uint64 `json:"tokenamount"`
}

Issuance holds Elements asset issuance data attached to a transaction input.

type PoolCreationRecord

type PoolCreationRecord struct {
	TxID   string // creation transaction ID
	Asset0 string // display hex (reversed from internal)
	Asset1 string // display hex
	FeeNum uint16
	FeeDen uint16
	Height int // block height (-1 if unconfirmed)
}

PoolCreationRecord holds parameters decoded from an ANCHR OP_RETURN output.

func ParseAnchorOutput

func ParseAnchorOutput(scriptHex, txid string, height int) (PoolCreationRecord, bool)

ParseAnchorOutput attempts to decode an ANCHR OP_RETURN from a scriptPubKey hex.

func ScanPoolCreations

func ScanPoolCreations(c *Client, asset0, asset1 string, startHeight int) ([]PoolCreationRecord, error)

ScanPoolCreations scans blocks from startHeight to the chain tip for ANCHR OP_RETURN outputs. Uses the Esplora block and block-tx endpoints which are indexed and much faster than RPC block-by-block scanning.

If asset0 or asset1 is non-empty, only records matching both assets are returned (case-insensitive). Pass "" to return all pools.

type Tx

type Tx struct {
	TxID     string   `json:"txid"`
	Version  int      `json:"version"`
	Locktime int      `json:"locktime"`
	Size     int      `json:"size"`
	Weight   int      `json:"weight"`
	Fee      uint64   `json:"fee"`
	Vin      []TxVin  `json:"vin"`
	Vout     []TxVout `json:"vout"`
	Status   TxStatus `json:"status"`
}

Tx is a transaction from the Esplora API.

type TxStatus

type TxStatus struct {
	Confirmed   bool   `json:"confirmed"`
	BlockHeight int    `json:"block_height"`
	BlockHash   string `json:"block_hash"`
	BlockTime   int64  `json:"block_time"`
}

TxStatus holds confirmation info for a transaction or UTXO.

type TxVin

type TxVin struct {
	TxID       string    `json:"txid"`
	Vout       uint32    `json:"vout"`
	Prevout    *TxVout   `json:"prevout"`
	Issuance   *Issuance `json:"issuance"`
	IsCoinbase bool      `json:"is_coinbase"`
	Sequence   uint32    `json:"sequence"`
}

TxVin is a transaction input.

type TxVout

type TxVout struct {
	ScriptPubKey     string `json:"scriptpubkey"`
	ScriptPubKeyAsm  string `json:"scriptpubkey_asm"`
	ScriptPubKeyType string `json:"scriptpubkey_type"`
	ScriptPubKeyAddr string `json:"scriptpubkey_address"`
	Value            uint64 `json:"value"`
	Asset            string `json:"asset"`
}

TxVout is a transaction output.

type UTXO

type UTXO struct {
	TxID   string   `json:"txid"`
	Vout   uint32   `json:"vout"`
	Value  uint64   `json:"value"`
	Asset  string   `json:"asset"`
	Status TxStatus `json:"status"`
}

UTXO is an unspent output from the address UTXO endpoint.

Jump to

Keyboard shortcuts

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