mempool

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package mempool is the library behind the mempool command line: the HTTP client, request shaping, and the typed data models for mempool.space.

The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public site throws under load.

Index

Constants

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "mempool-cli/dev (+https://github.com/tamnd/mempool-cli)"

DefaultUserAgent identifies the client to mempool.space.

View Source
const Host = "mempool.space"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Address     string `kit:"id" json:"address"`
	TxCount     int    `json:"tx_count"`
	FundedSum   int64  `json:"funded_sum"`
	FundedCount int    `json:"funded_count"`
	SpentSum    int64  `json:"spent_sum"`
	Balance     int64  `json:"balance"`
}

Address holds the chain stats for a Bitcoin address.

type Block

type Block struct {
	ID        string  `kit:"id" json:"id"`
	Height    int     `json:"height"`
	Timestamp int64   `json:"timestamp"`
	Size      int     `json:"size"`
	Weight    int     `json:"weight"`
	TxCount   int     `json:"tx_count"`
	TotalFees int64   `json:"total_fees"`
	MedianFee float64 `json:"median_fee"`
	AvgFee    float64 `json:"avg_fee"`
}

Block holds summary data for a single Bitcoin block.

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	Rate      time.Duration
	Retries   int
	// contains filtered or unexported fields
}

Client talks to mempool.space over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with sensible defaults.

func (*Client) GetAddress

func (c *Client) GetAddress(ctx context.Context, address string) (*Address, error)

GetAddress fetches the chain stats for a Bitcoin address.

func (*Client) GetBlock

func (c *Client) GetBlock(ctx context.Context, hash string) (*Block, error)

GetBlock fetches a single block by its hash.

func (*Client) GetBlocks

func (c *Client) GetBlocks(ctx context.Context, limit int) ([]*Block, error)

GetBlocks fetches the most recent blocks. The API returns the last 10 blocks; limit <= 10 slices the result; limit 0 or > 10 returns all 10.

func (*Client) GetFees

func (c *Client) GetFees(ctx context.Context) (*Fees, error)

GetFees fetches the current recommended fee rates.

func (*Client) GetPrice

func (c *Client) GetPrice(ctx context.Context) (*Price, error)

GetPrice fetches the current BTC price in multiple currencies.

func (*Client) GetTransaction

func (c *Client) GetTransaction(ctx context.Context, txid string) (*Transaction, error)

GetTransaction fetches a single transaction by its TXID.

type Config

type Config struct {
	UserAgent string
	Rate      time.Duration
	Retries   int
	Timeout   time.Duration
}

Config holds the client configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Domain

type Domain struct{}

Domain is the mempool driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (type, id). Bitcoin address (starts with 1, 3, bc1) -> "address" 64-char hex -> "tx" numeric -> "height" (not directly addressable, but classified) otherwise -> "block"

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Fees

type Fees struct {
	FastestFee  int `kit:"id" json:"fastest_fee"`
	HalfHourFee int `json:"half_hour_fee"`
	HourFee     int `json:"hour_fee"`
	EconomyFee  int `json:"economy_fee"`
	MinimumFee  int `json:"minimum_fee"`
}

Fees holds the current recommended fee rates in sat/vByte.

type Price

type Price struct {
	Time  int64            `json:"time"`
	Rates map[string]int64 `json:"rates"`
}

Price holds the current BTC exchange rates.

type Transaction

type Transaction struct {
	TXID        string `kit:"id" json:"txid"`
	Size        int    `json:"size"`
	Weight      int    `json:"weight"`
	Fee         int64  `json:"fee"`
	VinCount    int    `json:"vin_count"`
	VoutCount   int    `json:"vout_count"`
	Confirmed   bool   `json:"confirmed"`
	BlockHeight int    `json:"block_height"`
}

Transaction holds the data for a single Bitcoin transaction.

Jump to

Keyboard shortcuts

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