libbtc

package module
v0.0.0-...-80332c7 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2019 License: GPL-3.0 Imports: 23 Imported by: 2

README

LibBTC · GitHub license CircleCI Status

Documentation

Index

Constants

View Source
const (
	Nil = TxExecutionSpeed(iota)
	Slow
	Standard
	Fast
)

TxExecutionSpeed values.

View Source
const BitcoinDust = 600
View Source
const MaxBitcoinFee = int64(10000)

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

func SuggestedTxRate

func SuggestedTxRate(txSpeed TxExecutionSpeed) (int64, error)

SuggestedTxRate returns the gas price that bitcoinfees.earn.com recommends for transactions to be mined on Bitcoin blockchain based on the speed provided.

Types

type Account

type Account interface {
	Client
	BTCClient() Client
	Address() (btcutil.Address, error)
	SerializedPublicKey() ([]byte, error)
	Transfer(ctx context.Context, to string, value int64, speed TxExecutionSpeed, sendAll bool) (string, int64, error)
	BuildTransfer(ctx context.Context, to string, value int64, speed TxExecutionSpeed, sendAll bool) (string, []byte, error)
	SendTransaction(
		ctx context.Context,
		script []byte,
		speed TxExecutionSpeed,
		updateTxIn func(*wire.TxIn),
		preCond func(*wire.MsgTx) bool,
		f func(*txscript.ScriptBuilder),
		postCond func(*wire.MsgTx) bool,
		sendAll bool,
	) (string, int64, error)
	BuildTransaction(
		ctx context.Context,
		contract []byte,
		speed TxExecutionSpeed,
		updateTxIn func(*wire.TxIn),
		preCond func(*wire.MsgTx) bool,
		f func(*txscript.ScriptBuilder),
		postCond func(*wire.MsgTx) bool,
		sendAll bool,
	) (string, []byte, 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, logger logrus.FieldLogger) Account

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

type Client

type Client interface {
	clients.ClientCore

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

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

	// SerializePublicKey serializes the given public key.
	SerializePublicKey(pubKey *btcec.PublicKey) ([]byte, error)

	// PublicKeyToAddress converts the public key to a bitcoin address.
	PublicKeyToAddress(pubKeyBytes []byte) (btcutil.Address, error)

	// SlaveAddress creates an a deterministic unique address that can be spent
	// by the private key correspndong to the given master public key hash
	SlaveAddress(mpkh, nonce []byte) (btcutil.Address, error)

	// SlaveScript creates a deterministic unique script that can be spent by
	// the private key correspndong to the given master public key hash
	SlaveScript(mpkh, nonce []byte) ([]byte, error)

	// UTXOCount returns the number of utxos that can be spent.
	UTXOCount(ctx context.Context, address string, confirmations int64) (int, error)

	// Validate returns whether an address is valid or not
	Validate(address string) error
}

func NewBitcoinFNClient

func NewBitcoinFNClient(host, user, password string) (Client, error)

func NewBlockchainInfoClient

func NewBlockchainInfoClient(network string) (Client, error)

func NewMercuryClient

func NewMercuryClient(network string) (Client, error)

type Tx

type Tx interface {
	Hashes() [][]byte
	InjectSigs(sigs []*btcec.Signature) error
	Submit(ctx context.Context) ([]byte, error)
}

type TxBuilder

type TxBuilder interface {
	Build(ctx context.Context, pubKey ecdsa.PublicKey, to string, contract []byte, value int64, mwUTXOs, scriptUTXOs []clients.UTXO) (Tx, error)
}

func NewTxBuilder

func NewTxBuilder(client Client) TxBuilder

type TxExecutionSpeed

type TxExecutionSpeed uint8

The TxExecutionSpeed indicates the tier of speed that the transaction falls under while writing to the blockchain.

type Wallet

type Wallet interface {
	NewAccount(derivationPath []uint32, password string) (Account, error)
}

func NewWallet

func NewWallet(mnemonic string, client Client, logger logrus.FieldLogger) Wallet

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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