blockchaininfo

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: 11 Imported by: 0

Documentation

Overview

Package blockchaininfo is the library behind the blockchain-info command line: the HTTP client, request shaping, and the typed data models for blockchain.info.

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 = "blockchain-info-cli/dev (+https://github.com/tamnd/blockchain-info-cli)"

DefaultUserAgent identifies the client to blockchain.info.

View Source
const Host = "blockchain.info"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Hash       string  `kit:"id" json:"hash"`
	Height     int     `json:"height"`
	Time       int64   `json:"time"`
	TxCount    int     `json:"tx_count"`
	Size       int     `json:"size"`
	Difficulty float64 `json:"difficulty"`
	Nonce      int64   `json:"nonce"`
	Weight     int     `json:"weight"`
}

Block holds summary data for one block from /block-height/{height}?format=json.

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	// Rate is the minimum gap between requests. Zero means no pacing.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to blockchain.info over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults: a 30s timeout, a 500ms minimum gap between requests, and five retries on transient errors.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) ([]byte, error)

Get fetches url and returns the response body. It paces and retries according to the client's settings. The caller owns nothing extra; the body is read fully and closed here.

type Conversion

type Conversion struct {
	Currency string  `kit:"id" json:"currency"`
	Value    float64 `json:"fiat_value"`
	BTC      float64 `json:"btc"`
}

Conversion holds the result of converting a fiat amount to BTC.

type Domain

type Domain struct{}

Domain is the blockchain-info driver.

func (Domain) Classify

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

Classify turns any accepted input into the canonical (type, id). Numeric string → ("height", input); 3-letter uppercase → ("currency", input).

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 Stats

type Stats struct {
	MarketPriceUSD       float64 `kit:"id" json:"market_price_usd"`
	HashRate             float64 `json:"hash_rate"`
	TotalBlocksMined     int64   `json:"total_blocks_mined"`
	TotalBTCMinted       int64   `json:"total_btc_minted_satoshi"`
	TotalTransactions    int64   `json:"total_transactions"`
	Difficulty           float64 `json:"difficulty"`
	MinutesBetweenBlocks float64 `json:"minutes_between_blocks"`
}

Stats holds network statistics from /stats?format=json.

type TickerPrice

type TickerPrice struct {
	Currency string  `kit:"id" json:"currency"`
	Last     float64 `json:"last"`
	Buy      float64 `json:"buy"`
	Sell     float64 `json:"sell"`
	Symbol   string  `json:"symbol"`
}

TickerPrice holds the current price for one currency from /ticker.

Jump to

Keyboard shortcuts

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