gobcy

package module
v2.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2020 License: MIT Imports: 13 Imported by: 33

README

gobcy

A Go wrapper for the BlockCypher API. Targeting support for Bitcoin (main and testnet3) and BlockCypher's internal testnet, but others (Litecoin, Dogecoin) should work too. The wrapper works also for some query for Ethereum but the compatibility is not fully guaranteed.

Configuration

Import the package like so:

import "github.com/blockcypher/gobcy"

Then initiate an API struct with your credentials:

//explicitly
bc := gobcy.API{}
bc.Token = "your-api-token-here"
bc.Coin = "btc" //options: "btc","bcy","ltc","doge","eth"
bc.Chain = "main" //depending on coin: "main","test3","test"

//using a struct literal
bc := gobcy.API{"your-api-token-here","btc","main"}

//query away
fmt.Println(bc.GetChain())
fmt.Println(bc.GetBlock(300000,"",nil))

Usage

Check the "types.go" file for information on the return types. Almost all API calls are supported, with a few dropped to reduce complexity. If an API call supports URL parameters, it will likely appear as a params map[string]string variable in the API method. You can check the docs for supported URL flags.

Speaking of API docs, you can check out BlockCypher's documentation here. We've also heavily commented the code following Golang convention, so you might also find the GoDoc quite useful. The gobcy_test.go file also shows most of the API calls in action.

Testing

The aforementioned gobcy_test.go file contains a number of tests to ensure the wrapper is functioning properly. If you run it yourself, you'll have to insert a valid API token; you may also want to generate a new token, as the test POSTs and DELETEs WebHooks and Payment Forwarding requests.

Documentation

Overview

Package gobcy implements a wrapper for the http://www.blockcypher.com API. You can use it to interact with addresses, transactions, and blocks from various blockchains, including Bitcoin's main and test3 chains, and the BlockCypher test chain.

Please note: we assume you use are using a 64-bit architecture for deployment, which automatically makes `int` types 64-bit. Without 64-bit ints, some values might overflow on certain calls, depending on the blockchain you are querying. If you are using a 32-bit system, you can change all `int` types to `int64` to explicitly work around this issue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	Token, Coin, Chain string
}

API stores your BlockCypher Token, and the coin/chain you're querying. Coins can be "btc","bcy","ltc", and "doge". Chains can be "main", "test3", or "test", depending on the Coin. Check http://dev.blockcypher.com/ for more information. All your credentials are stored within an API struct, as are many of the API methods. You can allocate an API struct like so:

bc = gobcy.API{"your-api-token","btc","main"}

Then query as you like:

chain = bc.GetChain()

func (*API) AddAddrWallet

func (api *API) AddAddrWallet(name string, addrs []string, omitAddr bool) (wal Wallet, err error)

AddAddrWallet adds a slice of addresses to a named Wallet, associated with the API token/coin/chain. In addition to your list of addresses to add, takes one additional parameter:

"omitAddr," if true will omit wallet addresses in your
response. Useful to speed up the API call for larger wallets.

func (*API) CheckUsage added in v1.2.0

func (api *API) CheckUsage() (usage TokenUsage, err error)

CheckUsage checks token usage

func (*API) CreateHDWallet

func (api *API) CreateHDWallet(req HDWallet) (wal HDWallet, err error)

CreateHDWallet creates a public-address watching HDWallet associated with this token/coin/chain, usable anywhere in the API where an Address might be used (just use the wallet name instead). For example, with checking a wallet name balance:

addr, err := api.GetAddrBal("your-hd-wallet-name")

func (*API) CreateHook

func (api *API) CreateHook(hook Hook) (result Hook, err error)

CreateHook creates a new WebHook associated with your API.Token, and returns a WebHook with a BlockCypher-assigned id.

func (*API) CreatePayFwd added in v1.0.1

func (api *API) CreatePayFwd(payment PayFwd) (result PayFwd, err error)

CreatePayFwd creates a new PayFwd forwarding request associated with your API.Token, and returns a PayFwd with a BlockCypher-assigned id.

func (*API) CreateWallet

func (api *API) CreateWallet(req Wallet) (wal Wallet, err error)

CreateWallet creates a public-address watching wallet associated with this token/coin/chain, usable anywhere in the API where an Address might be used (just use the wallet name instead). For example, with checking a wallet name balance:

addr, err := api.GetAddrBal("your-wallet-name", nil)

func (*API) DecodeTX

func (api *API) DecodeTX(hex string) (trans TX, err error)

DecodeTX takes a hex-encoded transaction string and decodes it into a TX object, without sending it along to the Coin/Chain network.

func (*API) DeleteAddrWallet

func (api *API) DeleteAddrWallet(name string, addrs []string) (err error)

DeleteAddrWallet deletes a slice of addresses associated with a named Wallet, associated with the API token/coin/chain.

func (*API) DeleteHDWallet

func (api *API) DeleteHDWallet(name string) (err error)

DeleteHDWallet deletes a named HDWallet associated with the API token/coin/chain.

func (*API) DeleteHook

func (api *API) DeleteHook(id string) (err error)

DeleteHook deletes a WebHook notification from BlockCypher's database, based on its id.

func (*API) DeleteMeta added in v1.1.0

func (api *API) DeleteMeta(hash string, kind string) (err error)

DeleteMeta deletes ALL PRIVATE BlockCypher-stored metadata associated with the hash of the given blockchain object. "Kind" describes the blockchain object you're querying:

"addr" (for an address)
"tx" (for a transaction)
"block" (for a block)

Public metadata cannot be deleted; it is immutable.

func (*API) DeletePayFwd added in v1.0.1

func (api *API) DeletePayFwd(id string) (err error)

DeletePayFwd deletes a PayFwd request from BlockCypher's database, based on its id.

func (*API) DeleteWallet

func (api *API) DeleteWallet(name string) (err error)

DeleteWallet deletes a named wallet associated with the API token/coin/chain.

func (*API) DeriveAddrHDWallet

func (api *API) DeriveAddrHDWallet(name string, params map[string]string) (wal HDWallet, err error)

DeriveAddrHDWallet derives a new address within the named Wallet, associated with the API token/coin/chain. It will only return a partial HDWallet, ONLY containing the new address derived.

func (*API) Faucet

func (api *API) Faucet(a AddrKeychain, amount int) (txhash string, err error)

Faucet funds the AddrKeychain with an amount. Only works on BlockCypher's Testnet and Bitcoin Testnet3. Returns the transaction hash funding your AddrKeychain.

func (*API) GenAddrKeychain

func (api *API) GenAddrKeychain() (pair AddrKeychain, err error)

GenAddrKeychain generates a public/private key pair for use with transactions within the specified coin/chain. Please note that this call must be made over SSL, and it is not recommended to keep large amounts in these addresses, or for very long.

func (*API) GenAddrMultisig

func (api *API) GenAddrMultisig(multi AddrKeychain) (addr AddrKeychain, err error)

GenAddrMultisig generates a P2SH multisignature address using an array of PubKeys and the ScriptType from a AddrKeychain. Other fields are ignored, and the ScriptType must be a "multisig-n-of-m" type. Returns an AddrKeychain with the same PubKeys, ScriptType, and the proper P2SH address in the AddrKeychain's address field.

func (*API) GenAddrWallet

func (api *API) GenAddrWallet(name string) (wal Wallet, addr AddrKeychain, err error)

GenAddrWallet generates a new address within the named Wallet, associated with the API token/coin/chain. Also returns the private/WIF/public key of address via an Address Keychain.

func (*API) GenAssetKeychain added in v1.1.0

func (api *API) GenAssetKeychain() (pair AddrKeychain, err error)

GenAssetKeychain generates a public/private key pair, alongside an associated OAPAddress for use in the Asset API.

func (*API) GetAddr

func (api *API) GetAddr(hash string, params map[string]string) (addr Addr, err error)

GetAddr returns information for a given public address, including a slice of confirmed and unconfirmed transaction outpus via the TXRef arrays in the Address type. Returns more information than GetAddrBal, but slightly slower.

func (*API) GetAddrBal

func (api *API) GetAddrBal(hash string, params map[string]string) (addr Addr, err error)

GetAddrBal returns balance information for a given public address. Fastest Address API call, but does not include transaction details.

func (*API) GetAddrFull

func (api *API) GetAddrFull(hash string, params map[string]string) (addr Addr, err error)

GetAddrFull returns information for a given public address, including a slice of TXs associated with this address. Returns more data than GetAddr since it includes full transactions, but slowest Address query.

func (*API) GetAddrFullNext added in v1.1.0

func (api *API) GetAddrFullNext(this Addr) (next Addr, err error)

GetAddrFullNext returns a given Addr's next page of TXs, if Addr.HasMore is true. If HasMore is false, will return an error. It assumes default API URL parameters, like GetAddrFull.

func (*API) GetAddrHDWallet

func (api *API) GetAddrHDWallet(name string, params map[string]string) (addrs HDWallet, err error)

GetAddrHDWallet returns addresses associated with a named HDWallet, associated with the API token/coin/chain. It also optionally accepts URL parameters.

func (*API) GetAddrNext added in v1.1.0

func (api *API) GetAddrNext(this Addr) (next Addr, err error)

GetAddrNext returns a given Addr's next page of TXRefs, if Addr.HasMore is true. If HasMore is false, will return an error. It assumes default API URL parameters.

func (*API) GetAddrWallet

func (api *API) GetAddrWallet(name string, params map[string]string) (addrs []string, err error)

GetAddrWallet returns a slice of addresses associated with a named Wallet, associated with the API token/coin/chain. Takes an optionally-nil URL parameter map.

func (*API) GetAssetAddr added in v1.1.0

func (api *API) GetAssetAddr(assetID, oapAddr string) (addr Addr, err error)

GetAssetAddr returns an Addr associated with the given assetID and oapAddr. Note that while it returns an Address, anything that would have represented "satoshis" now represents "amount of asset."

func (*API) GetAssetTX added in v1.1.0

func (api *API) GetAssetTX(assetID, hash string) (tx OAPTX, err error)

GetAssetTX returns a OAPTX associated with the given assetID and transaction hash.

func (*API) GetBlock

func (api *API) GetBlock(height int, hash string, params map[string]string) (block Block, err error)

GetBlock returns a Block based on either height or hash. If both height and hash are sent, it will throw an error.

func (*API) GetBlockNextTXs

func (api *API) GetBlockNextTXs(this Block) (next Block, err error)

GetBlockNextTXs returns the the next page of TXids based on the NextTXs URL in this Block. If NextTXs is empty, this will return an error.

func (*API) GetChain

func (api *API) GetChain() (chain Blockchain, err error)

GetChain returns the current state of the configured Coin/Chain.

func (*API) GetHDWallet

func (api *API) GetHDWallet(name string) (wal HDWallet, err error)

GetHDWallet gets a HDWallet based on its name and the associated API token/coin/chain.

func (*API) GetHook added in v1.0.1

func (api *API) GetHook(id string) (hook Hook, err error)

GetHook returns a WebHook by its id.

func (*API) GetMeta added in v1.1.0

func (api *API) GetMeta(hash string, kind string, private bool) (meta map[string]string, err error)

GetMeta gets BlockCypher-stored metadata associated with the hash of the given blockchain object. "Kind" describes the blockchain object you're querying:

"addr" (for an address)
"tx" (for a transaction)
"block" (for a block)

If private is false, will retrieve publicly stored metadata. If private is true, will retrieve privately stored metadata associated with your token.

func (*API) GetPayFwd added in v1.0.1

func (api *API) GetPayFwd(id string) (payment PayFwd, err error)

GetPayFwd returns a PayFwd based on its id.

func (*API) GetTX

func (api *API) GetTX(hash string, params map[string]string) (tx TX, err error)

GetTX returns a TX represented by the passed hash. Takes an optionally-nil URL parameter map.

func (*API) GetTXConf

func (api *API) GetTXConf(hash string) (conf TXConf, err error)

GetTXConf returns a TXConf containing a float [0,1] that represents BlockCypher's confidence that an unconfirmed transaction won't be successfully double-spent against. If the confidence is 1, the transaction has already been confirmed.

func (*API) GetUnTX

func (api *API) GetUnTX() (txs []TX, err error)

GetUnTX returns an array of the latest unconfirmed TXs.

func (*API) GetWallet

func (api *API) GetWallet(name string) (wal Wallet, err error)

GetWallet gets a Wallet based on its name, the associated API token/coin/chain, and whether it's an HD wallet or not.

func (*API) IssueAsset added in v1.1.0

func (api *API) IssueAsset(issue OAPIssue) (tx OAPTX, err error)

IssueAsset issues new assets onto an Open Asset Address, using a private key associated with a funded address on the underlying blockchain.

func (*API) ListAssetTXs added in v1.1.0

func (api *API) ListAssetTXs(assetID string) (txs []string, err error)

ListAssetTXs lists the transaction hashes associated with the given assetID.

func (*API) ListHooks

func (api *API) ListHooks() (hooks []Hook, err error)

ListHooks returns a slice of WebHooks associated with your API.Token.

func (*API) ListPayFwds added in v1.0.1

func (api *API) ListPayFwds() (payments []PayFwd, err error)

ListPayFwds returns a PayFwds slice associated with your API.Token.

func (*API) ListPayFwdsPage added in v1.3.1

func (api *API) ListPayFwdsPage(start int) (payments []PayFwd, err error)

ListPayFwdsPage returns a PayFwds slice associated with your API.Token, starting at the start index. Useful for paging past the 200 payment forward limit.

func (*API) ListWallets

func (api *API) ListWallets() (names []string, err error)

ListWallets lists all known Wallets associated with this token/coin/chain.

func (*API) NewTX

func (api *API) NewTX(trans TX, verify bool) (skel TXSkel, err error)

NewTX takes a partially formed TX and returns a TXSkel with the data that needs to be signed. Can use TempNewTX or TempMultiTX to streamline input transaction, or customize transaction as described in the BlockCypher docs: http://dev.blockcypher.com/#customizing-transaction-requests If verify is true, will include "ToSignTX," which can be used to locally verify the "ToSign" data is valid.

func (*API) PushTX

func (api *API) PushTX(hex string) (trans TXSkel, err error)

PushTX takes a hex-encoded transaction string and pushes it directly to the Coin/Chain network.

func (*API) PutMeta added in v1.1.0

func (api *API) PutMeta(hash string, kind string, private bool, meta map[string]string) (err error)

PutMeta puts BlockCypher-stored metadata associated with the hash of the given blockchain object. "Kind" describes the blockchain object you're querying:

"addr" (for an address)
"tx" (for a transaction)
"block" (for a block)

If private is false, will set publicly stored metadata. If private is true, will set privately stored metadata associated with your token.

func (*API) SendMicro

func (api *API) SendMicro(mic MicroTX) (result MicroTX, err error)

SendMicro sends a Micro through the Coin/Chain network. It will return a Micro with a proper hash if it successfully sent. If using public (instead of private) keys, you'll need to sign the returned Micro (using the *Micro.Sign method) and run SendMicro again with the signed data, which will then return a proper hash.

func (*API) SendTX

func (api *API) SendTX(skel TXSkel) (trans TXSkel, err error)

SendTX takes a TXSkel, returns the completed transaction and sends it across the Coin/Chain network. TXSkel requires a fully formed TX, Signatures, and PubKeys. PubKeys should not be included in the special case of multi-sig addresses.

func (*API) TransferAsset added in v1.1.0

func (api *API) TransferAsset(issue OAPIssue, assetID string) (tx OAPTX, err error)

TransferAsset transfers previously issued assets onto a new Open Asset Address, based on the assetid and OAPIssue.

type Addr

type Addr struct {
	Address            string   `json:"address,omitempty"`
	Wallet             Wallet   `json:"wallet,omitempty"`
	HDWallet           HDWallet `json:"hd_wallet,omitempty"`
	TotalReceived      big.Int  `json:"total_received"`
	TotalSent          big.Int  `json:"total_sent"`
	Balance            big.Int  `json:"balance"`
	UnconfirmedBalance big.Int  `json:"unconfirmed_balance"`
	FinalBalance       big.Int  `json:"final_balance"`
	NumTX              int      `json:"n_tx"`
	UnconfirmedNumTX   int      `json:"unconfirmed_n_tx"`
	FinalNumTX         int      `json:"final_n_tx"`
	TXs                []TX     `json:"txs,omitempty"`
	TXRefs             []TXRef  `json:"txrefs,omitempty"`
	UnconfirmedTXRefs  []TXRef  `json:"unconfirmed_txrefs,omitempty"`
	HasMore            bool     `json:"hasMore,omitempty"`
}

Addr represents information about the state of a public address.

type AddrKeychain

type AddrKeychain struct {
	Address         string   `json:"address,omitempty"`
	Private         string   `json:"private,omitempty"`
	Public          string   `json:"public,omitempty"`
	Wif             string   `json:"wif,omitempty"`
	PubKeys         []string `json:"pubkeys,omitempty"`
	ScriptType      string   `json:"script_type,omitempty"`
	OriginalAddress string   `json:"original_address,omitempty"`
	OAPAddress      string   `json:"oap_address,omitempty"`
}

AddrKeychain represents information about a generated public-private key pair from BlockCypher's address generation API. Large amounts are not recommended to be stored with these addresses.

type Block

type Block struct {
	Hash         string    `json:"hash"`
	Height       int       `json:"height"`
	Depth        int       `json:"depth"`
	Chain        string    `json:"chain"`
	Total        big.Int   `json:"total"`
	Fees         big.Int   `json:"fees"`
	Ver          int       `json:"ver"`
	Time         time.Time `json:"time"`
	ReceivedTime time.Time `json:"received_time"`
	RelayedBy    string    `json:"relayed_by,omitempty"`
	Bits         int       `json:"bits"`
	Nonce        int       `json:"nonce"`
	NumTX        int       `json:"n_tx"`
	PrevBlock    string    `json:"prev_block"`
	MerkleRoot   string    `json:"mrkl_root"`
	TXids        []string  `json:"txids"`
	NextTXs      string    `json:"next_txids"`
}

Block represents information about the state of a given block in a blockchain.

type Blockchain

type Blockchain struct {
	Name             string    `json:"name"`
	Height           int       `json:"height"`
	Hash             string    `json:"hash"`
	Time             time.Time `json:"time"`
	PrevHash         string    `json:"previous_hash"`
	PeerCount        int       `json:"peer_count"`
	HighFee          int       `json:"high_fee_per_kb"`
	MediumFee        int       `json:"medium_fee_per_kb"`
	LowFee           int       `json:"low_fee_per_kb"`
	UnconfirmedCount int       `json:"unconfirmed_count"`
	LastForkHeight   int       `json:"last_fork_height"`
	LastForkHash     string    `json:"last_fork_hash"`
}

Blockchain represents information about the state of a blockchain.

type HDWallet

type HDWallet struct {
	Name            string `json:"name,omitempty"`
	ExtPubKey       string `json:"extended_public_key,omitempty"`
	SubchainIndexes []int  `json:"subchain_indexes,omitempty"`
	Chains          []struct {
		ChainAddr []struct {
			Address string `json:"address,omitempty"`
			Path    string `json:"path,omitempty"`
			Public  string `json:"public,omitempty"`
		} `json:"chain_addresses,omitempty"`
		Index int `json:"index,omitempty"`
	} `json:"chains,omitempty"`
}

HDWallet represents information about a Hierarchical Deterministic (HD) wallet. Like regular Wallets, HDWallets can be used wherever an address can be used within the API.

type Hook

type Hook struct {
	ID            string  `json:"id,omitempty"`
	Event         string  `json:"event"`
	Hash          string  `json:"hash,omitempty"`
	WalletName    string  `json:"wallet_name,omitempty"`
	Address       string  `json:"address,omitempty"`
	Confirmations int     `json:"confirmations,omitempty"`
	Confidence    float32 `json:"confidence,omitempty"`
	Script        string  `json:"script,omitempty"`
	URL           string  `json:"url,omitempty"`
	CallbackErrs  int     `json:"callback_errors,omitempty"`
}

Hook represents a WebHook/WebSockets event. BlockCypher supports the following events:

	Event = "unconfirmed-tx"
	Event = "new-block"
	Event = "confirmed-tx"
	Event = "tx-confirmation"
	Event = "double-spend-tx"
 Event = "tx-confidence"

Hash, Address, and Script are all optional; creating a WebHook with any of them will filter the resulting notifications, if appropriate. ID is returned by BlockCyphers servers after Posting a new WebHook; you shouldn't manually generate this field.

type MicroTX

type MicroTX struct {
	//Only one of Pubkey/Private/Wif is required
	Pubkey     string   `json:"from_pubkey,omitempty"`
	Priv       string   `json:"from_private,omitempty"`
	Wif        string   `json:"from_wif,omitempty"`
	ToAddr     string   `json:"to_address"`
	Value      big.Int  `json:"value_satoshis"`
	ChangeAddr string   `json:"change_address,omitempty"`
	Wait       bool     `json:"wait_guarantee,omitempty"`
	ToSign     []string `json:"tosign,omitempty"`
	Signatures []string `json:"signatures,omitempty"`
	Hash       string   `json:"hash,omitempty"`
	Inputs     []struct {
		PrevHash    string `json:"prev_hash"`
		OutputIndex int    `json:"output_index"`
	} `json:"inputs,omitempty"`
	Outputs []struct {
		Value   big.Int `json:"value"`
		Address string  `json:"address"`
	} `json:"outputs,omitempty"`
	Fees int `json:"fees,omitempty"`
}

MicroTX represents a microtransaction. For small-value transactions, BlockCypher will sign the transaction on your behalf, with your private key (if provided). Setting a separate change address is recommended. Where your application model allows it, consider only using public keys with microtransactions, and sign the microtransaction with your private key (without sending to BlockCypher's server).

func (*MicroTX) Sign

func (mic *MicroTX) Sign(priv string) (err error)

Sign takes a hex-encoded string slice of private keys and uses them to sign the ToSign data in a MicroTX, generating the proper hex-encoded Signatures. This is meant as a helperfunction, and leverages btcd's btcec library.

type NullData

type NullData struct {
	Data     string `json:"data"`
	Encoding string `json:"encoding,omitempty"`
	Hash     string `json:"hash,omitempty"`
}

NullData represents the call and return to BlockCypher's Data API, allowing you to embed up to 80 bytes into a blockchain via an OP_RETURN.

type OAPIssue added in v1.1.0

type OAPIssue struct {
	Priv     string  `json:"from_private"`
	ToAddr   string  `json:"to_address"`
	Amount   big.Int `json:"amount"`
	Metadata string  `json:"metadata,omitempty"`
}

OAPIssue represents a request for issuance or transfer of an Open Asset on a blockchain.

type OAPTX added in v1.1.0

type OAPTX struct {
	Ver         int       `json:"ver"`
	AssetID     string    `json:"assetid"`
	Hash        string    `json:"hash"`
	Confirmed   time.Time `json:"confirmed,omitempty"`
	Received    time.Time `json:"received"`
	Metadata    string    `json:"oap_meta,omitempty"`
	DoubleSpend bool      `json:"double_spend"`
	Inputs      []struct {
		PrevHash    string  `json:"prev_hash"`
		OutputIndex int     `json:"output_index"`
		OAPAddress  string  `json:"address"`
		OutputValue big.Int `json:"output_value"`
	} `json:"inputs"`
	Outputs []struct {
		OAPAddress      string  `json:"address"`
		Value           big.Int `json:"value"`
		OrigOutputIndex int     `json:"original_output_index"`
	} `json:"outputs"`
}

OAPTX represents an Open Asset protocol transaction, generated when issuing or transferring assets.

type PayFwd

type PayFwd struct {
	ID             string   `json:"id,omitempty"`
	Destination    string   `json:"destination"`
	InputAddr      string   `json:"input_address,omitempty"`
	ProcessAddr    string   `json:"process_fees_address,omitempty"`
	ProcessPercent float64  `json:"process_fees_percent,omitempty"`
	ProcessValue   big.Int  `json:"process_fees_satoshis,omitempty"`
	CallbackURL    string   `json:"callback_url,omitempty"`
	EnableConfirm  bool     `json:"enable_confirmations,omitempty"`
	MiningFees     int      `json:"mining_fees_satoshis,omitempty"`
	TXHistory      []string `json:"transactions,omitempty"`
}

PayFwd represents a reference to a Payment Forwarding request.

type Payback

type Payback struct {
	Value       big.Int `json:"value"`
	Destination string  `json:"destination"`
	DestHash    string  `json:"transaction_hash"`
	InputAddr   string  `json:"input_address"`
	InputHash   string  `json:"input_transaction_hash"`
}

Payback represents a Payment Forwarding Callback. It's more fun to call it a "payback."

type TX

type TX struct {
	BlockHash     string     `json:"block_hash,omitempty"`
	BlockHeight   int        `json:"block_height,omitempty"`
	Hash          string     `json:"hash,omitempty"`
	Addresses     []string   `json:"addresses,omitempty"`
	Total         big.Int    `json:"total,omitempty"`
	Fees          big.Int    `json:"fees,omitempty"`
	Size          int        `json:"size"`
	Preference    string     `json:"preference,omitempty"`
	RelayedBy     string     `json:"relayed_by,omitempty"`
	Received      time.Time  `json:"received,omitempty"`
	Confirmed     time.Time  `json:"confirmed,omitempty"`
	Confirmations int        `json:"confirmations,omitempty"`
	Confidence    float64    `json:"confidence,omitempty"`
	Ver           int        `json:"ver,omitempty"`
	LockTime      int        `json:"lock_time,omitempty"`
	DoubleSpend   bool       `json:"double_spend,omitempty"`
	DoubleOf      string     `json:"double_of,omitempty"`
	ReceiveCount  int        `json:"receive_count,omitempty"`
	VinSize       int        `json:"vin_sz,omitempty"`
	VoutSize      int        `json:"vout_sz,omitempty"`
	Hex           string     `json:"hex,omitempty"`
	DataProtocol  string     `json:"data_protocol,omitempty"`
	ChangeAddress string     `json:"change_address,omitempty"`
	NextInputs    string     `json:"next_inputs,omitempty"`
	NextOutputs   string     `json:"next_outputs,omitempty"`
	Inputs        []TXInput  `json:"inputs"`
	Outputs       []TXOutput `json:"outputs"`
}

TX represents information about the state of a given transaction in a blockchain.

func TempMultiTX

func TempMultiTX(inAddr string, outAddr string, amount big.Int, n int, pubkeys []string) (trans TX, err error)

TempMultiTX creates a skeleton multisig transaction, suitable for use in NewTX. If outAddr == "", then the returned TX will be a skeleton to fund a multisig address. If inAddr == "", then the returned TX will be a skeleton to send from a multisig address (/series of public keys). n represents the number of valid signatures required, and m is derived from the number of pubkeys.

func TempNewTX

func TempNewTX(inAddr string, outAddr string, amount big.Int) (trans TX)

TempNewTX creates a simple template transaction, suitable for use in NewTX. Takes an input/output address and amount.

type TXConf

type TXConf struct {
	Age          int     `json:"age_millis"`
	ReceiveCount int     `json:"receive_count,omitempty"`
	Confidence   float64 `json:"confidence"`
	TXHash       string  `json:"txhash"`
}

TXConf represents information about the confidence of an unconfirmed transaction.

type TXInput

type TXInput struct {
	PrevHash    string   `json:"prev_hash,omitempty"`
	OutputIndex int      `json:"output_index,omitempty"`
	OutputValue int      `json:"output_value,omitempty"`
	Addresses   []string `json:"addresses"`
	Sequence    int      `json:"sequence,omitempty"`
	ScriptType  string   `json:"script_type,omitempty"`
	Script      string   `json:"script,omitempty"`
	Age         int      `json:"age,omitempty"`
	WalletName  string   `json:"wallet_name,omitempty"`
}

TXInput represents the state of a transaction input

type TXOutput

type TXOutput struct {
	SpentBy    string   `json:"spent_by,omitempty"`
	Value      big.Int  `json:"value"`
	Addresses  []string `json:"addresses"`
	ScriptType string   `json:"script_type,omitempty"`
	Script     string   `json:"script,omitempty"`
	DataHex    string   `json:"data_hex,omitempty"`
	DataString string   `json:"data_string,omitempty"`
}

TXOutput represents the state of a transaction output

type TXRef

type TXRef struct {
	Address       string    `json:"address,omitempty"`
	BlockHeight   int       `json:"block_height"`
	TXHash        string    `json:"tx_hash"`
	TXInputN      int       `json:"tx_input_n"`
	TXOutputN     int       `json:"tx_output_n"`
	Value         big.Int   `json:"value"`
	Pref          string    `json:"preference"`
	Spent         bool      `json:"spent"`
	DoubleSpend   bool      `json:"double_spend"`
	DoubleOf      string    `json:"double_of,omitempty"`
	Confirmations int       `json:"confirmations"`
	Script        string    `json:"script,omitempty"`
	RefBalance    int       `json:"ref_balance,omitempty"`
	Confidence    float64   `json:"confidence,omitempty"`
	Confirmed     time.Time `json:"confirmed,omitempty"`
	SpentBy       string    `json:"spent_by,omitempty"`
	Received      time.Time `json:"received,omitempty"`
	ReceivedCount big.Int   `json:"received_count,omitempty"`
}

TXRef represents summarized data about a transaction input or output.

type TXSkel

type TXSkel struct {
	Trans      TX       `json:"tx"`
	ToSign     []string `json:"tosign"`
	Signatures []string `json:"signatures"`
	PubKeys    []string `json:"pubkeys,omitempty"`
	ToSignTX   []string `json:"tosign_tx,omitempty"`
	Errors     []struct {
		Error string `json:"error,omitempty"`
	} `json:"errors,omitempty"`
}

TXSkel represents the return call to BlockCypher's txs/new endpoint, and includes error information, hex transactions that need to be signed, and space for the signed transactions and associated public keys.

func (*TXSkel) Sign

func (skel *TXSkel) Sign(priv []string) (err error)

Sign takes a hex-encoded string slice of private keys and uses them to sign the ToSign data in a TXSkel, generating the proper Signatures and PubKeys array, both hex-encoded. This is meant as a helper function, and leverages btcd's btcec library.

type TokenUsage added in v1.2.0

type TokenUsage struct {
	Limits      Usage          `json:"limits"`
	Hits        Usage          `json:"hits"`
	HitsHistory []UsageHistory `json:"hits_history"`
}

TokenUsage represents information about the limits and usage against your token.

type Usage added in v1.2.0

type Usage struct {
	PerSec       int `json:"api/second,omitempty"`
	PerHour      int `json:"api/hour,omitempty"`
	PerDay       int `json:"api/day,omitempty"`
	HooksPerHour int `json:"hooks/hour,omitempty"`
	ConfPerHour  int `json:"confidence/hour,omitempty"`
	Hooks        int `json:"hooks,omitempty"`
	PayFwds      int `json:"payments,omitempty"`
}

Usage defines the usage of the token

type UsageHistory added in v1.3.1

type UsageHistory struct {
	Usage
	Time time.Time `json:",omitempty"`
}

UsageHistory defines the usage over time

type Wallet

type Wallet struct {
	Name      string   `json:"name,omitempty"`
	Addresses []string `json:"addresses,omitempty"`
}

Wallet represents information about a standard wallet. Typically, wallets can be used wherever an address can be used within the API.

Jump to

Keyboard shortcuts

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