bitcoin

package
v0.0.0-...-4a17716 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultClientTimeout used by the Client.
	DefaultClientTimeout = time.Minute
	// DefaultClientTimeoutRetry used by the Client.
	DefaultClientTimeoutRetry = time.Second
	// DefaultClientHost used by the Client. This should only be used for local
	// deployments of the multichain.
	DefaultClientHost = "http://0.0.0.0:18443"
	// DefaultClientUser used by the Client. This is insecure, and should only
	// be used for local — or publicly accessible — deployments of the
	// multichain.
	DefaultClientUser = "user"
	// DefaultClientPassword used by the Client. This is insecure, and should
	// only be used for local — or publicly accessible — deployments of the
	// multichain.
	DefaultClientPassword = "password"
)
View Source
const Version int32 = 2

Version of Bitcoin transactions supported by the multichain.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressDecoder

type AddressDecoder struct {
	// contains filtered or unexported fields
}

AddressDecoder encapsulates the chain specific configurations and implements the address.Decoder interface

func NewAddressDecoder

func NewAddressDecoder(params *chaincfg.Params) AddressDecoder

NewAddressDecoder constructs a new AddressDecoder with the chain specific configurations

func (AddressDecoder) DecodeAddress

func (decoder AddressDecoder) DecodeAddress(addr address.Address) (address.RawAddress, error)

DecodeAddress implements the address.Decoder interface

type AddressEncodeDecoder

type AddressEncodeDecoder struct {
	AddressEncoder
	AddressDecoder
}

AddressEncodeDecoder implements the address.EncodeDecoder interface

func NewAddressEncodeDecoder

func NewAddressEncodeDecoder(params *chaincfg.Params) AddressEncodeDecoder

NewAddressEncodeDecoder constructs a new AddressEncodeDecoder with the chain specific configurations

type AddressEncoder

type AddressEncoder struct {
	// contains filtered or unexported fields
}

AddressEncoder encapsulates the chain specific configurations and implements the address.Encoder interface

func NewAddressEncoder

func NewAddressEncoder(params *chaincfg.Params) AddressEncoder

NewAddressEncoder constructs a new AddressEncoder with the chain specific configurations

func (AddressEncoder) EncodeAddress

func (encoder AddressEncoder) EncodeAddress(rawAddr address.RawAddress) (address.Address, error)

EncodeAddress implements the address.Encoder interface

type Client

type Client interface {
	utxo.Client
	// UnspentOutputs spendable by the given address.
	UnspentOutputs(ctx context.Context, minConf, maxConf int64, address address.Address) ([]utxo.Output, error)
	// Confirmations of a transaction in the Bitcoin network.
	Confirmations(ctx context.Context, txHash pack.Bytes) (int64, error)
	// EstimateSmartFee
	EstimateSmartFee(ctx context.Context, numBlocks int64) (float64, error)
	// EstimateFeeLegacy
	EstimateFeeLegacy(ctx context.Context, numBlocks int64) (float64, error)
}

A Client interacts with an instance of the Bitcoin network using the RPC interface exposed by a Bitcoin node.

func NewClient

func NewClient(opts ClientOptions) Client

NewClient returns a new Client.

type ClientOptions

type ClientOptions struct {
	Timeout      time.Duration
	TimeoutRetry time.Duration
	Host         string
	User         string
	Password     string
}

ClientOptions are used to parameterise the behaviour of the Client.

func DefaultClientOptions

func DefaultClientOptions() ClientOptions

DefaultClientOptions returns ClientOptions with the default settings. These settings are valid for use with the default local deployment of the multichain. In production, the host, user, and password should be changed.

func (ClientOptions) WithHost

func (opts ClientOptions) WithHost(host string) ClientOptions

WithHost sets the URL of the Bitcoin node.

func (ClientOptions) WithPassword

func (opts ClientOptions) WithPassword(password string) ClientOptions

WithPassword sets the password that will be used to authenticate with the Bitcoin node.

func (ClientOptions) WithUser

func (opts ClientOptions) WithUser(user string) ClientOptions

WithUser sets the username that will be used to authenticate with the Bitcoin node.

type GasEstimator

type GasEstimator struct {
	// contains filtered or unexported fields
}

A GasEstimator returns the SATs-per-byte that is needed in order to confirm transactions with an estimated maximum delay of one block. In distributed networks that collectively build, sign, and submit transactions, it is important that all nodes in the network have reached consensus on the SATs-per-byte.

func NewGasEstimator

func NewGasEstimator(client Client, numBlocks int64, fallbackGas pack.U256) GasEstimator

NewGasEstimator returns a simple gas estimator that always returns the given number of SATs-per-byte.

func (GasEstimator) EstimateGas

func (gasEstimator GasEstimator) EstimateGas(ctx context.Context) (pack.U256, pack.U256, error)

EstimateGas returns the number of SATs-per-byte (for both price and cap) that is needed in order to confirm transactions with an estimated maximum delay of `numBlocks` block. It is the responsibility of the caller to know the number of bytes in their transaction. This method calls the `estimatesmartfee` RPC call to the node, which based on a conservative (considering longer history) strategy returns the estimated BTC per kilobyte of data in the transaction. An error will be returned if the bitcoin node hasn't observed enough blocks to make an estimate for the provided target `numBlocks`.

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

Tx represents a simple Bitcoin transaction that implements the Bitcoin Compat API.

func (*Tx) Hash

func (tx *Tx) Hash() (pack.Bytes, error)

Hash returns the transaction hash of the given underlying transaction.

func (*Tx) Inputs

func (tx *Tx) Inputs() ([]utxo.Input, error)

Inputs returns the UTXO inputs in the underlying transaction.

func (*Tx) Outputs

func (tx *Tx) Outputs() ([]utxo.Output, error)

Outputs returns the UTXO outputs in the underlying transaction.

func (*Tx) Serialize

func (tx *Tx) Serialize() (pack.Bytes, error)

Serialize serializes the UTXO transaction to bytes

func (*Tx) Sighashes

func (tx *Tx) Sighashes() ([]pack.Bytes32, error)

Sighashes returns the digests that must be signed before the transaction can be submitted by the client.

func (*Tx) Sign

func (tx *Tx) Sign(signatures []pack.Bytes65, pubKey pack.Bytes) error

Sign consumes a list of signatures, and adds them to the list of UTXOs in the underlying transactions.

type TxBuilder

type TxBuilder struct {
	// contains filtered or unexported fields
}

The TxBuilder is an implementation of a UTXO-compatible transaction builder for Bitcoin.

func NewTxBuilder

func NewTxBuilder(params *chaincfg.Params) TxBuilder

NewTxBuilder returns a transaction builder that builds UTXO-compatible Bitcoin transactions for the given chain configuration (this means that it can be used for regnet, testnet, and mainnet, but also for networks that are minimally modified forks of the Bitcoin network).

func (TxBuilder) BuildTx

func (txBuilder TxBuilder) BuildTx(inputs []utxo.Input, recipients []utxo.Recipient) (utxo.Tx, error)

BuildTx returns a Bitcoin transaction that consumes funds from the given inputs, and sends them to the given recipients. The difference in the sum value of the inputs and the sum value of the recipients is paid as a fee to the Bitcoin network. This fee must be calculated independently of this function. Outputs produced for recipients will use P2PKH, P2SH, P2WPKH, or P2WSH scripts as the pubkey script, based on the format of the recipient address.

Jump to

Keyboard shortcuts

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