bitcoin

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2020 License: GPL-3.0 Imports: 23 Imported by: 7

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 added in v0.2.0

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

func NewAddressDecoder

func NewAddressDecoder(params *chaincfg.Params) AddressDecoder

func (AddressDecoder) DecodeAddress added in v0.2.0

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

type AddressEncodeDecoder added in v0.2.1

type AddressEncodeDecoder struct {
	AddressEncoder
	AddressDecoder
}

func NewAddressEncodeDecoder added in v0.2.1

func NewAddressEncodeDecoder(params *chaincfg.Params) AddressEncodeDecoder

type AddressEncoder added in v0.2.0

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

func NewAddressEncoder added in v0.2.0

func NewAddressEncoder(params *chaincfg.Params) AddressEncoder

func (AddressEncoder) EncodeAddress added in v0.2.0

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

type Client added in v0.2.0

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)
}

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

func NewClient added in v0.2.0

func NewClient(opts ClientOptions) Client

NewClient returns a new Client.

type ClientOptions added in v0.2.0

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 added in v0.2.0

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 added in v0.2.0

func (opts ClientOptions) WithHost(host string) ClientOptions

WithHost sets the URL of the Bitcoin node.

func (ClientOptions) WithPassword added in v0.2.0

func (opts ClientOptions) WithPassword(password string) ClientOptions

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

func (ClientOptions) WithUser added in v0.2.0

func (opts ClientOptions) WithUser(user string) ClientOptions

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

type GasEstimator added in v0.2.0

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 added in v0.2.0

func NewGasEstimator(satsPerByte pack.U256) GasEstimator

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

func (GasEstimator) GasPrice added in v0.2.0

func (gasEstimator GasEstimator) GasPrice(_ context.Context) (pack.U256, error)

GasPrice returns the number of SATs-per-byte that is needed in order to confirm transactions with an estimated maximum delay of one block. It is the responsibility of the caller to know the number of bytes in their transaction.

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)

func (*Tx) Inputs added in v0.2.0

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

func (*Tx) Outputs added in v0.2.0

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

func (*Tx) Serialize

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

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. All transactions assume that the f

func (*Tx) Sign

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

type TxBuilder added in v0.2.0

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 added in v0.2.0

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