Documentation ¶
Index ¶
- Constants
- func CompatibilityCheck(items *CompatibilityItems, chainParams *chaincfg.Params, t *testing.T)
- func LiveFeeRates(btc *Backend, t *testing.T, standards map[string]uint64)
- func LiveP2SHStats(btc *Backend, t *testing.T, numToDo int)
- func LiveUTXOStats(btc *Backend, t *testing.T)
- func NewBackend(configPath string, logger dex.Logger, network dex.Network) (asset.Backend, error)
- type AddressDeriver
- type Backend
- func (btc *Backend) BlockChannel(size int) <-chan *asset.BlockUpdate
- func (btc *Backend) CheckAddress(addr string) bool
- func (btc *Backend) Connect(ctx context.Context) (*sync.WaitGroup, error)
- func (btc *Backend) Contract(coinID []byte, redeemScript []byte) (*asset.Contract, error)
- func (btc *Backend) FeeCoin(coinID []byte) (addr string, val uint64, confs int64, err error)
- func (btc *Backend) FeeRate(_ context.Context) (uint64, error)
- func (btc *Backend) FundingCoin(_ context.Context, coinID []byte, redeemScript []byte) (asset.FundingCoin, error)
- func (btc *Backend) InitTxSize() uint32
- func (btc *Backend) InitTxSizeBase() uint32
- func (btc *Backend) Net() *chaincfg.Params
- func (btc *Backend) Redemption(redemptionID, contractID []byte) (asset.Coin, error)
- func (btc *Backend) Synced() (bool, error)
- func (btc *Backend) TxData(coinID []byte) ([]byte, error)
- func (btc *Backend) ValidateCoinID(coinID []byte) (string, error)
- func (btc *Backend) ValidateContract(contract []byte) error
- func (btc *Backend) ValidateSecret(secret, contract []byte) bool
- func (btc *Backend) VerifyUnspentCoin(_ context.Context, coinID []byte) error
- type BackendCloneConfig
- type CompatibilityItems
- type Driver
- func (d *Driver) DecodeCoinID(coinID []byte) (string, error)
- func (d *Driver) NewAddresser(xPub string, keyIndexer asset.KeyIndexer, network dex.Network) (asset.Addresser, uint32, error)
- func (d *Driver) Setup(configPath string, logger dex.Logger, network dex.Network) (asset.Backend, error)
- func (d *Driver) UnitInfo() dex.UnitInfo
- func (d *Driver) Version() uint32
- type GetBlockchainInfoResult
- type Input
- type Output
- func (output *Output) Addresses() []string
- func (output *Output) Auth(pubkeys, sigs [][]byte, msg []byte) error
- func (output *Output) Confirmations(context.Context) (int64, error)
- func (output *Output) ID() []byte
- func (output *Output) SpendSize() uint32
- func (output *Output) String() string
- func (output *Output) Value() uint64
- type RPCClient
- func (rc *RPCClient) EstimateSmartFee(confTarget int64, mode *btcjson.EstimateSmartFeeMode) (*btcjson.EstimateSmartFeeResult, error)
- func (rc *RPCClient) GetBestBlockHash() (*chainhash.Hash, error)
- func (rc *RPCClient) GetBlockChainInfo() (*GetBlockchainInfoResult, error)
- func (rc *RPCClient) GetBlockVerbose(blockHash *chainhash.Hash) (*btcjson.GetBlockVerboseResult, error)
- func (rc *RPCClient) GetRawTransaction(txHash *chainhash.Hash) (*btcutil.Tx, error)
- func (rc *RPCClient) GetRawTransactionVerbose(txHash *chainhash.Hash) (*btcjson.TxRawResult, error)
- func (rc *RPCClient) GetTxOut(txHash *chainhash.Hash, index uint32, mempool bool) (*btcjson.GetTxOutResult, error)
- func (rc *RPCClient) RawRequest(method string, params []json.RawMessage) (json.RawMessage, error)
- type RawRequester
- type TXIO
- type Tx
- type UTXO
Constants ¶
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 ¶
LiveFeeRates scans a mapping of txid -> fee rate checking that the backend returns the expected fee rate.
func LiveP2SHStats ¶
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 ¶
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 ¶
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 AddressDeriver ¶ added in v0.4.0
type AddressDeriver struct {
// contains filtered or unexported fields
}
AddressDeriver generates unique addresses from an extended public key.
func NewAddressDeriver ¶ added in v0.4.0
func NewAddressDeriver(xpub string, keyIndexer asset.KeyIndexer, chainParams *chaincfg.Params) (*AddressDeriver, uint32, error)
NewAddressDeriver creates a new AddressDeriver for the provided extended public key, KeyIndexer, and network parameters. Note that if the source wallet has accounts (e.g. BIP44), the extended key should be for an account. Since AddressDeriver returns P2WPKH addresses, the extended public key should be for a P2WPKH derivation path (e.g. zpub for mainnet, and vpub for regnet and testnet). However, if a key for a different address encoding is provided that is otherwise valid for the specified network, the error message will suggest the equivalent extended key for P2WPKH addresses, but the operator must be certain they can redeem payments to P2WPKH addresses. This is done instead of returning different encodings depending on the extended key format to prevent accidental reuse of keys.
Refs: https://github.com/bitcoin/bips/blob/master/bip-0084.mediawiki#extended-key-version https://github.com/satoshilabs/slips/blob/master/slip-0132.md
See TestAddressDeriver to double check your own keys and the first addresses.
func (*AddressDeriver) NextAddress ¶ added in v0.4.0
func (ap *AddressDeriver) NextAddress() (string, error)
NextAddress retrieves the p2wpkh address for the next pubkey. While this should always return a valid address, an empty string may be returned in the event of an unexpected internal error.
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(cloneCfg *BackendCloneConfig) (*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 ¶
CheckAddress checks that the given address is parseable.
func (*Backend) Contract ¶
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) FeeCoin ¶ added in v0.4.0
FeeCoin gets the recipient address, value, and confirmations of a transaction output encoded by the given coinID. A non-nil error is returned if the output's pubkey script is not a P2WPKH requiring a single ECDSA-secp256k1 signature.
func (*Backend) FundingCoin ¶
func (btc *Backend) FundingCoin(_ context.Context, coinID []byte, redeemScript []byte) (asset.FundingCoin, error)
FundingCoin is an unspent output.
func (*Backend) InitTxSize ¶
InitTxSize is an asset.Backend method that must produce the max size of a standardized atomic swap initialization transaction.
func (*Backend) InitTxSizeBase ¶
InitTxSizeBase is InitTxSize not including an input.
func (*Backend) Net ¶ added in v0.2.0
Net returns the *chaincfg.Params. This is not part of the asset.Backend interface, and is exported as a convenience for embedding types.
func (*Backend) Redemption ¶
Redemption is an input that redeems a swap contract.
func (*Backend) TxData ¶ added in v0.2.0
TxData is the raw transaction bytes. SPV clients rebroadcast the transaction bytes to get around not having a mempool to check.
func (*Backend) ValidateCoinID ¶
ValidateCoinID attempts to decode the coinID.
func (*Backend) ValidateContract ¶
ValidateContract ensures that the swap contract is constructed properly, and contains valid sender and receiver addresses.
func (*Backend) ValidateSecret ¶
ValidateSecret checks that the secret satisfies the contract.
func (*Backend) VerifyUnspentCoin ¶
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 BackendCloneConfig ¶ added in v0.2.0
type BackendCloneConfig struct { Name string Segwit bool ConfigPath string AddressDecoder dexbtc.AddressDecoder Logger dex.Logger Net dex.Network ChainParams *chaincfg.Params Ports dexbtc.NetPorts // FeeEstimator provides a way to get fees given an RawRequest-enabled // client and a confirmation target. FeeEstimator func(*RPCClient) (uint64, error) }
BackendCloneConfig captures the arguments necessary to configure a BTC clone backend.
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 Driver ¶
type Driver struct{}
Driver implements asset.Driver.
func (*Driver) DecodeCoinID ¶
DecodeCoinID creates a human-readable representation of a coin ID for Bitcoin.
func (*Driver) NewAddresser ¶ added in v0.4.0
func (d *Driver) NewAddresser(xPub string, keyIndexer asset.KeyIndexer, network dex.Network) (asset.Addresser, uint32, error)
NewAddresser creates an asset.Addresser for deriving addresses for the given extended public key. The KeyIndexer will be used for discovering the current child index, and storing the index as new addresses are generated with the NextAddress method of the Addresser.
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 GetBlockchainInfoResult ¶ added in v0.4.0
type GetBlockchainInfoResult struct { Blocks int64 `json:"blocks"` Headers int64 `json:"headers"` BestBlockHash string `json:"bestblockhash"` InitialBlockDownload bool `json:"initialblockdownload"` }
GetBlockchainInfoResult models the data returned from the getblockchaininfo command.
type Input ¶
type Input struct { TXIO // contains filtered or unexported fields }
Input is a transaction input.
func (*Input) Confirmations ¶
Confirmations returns the number of confirmations on this input's transaction.
type Output ¶
type Output struct { TXIO // contains filtered or unexported fields }
Output represents a transaction output.
func (*Output) Auth ¶
Auth verifies that the output pays to the supplied public key(s). This is an asset.Backend method.
func (*Output) Confirmations ¶
Confirmations returns the number of confirmations on this output's transaction.
func (*Output) SpendSize ¶
SpendSize returns the maximum size of the serialized TxIn that spends this output, in bytes. This is a method of the asset.Output interface.
type RPCClient ¶ added in v0.4.0
type RPCClient struct {
// contains filtered or unexported fields
}
RPCClient is a bitcoind wallet RPC client that uses rpcclient.Client's RawRequest for wallet-related calls.
func (*RPCClient) EstimateSmartFee ¶ added in v0.4.0
func (rc *RPCClient) EstimateSmartFee(confTarget int64, mode *btcjson.EstimateSmartFeeMode) (*btcjson.EstimateSmartFeeResult, error)
EstimateSmartFee requests the server to estimate a fee level.
func (*RPCClient) GetBestBlockHash ¶ added in v0.4.0
GetBestBlockHash returns the hash of the best block in the longest block chain.
func (*RPCClient) GetBlockChainInfo ¶ added in v0.4.0
func (rc *RPCClient) GetBlockChainInfo() (*GetBlockchainInfoResult, error)
GetBlockChainInfo returns information related to the processing state of various chain-specific details.
func (*RPCClient) GetBlockVerbose ¶ added in v0.4.0
func (rc *RPCClient) GetBlockVerbose(blockHash *chainhash.Hash) (*btcjson.GetBlockVerboseResult, error)
GetBlockVerbose fetches verbose block data for the specified hash.
func (*RPCClient) GetRawTransaction ¶ added in v0.4.0
GetRawTransaction retrieves tx's information.
func (*RPCClient) GetRawTransactionVerbose ¶ added in v0.4.0
GetRawTransactionVerbose retrieves the verbose tx information.
func (*RPCClient) GetTxOut ¶ added in v0.4.0
func (rc *RPCClient) GetTxOut(txHash *chainhash.Hash, index uint32, mempool bool) (*btcjson.GetTxOutResult, error)
GetTxOut returns the transaction output info if it's unspent and nil, otherwise.
func (*RPCClient) RawRequest ¶ added in v0.4.0
func (rc *RPCClient) RawRequest(method string, params []json.RawMessage) (json.RawMessage, error)
RawRequest is a wrapper func for callers that are not context-enabled.
type RawRequester ¶ added in v0.4.0
type RawRequester interface { RawRequest(context.Context, string, []json.RawMessage) (json.RawMessage, error) Shutdown() WaitForShutdown() }
RawRequester is for sending context-aware RPC requests, and has methods for shutting down the underlying connection. The returned error should be of type dcrjson.RPCError if non-nil.
type TXIO ¶
type TXIO struct {
// contains filtered or unexported fields
}
TXIO is common information stored with an Input or Output.
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 ¶
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.