Documentation
¶
Overview ¶
Package blockchain is the library behind the blockchain command line: the HTTP client, request shaping, and the typed data models for blockchain.info public endpoints.
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 transient failures (429 and 5xx) that a public API can throw under load. Build your endpoint calls and JSON decoding on top of it.
Index ¶
- Constants
- type Address
- type Block
- type Client
- func (c *Client) GetAddress(ctx context.Context, address string, limit int) (*Address, error)
- func (c *Client) GetLatestBlock(ctx context.Context) (*Block, error)
- func (c *Client) GetStats(ctx context.Context) (*Stats, error)
- func (c *Client) GetTicker(ctx context.Context, currency string) ([]*Price, error)
- func (c *Client) GetTransaction(ctx context.Context, hash string) (*Transaction, error)
- type Config
- type Domain
- type Price
- type Stats
- type Transaction
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const DefaultUserAgent = "blockchain-cli/dev (+https://github.com/tamnd/blockchain-cli)"
DefaultUserAgent identifies the client to blockchain.info. A real, honest User-Agent is both polite and the thing most likely to keep you unblocked.
const Host = "blockchain.info"
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"`
TotalReceived int64 `json:"total_received"`
TotalSent int64 `json:"total_sent"`
FinalBalance int64 `json:"final_balance"`
}
Address is address info from /rawaddr/<address>.
type Block ¶
type Block struct {
Hash string `kit:"id" json:"hash"`
Height int `json:"height"`
Time int64 `json:"time"`
BlockIndex int `json:"block_index"`
TxCount int `json:"tx_count"`
}
Block is the latest block summary from /latestblock.
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 (*Client) GetAddress ¶
GetAddress fetches /rawaddr/<address>?limit=<limit>.
func (*Client) GetLatestBlock ¶
GetLatestBlock fetches /latestblock and returns the latest block.
func (*Client) GetStats ¶
GetStats fetches /stats and /latestblock, combines them into one Stats record.
func (*Client) GetTicker ¶
GetTicker fetches /ticker and returns prices for all currencies. If currency is non-empty, only that currency is returned.
func (*Client) GetTransaction ¶
GetTransaction fetches /rawtx/<hash> and computes input/output sums.
type Domain ¶
type Domain struct{}
Domain is the blockchain driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Classify ¶
Classify turns any accepted input into the canonical (type, id). Bitcoin address starts with 1, 3, or bc1; 64-char hex is a tx hash.
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.
type Price ¶
type Price struct {
Currency string `kit:"id" json:"currency"`
Last float64 `json:"last"`
Buy float64 `json:"buy"`
Sell float64 `json:"sell"`
Symbol string `json:"symbol"`
}
Price is the BTC price in one currency from /ticker.
type Stats ¶
type Stats struct {
Difficulty float64 `kit:"id" json:"difficulty"`
HashRate float64 `json:"hash_rate"`
TotalBitcoins float64 `json:"total_bitcoins"`
MarketPriceUSD float64 `json:"market_price_usd"`
TradeVolumeBTC float64 `json:"trade_volume_btc"`
MinutesBetweenBlocks float64 `json:"minutes_between_blocks"`
BlockHeight int `json:"block_height"`
}
Stats is the Bitcoin network snapshot from /stats.
type Transaction ¶
type Transaction struct {
Hash string `kit:"id" json:"hash"`
Time int64 `json:"time"`
BlockHeight int `json:"block_height"`
Fee int64 `json:"fee"`
InputCount int `json:"input_count"`
OutputCount int `json:"output_count"`
InputSum int64 `json:"input_sum"`
OutputSum int64 `json:"output_sum"`
}
Transaction is a raw transaction from /rawtx/<hash>.