libbtc

package module
v0.0.0-...-13bd5bd Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2019 License: GPL-3.0 Imports: 18 Imported by: 4

README

LibBTC

Build Status Coverage Status

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMismatchedPubKeys = fmt.Errorf("failed to fund the transaction mismatched script public keys")
View Source
var ErrNoSpendingTransactions = fmt.Errorf("No spending transactions")
View Source
var ErrPostConditionCheckFailed = errors.New("post-condition check failed")

ErrPostConditionCheckFailed indicates that the post-condition for executing a transaction failed.

View Source
var ErrPreConditionCheckFailed = errors.New("pre-condition check failed")

ErrPreConditionCheckFailed indicates that the pre-condition for executing a transaction failed.

View Source
var ErrTimedOut = errors.New("timed out")

Functions

func NewErrBitcoinSubmitTx

func NewErrBitcoinSubmitTx(msg string) error

func NewErrInsufficientBalance

func NewErrInsufficientBalance(address string, required, current int64) error

func NewErrUnsupportedNetwork

func NewErrUnsupportedNetwork(network string) error

Types

type Account

type Account interface {
	Client
	Address() (btcutil.Address, error)
	SerializedPublicKey() ([]byte, error)
	Transfer(ctx context.Context, to string, value, fee int64, sendAll bool) (string, error)
	SendTransaction(
		ctx context.Context,
		script []byte,
		fee int64,
		updateTxIn func(*wire.TxIn),
		preCond func(*wire.MsgTx) bool,
		f func(*txscript.ScriptBuilder),
		postCond func(*wire.MsgTx) bool,
	) error
}

Account is an Bitcoin external account that can sign and submit transactions to the Bitcoin blockchain. An Account is an abstraction over the Bitcoin blockchain.

func NewAccount

func NewAccount(client Client, privateKey *ecdsa.PrivateKey) Account

NewAccount returns a user account for the provided private key which is connected to a Bitcoin client.

type Address

type Address struct {
	PublicKeyHash    string `json:"hash160"`
	Address          string `json:"address"`
	TransactionCount int64  `json:"n_tx"`
	Received         int64  `json:"total_received"`
	Sent             int64  `json:"total_sent"`
	Balance          int64  `json:"final_balance"`
}

type Block

type Block struct {
	BlockHash         string        `json:"hash"`
	Version           uint8         `json:"ver"`
	PreviousBlockHash string        `json:"prev_block"`
	MerkleRoot        string        `json:"mrkl_root"`
	Time              int64         `json:"time"`
	Bits              int64         `json:"bits"`
	Nonce             int64         `json:"nonce"`
	TransactionCount  int           `json:"n_tx"`
	Size              int64         `json:"size"`
	BlockIndex        uint64        `json:"block_index"`
	MainChain         bool          `json:"main_chain"`
	Height            int64         `json:"height"`
	ReceivedTime      int64         `json:"received_time"`
	RelayedBy         string        `json:"relayed_by"`
	Transactions      []Transaction `json:"tx"`
}

type Blocks

type Blocks struct {
	Blocks []Block `json:"block"`
}

type Client

type Client interface {
	// NetworkParams should return the network parameters of the underlying
	// Bitcoin blockchain.
	NetworkParams() *chaincfg.Params
	GetUnspentOutputs(ctx context.Context, address string, limit, confitmations int64) (Unspent, error)
	GetRawTransaction(ctx context.Context, txhash string) (Transaction, error)
	GetRawAddressInformation(ctx context.Context, addr string) (SingleAddress, error)

	// PublishTransaction should publish a signed transaction to the Bitcoin
	// blockchain.
	PublishTransaction(ctx context.Context, signedTransaction []byte) error

	// Balance of the given address on Bitcoin blockchain.
	Balance(ctx context.Context, address string, confirmations int64) (int64, error)

	// ScriptSpent checks whether a script is spent.
	ScriptSpent(ctx context.Context, address string) (bool, error)

	// ScriptFunded checks whether a script is funded.
	ScriptFunded(ctx context.Context, address string, value int64) (bool, int64, error)

	ScriptRedeemed(ctx context.Context, address string, value int64) (bool, int64, error)

	GetScriptFromSpentP2SH(ctx context.Context, address string) ([]byte, error)

	Confirmations(ctx context.Context, txHash string) (int64, error)

	// FormatTransactionView formats the message and txhash into a user friendly
	// message.
	FormatTransactionView(msg, txhash string) string
}

func NewBlockchainInfoClient

func NewBlockchainInfoClient(network string) Client

type Input

type Input struct {
	PrevOut PreviousOut `json:"prev_out"`
	Script  string      `json:"script"`
}

type LatestBlock

type LatestBlock struct {
	Hash       string `json:"hash"`
	Time       int64  `json:"time"`
	BlockIndex int64  `json:"block_index"`
	Height     int64  `json:"height"`
}

type MultiAddress

type MultiAddress struct {
	Addresses    []Address     `json:"addresses"`
	Transactions []Transaction `json:"txs"`
}

type Output

type Output struct {
	Value           uint64 `json:"value"`
	TransactionHash string `json:"hash"`
	Script          string `json:"script"`
}

type PreviousOut

type PreviousOut struct {
	TransactionHash  string `json:"hash"`
	Value            uint64 `json:"value"`
	TransactionIndex uint64 `json:"tx_index"`
	VoutNumber       uint8  `json:"n"`
	Address          string `json:"addr"`
}

type SingleAddress

type SingleAddress struct {
	PublicKeyHash              string        `json:"hash160"`
	Address                    string        `json:"address"`
	TransactionCount           int64         `json:"n_tx"`
	UnredeemedTransactionCount int64         `json:"n_unredeemed"`
	Received                   int64         `json:"total_received"`
	Sent                       int64         `json:"total_sent"`
	Balance                    int64         `json:"final_balance"`
	Transactions               []Transaction `json:"txs"`
}

type Transaction

type Transaction struct {
	TransactionHash  string   `json:"hash"`
	Version          uint8    `json:"ver"`
	VinSize          uint32   `json:"vin_sz"`
	VoutSize         uint32   `json:"vout_sz"`
	Size             int64    `json:"size"`
	RelayedBy        string   `json:"relayed_by"`
	BlockHeight      int64    `json:"block_height"`
	TransactionIndex uint64   `json:"tx_index"`
	Inputs           []Input  `json:"inputs"`
	Outputs          []Output `json:"out"`
}

type Unspent

type Unspent struct {
	Outputs []UnspentOutput `json:"unspent_outputs"`
}

type UnspentOutput

type UnspentOutput struct {
	TransactionAge          string `json:"tx_age"`
	TransactionHash         string `json:"tx_hash"`
	TransactionIndex        uint32 `json:"tx_index"`
	TransactionOutputNumber uint32 `json:"tx_output_n"`
	ScriptPubKey            string `json:"script"`
	Amount                  int64  `json:"value"`
}

Jump to

Keyboard shortcuts

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