bitcoincompat

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2020 License: GPL-3.0 Imports: 15 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"
)

Variables

This section is empty.

Functions

func GatewayPubKeyScript

func GatewayPubKeyScript(gpubkey pack.Bytes, ghash pack.Bytes32) ([]byte, error)

GatewayPubKeyScript returns the pubkey script of a Bitcoin gateway script. This is the pubkey script that is expected to be in the underlying transaction output for lock-and-mint cross-chain transactions (when working with BTC).

func GatewayScript

func GatewayScript(gpubkey pack.Bytes, ghash pack.Bytes32) ([]byte, error)

GatewayScript returns the Bitcoin gateway script that is used to when submitting lock-and-mint cross-chain transactions (when working with BTC).

Types

type Address

type Address btcutil.Address

An Address is a public address that can be encoded/decoded to/from strings. Addresses are usually formatted different between different network configurations.

type AddressDecoder

type AddressDecoder interface {
	DecodeAddress(pack.String) (Address, error)
}

The AddressDecoder defines an interface for decoding string representations of Bitcoin address into the Address interface.

type AddressDecoderCallbacks

type AddressDecoderCallbacks struct {
	DecodeAddressCallback func(pack.String) (Address, error)
}

AddressDecoderCallbacks implements the AddressDecoder interface by allowing users to define closures for all required methods.

func (AddressDecoderCallbacks) DecodeAddress

func (cbs AddressDecoderCallbacks) DecodeAddress(encoded pack.String) (Address, error)

DecodeAddress delegates the method to an inner callback. If not callback exists, then an error is returned.

type Client

type Client interface {
	// Output associated with an outpoint, and its number of confirmations.
	Output(ctx context.Context, outpoint Outpoint) (Output, int64, error)
	// UnspentOutputs spendable by the given address.
	UnspentOutputs(ctx context.Context, minConf, maxConf int64, address Address) ([]Output, error)
	// Confirmations of a transaction in the Bitcoin network.
	Confirmations(ctx context.Context, txHash pack.Bytes32) (int64, error)
	// SubmitTx to the Bitcoin network.
	SubmitTx(ctx context.Context, tx Tx) (pack.Bytes32, 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 interface {
	GasPerByte(ctx context.Context) (pack.U64, error)
}

A GasEstimator returns the gas-per-byte that is needed in order to confirm transactions with relatively high speed. In distributed networks that work to collectively build transactions, it is important that all nodes return the same values from this interface.

func NewGasEstimator

func NewGasEstimator(satsPerByte pack.U64) GasEstimator

NewGasEstimator returns a simple gas estimator that always returns the same amount of gas-per-byte.

type Input

type Input struct {
	Outpoint  Outpoint   `json:"outpoint"`
	SigScript pack.Bytes `json:"sigScript"`
}

An Input to a Bitcoin transaction. It consumes an outpoint, and contains a signature script that satisfies the pubkey script of the output that it is consuming.

https://developer.bitcoin.org/reference/transactions.html#txin-a-transaction-input-non-coinbase

type Outpoint

type Outpoint struct {
	Hash  pack.Bytes32 `json:"hash"`
	Index pack.U32     `json:"index"`
}

An Outpoint is a transaction outpoint, identifying a specific part of a transaction output.

https://developer.bitcoin.org/reference/transactions.html#outpoint-the-specific-part-of-a-specific-output

type Output

type Output struct {
	Outpoint     Outpoint   `json:"outpoint"`
	Value        pack.U64   `json:"value"`
	PubKeyScript pack.Bytes `json:"pubKeyScript"`
}

An Output of a Bitcoin transaction. It contains a pubkey script that defines the conditions required to spend the output.

https://developer.bitcoin.org/reference/transactions.html#txout-a-transaction-output

type Recipient

type Recipient struct {
	Address Address  `json:"address"`
	Value   pack.U64 `json:"value"`
}

A Recipient of funds from a Bitcoin transaction. This is useful for buidling simple pay-to-address Bitcoin transactions.

type Tx

type Tx interface {
	// Hash of the transaction.
	Hash() pack.Bytes32

	// Sighashes that need to be signed before this transaction can be
	// submitted.
	Sighashes() ([]pack.Bytes32, error)

	// Sign the transaction by injecting signatures and the serialized pubkey of
	// the signer.
	Sign([]pack.Bytes65, pack.Bytes) error

	// Serialize the transaction.
	Serialize() (pack.Bytes, error)
}

Tx defines an interface that must be implemented by all types of Bitcoin transactions.

type TxBuilder

type TxBuilder interface {
	// BuildTx returns a simple Bitcoin transaction that consumes a set of
	// Bitcoin outputs and uses the funds to make payments to a set of Bitcoin
	// recipients. The sum value of the inputs must be greater than the sum
	// value of the outputs, and the difference is paid as a fee to the Bitcoin
	// network.
	BuildTx(inputs []Output, recipients []Recipient) (Tx, error)
}

TxBuilder defines an interface that can be used to build simple Bitcoin transactions.

Jump to

Keyboard shortcuts

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