Documentation

Index

Constants

View Source
const ErrReorgDetected = dex.ErrorKind("reorg detected")

Variables

This section is empty.

Functions

func CompatibilityCheck

func CompatibilityCheck(items *CompatibilityItems, chainParams *chaincfg.Params, t *testing.T)

    CompatibilityCheck checks various scripts' compatibility with the Backend. If a fork's CompatibilityItems can pass the CompatibilityCheck, the node can likely use NewBTCClone to create a DEX-compatible backend.

    func LiveFeeRates

    func LiveFeeRates(btc *Backend, t *testing.T, standards map[string]uint64)

      LiveFeeRates scans a mapping of txid -> fee rate checking that the backend returns the expected fee rate.

      func LiveP2SHStats

      func LiveP2SHStats(btc *Backend, t *testing.T)

        LiveP2SHStats will scan the provided Backend's node for inputs that spend pay-to-script-hash outputs. The pubkey scripts and redeem scripts are examined to ensure the backend understands what they are and can extract addresses. Ideally, the stats will show no scripts which were unparseable by the backend, but the presence of unknowns is not an error.

        func LiveUTXOStats

        func LiveUTXOStats(btc *Backend, t *testing.T)

          LiveUTXOStats will scan the provided Backend's node for transaction outputs. The outputs are requested with GetRawTransactionVerbose, and statistics collected regarding spendability and pubkey script types. This test does not request via the Backend.UTXO method and is not meant to cover that code. Instead, these tests check the backend's real-world blockchain literacy. Ideally, the stats will show no scripts which were unparseable by the backend, but the presence of unknowns is not an error.

          func NewBackend

          func NewBackend(configPath string, logger dex.Logger, network dex.Network) (asset.Backend, error)

            NewBackend is the exported constructor by which the DEX will import the backend. The configPath can be an empty string, in which case the standard system location of the bitcoind config file is assumed.

            Types

            type Backend

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

              Backend is a dex backend for Bitcoin or a Bitcoin clone. It has methods for fetching UTXO information and subscribing to block updates. It maintains a cache of block data for quick lookups. Backend implements asset.Backend, so provides exported methods for DEX-related blockchain info.

              func NewBTCClone

              func NewBTCClone(name string, segwit bool, configPath string, logger dex.Logger, network dex.Network,
              	params *chaincfg.Params, ports dexbtc.NetPorts) (*Backend, error)

                NewBTCClone creates a BTC backend for a set of network parameters and default network ports. A BTC clone can use this method, possibly in conjunction with ReadCloneParams, to create a Backend for other assets with minimal coding. See ReadCloneParams and CompatibilityCheck for more info.

                func (*Backend) BlockChannel

                func (btc *Backend) BlockChannel(size int) <-chan *asset.BlockUpdate

                  BlockChannel creates and returns a new channel on which to receive block updates. If the returned channel is ever blocking, there will be no error logged from the btc package. Part of the asset.Backend interface.

                  func (*Backend) CheckAddress

                  func (btc *Backend) CheckAddress(addr string) bool

                    CheckAddress checks that the given address is parseable.

                    func (*Backend) Contract

                    func (btc *Backend) Contract(coinID []byte, redeemScript []byte) (asset.Contract, error)

                      Contract is part of the asset.Backend interface. An asset.Contract is an output that has been validated as a swap contract for the passed redeem script. A spendable output is one that can be spent in the next block. Every output from a non-coinbase transaction is spendable immediately. Coinbase outputs are only spendable after CoinbaseMaturity confirmations. Pubkey scripts can be P2PKH or P2SH. Multi-sig P2SH redeem scripts are supported.

                      func (*Backend) FeeRate

                      func (btc *Backend) FeeRate() (uint64, error)

                        FeeRate returns the current optimal fee rate in sat / byte.

                        func (*Backend) FundingCoin

                        func (btc *Backend) FundingCoin(coinID []byte, redeemScript []byte) (asset.FundingCoin, error)

                          FundingCoin is an unspent output.

                          func (*Backend) InitTxSize

                          func (btc *Backend) InitTxSize() uint32

                            InitTxSize is an asset.Backend method that must produce the max size of a standardized atomic swap initialization transaction.

                            func (*Backend) InitTxSizeBase

                            func (btc *Backend) InitTxSizeBase() uint32

                              InitTxSizeBase is InitTxSize not including an input.

                              func (*Backend) Redemption

                              func (btc *Backend) Redemption(redemptionID, contractID []byte) (asset.Coin, error)

                                Redemption is an input that redeems a swap contract.

                                func (*Backend) Run

                                func (btc *Backend) Run(ctx context.Context)

                                  Run is responsible for best block polling and checking the application context to trigger a clean shutdown.

                                  func (*Backend) Synced

                                  func (btc *Backend) Synced() (bool, error)

                                    Synced is true if the blockchain is ready for action.

                                    func (*Backend) ValidateCoinID

                                    func (btc *Backend) ValidateCoinID(coinID []byte) (string, error)

                                      ValidateCoinID attempts to decode the coinID.

                                      func (*Backend) ValidateContract

                                      func (btc *Backend) ValidateContract(contract []byte) error

                                        ValidateContract ensures that the swap contract is constructed properly, and contains valid sender and receiver addresses.

                                        func (*Backend) ValidateSecret

                                        func (btc *Backend) ValidateSecret(secret, contract []byte) bool

                                          VerifySecret checks that the secret satisfies the contract.

                                          func (*Backend) VerifyUnspentCoin

                                          func (dcr *Backend) VerifyUnspentCoin(coinID []byte) error

                                            VerifyUnspentCoin attempts to verify a coin ID by decoding the coin ID and retrieving the corresponding UTXO. If the coin is not found or no longer unspent, an asset.CoinNotFoundError is returned.

                                            type CompatibilityItems

                                            type CompatibilityItems struct {
                                            	P2PKHScript  []byte
                                            	PKHAddr      string
                                            	P2WPKHScript []byte
                                            	WPKHAddr     string
                                            	P2SHScript   []byte
                                            	SHAddr       string
                                            	P2WSHScript  []byte
                                            	WSHAddr      string
                                            }

                                              CompatibilityItems are a set of pubkey scripts and corresponding string-encoded addresses checked in CompatibilityTest. They should be taken from existing on-chain data.

                                              type Contract

                                              type Contract struct {
                                              	*Output
                                              	// contains filtered or unexported fields
                                              }

                                                Contract is a transaction output containing a swap contract.

                                                func (*Contract) LockTime

                                                func (contract *Contract) LockTime() time.Time

                                                  LockTime is a method on the asset.Contract interface for reading the locktime in the contract script.

                                                  func (*Contract) RedeemScript

                                                  func (contract *Contract) RedeemScript() []byte

                                                    RedeemScript returns the Contract's redeem script.

                                                    func (*Contract) RefundAddress

                                                    func (contract *Contract) RefundAddress() string

                                                      RefundAddress is the refund address of this swap contract.

                                                      func (*Contract) SwapAddress

                                                      func (contract *Contract) SwapAddress() string

                                                        SwapAddress is the receiving address of this swap contract.

                                                        type Driver

                                                        type Driver struct{}

                                                          Driver implements asset.Driver.

                                                          func (*Driver) DecodeCoinID

                                                          func (d *Driver) DecodeCoinID(coinID []byte) (string, error)

                                                            DecodeCoinID creates a human-readable representation of a coin ID for Bitcoin.

                                                            func (*Driver) Setup

                                                            func (d *Driver) Setup(configPath string, logger dex.Logger, network dex.Network) (asset.Backend, error)

                                                              Setup creates the BTC backend. Start the backend with its Run method.

                                                              type Input

                                                              type Input struct {
                                                              	TXIO
                                                              	// contains filtered or unexported fields
                                                              }

                                                                Input is a transaction input.

                                                                func (*Input) Confirmations

                                                                func (input *Input) Confirmations() (int64, error)

                                                                  Confirmations returns the number of confirmations on this input's transaction.

                                                                  func (*Input) ID

                                                                  func (input *Input) ID() []byte

                                                                    ID returns the coin ID.

                                                                    func (*Input) String

                                                                    func (input *Input) String() string

                                                                      String creates a human-readable representation of a Bitcoin transaction input in the format "{txid = [transaction hash], vin = [input index]}".

                                                                      func (*Input) Value

                                                                      func (input *Input) Value() uint64

                                                                        Value is the value of the previous output spent by the input.

                                                                        type Output

                                                                        type Output struct {
                                                                        	TXIO
                                                                        	// contains filtered or unexported fields
                                                                        }

                                                                          Output represents a transaction output.

                                                                          func (*Output) Addresses

                                                                          func (output *Output) Addresses() []string

                                                                          func (*Output) Auth

                                                                          func (output *Output) Auth(pubkeys, sigs [][]byte, msg []byte) error

                                                                            Auth verifies that the output pays to the supplied public key(s). This is an asset.Backend method.

                                                                            func (*Output) Confirmations

                                                                            func (output *Output) Confirmations() (int64, error)

                                                                              Confirmations returns the number of confirmations on this output's transaction.

                                                                              func (*Output) ID

                                                                              func (output *Output) ID() []byte

                                                                                ID returns the coin ID.

                                                                                func (*Output) SpendSize

                                                                                func (output *Output) SpendSize() uint32

                                                                                  SpendSize returns the maximum size of the serialized TxIn that spends this output, in bytes. This is a method of the asset.Output interface.

                                                                                  func (*Output) String

                                                                                  func (output *Output) String() string

                                                                                    String creates a human-readable representation of a Bitcoin transaction output in the format "{txid = [transaction hash], vout = [output index]}".

                                                                                    func (*Output) Value

                                                                                    func (output *Output) Value() uint64

                                                                                      Value is the output value, in satoshis.

                                                                                      type TXIO

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

                                                                                        TXIO is common information stored with an Input or Output.

                                                                                        func (*TXIO) FeeRate

                                                                                        func (txio *TXIO) FeeRate() uint64

                                                                                          FeeRate returns the transaction fee rate, in satoshi/vbyte.

                                                                                          func (*TXIO) TxID

                                                                                          func (txio *TXIO) TxID() string

                                                                                            TxID is a string identifier for the transaction, typically a hexadecimal representation of the byte-reversed transaction hash.

                                                                                            type Tx

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

                                                                                              Tx is information about a transaction. It must satisfy the asset.DEXTx interface to be DEX-compatible.

                                                                                              type UTXO

                                                                                              type UTXO struct {
                                                                                              	*Output
                                                                                              }

                                                                                                A UTXO is information regarding an unspent transaction output.

                                                                                                func (*UTXO) Confirmations

                                                                                                func (utxo *UTXO) Confirmations() (int64, error)

                                                                                                  Confirmations returns the number of confirmations on this output's transaction. See also (*Output).Confirmations. This function differs from the Output method in that it is necessary to relocate the utxo after a reorg, it may error if the output is spent.