Documentation ¶
Index ¶
- Constants
- func ParseBondTx(ver uint16, rawTx []byte) (bondCoinID []byte, amt int64, bondAddr string, bondPubKeyHash []byte, ...)
- func ValidateXPub(xpub string) error
- type Backend
- func (dcr *Backend) BlockChannel(size int) <-chan *asset.BlockUpdate
- func (dcr *Backend) BondCoin(ctx context.Context, ver uint16, coinID []byte) (amt, lockTime, confs int64, acct account.AccountID, err error)
- func (dcr *Backend) BondVer() uint16
- func (dcr *Backend) CheckSwapAddress(addr string) bool
- func (dcr *Backend) Connect(ctx context.Context) (_ *sync.WaitGroup, err error)
- func (dcr *Backend) Contract(coinID []byte, redeemScript []byte) (*asset.Contract, error)
- func (dcr *Backend) FeeCoin(coinID []byte) (addr string, val uint64, confs int64, err error)
- func (dcr *Backend) FeeRate(ctx context.Context) (uint64, error)
- func (dcr *Backend) FundingCoin(ctx context.Context, coinID []byte, redeemScript []byte) (asset.FundingCoin, error)
- func (*Backend) Info() *asset.BackendInfo
- func (*Backend) ParseBondTx(ver uint16, rawTx []byte) (bondCoinID []byte, amt int64, bondAddr string, bondPubKeyHash []byte, ...)
- func (dcr *Backend) Redemption(redemptionID, contractID, _ []byte) (asset.Coin, error)
- func (dcr *Backend) SendRawTransaction(rawtx []byte) (coinID []byte, err error)
- func (dcr *Backend) Synced() (bool, error)
- func (dcr *Backend) TxData(coinID []byte) ([]byte, error)
- func (dcr *Backend) ValidateCoinID(coinID []byte) (string, error)
- func (dcr *Backend) ValidateContract(contract []byte) error
- func (dcr *Backend) ValidateFeeRate(c asset.Coin, reqFeeRate uint64) bool
- func (*Backend) ValidateOrderFunding(swapVal, valSum, _, inputsSize, maxSwaps uint64, nfo *dex.Asset) bool
- func (dcr *Backend) ValidateSecret(secret, contract []byte) bool
- func (dcr *Backend) VerifyUnspentCoin(ctx context.Context, coinID []byte) error
- type Driver
- func (d *Driver) DecodeCoinID(coinID []byte) (string, error)
- func (d *Driver) MinBondSize(maxFeeRate uint64) uint64
- func (d *Driver) MinLotSize(maxFeeRate uint64) uint64
- func (d *Driver) Name() string
- func (d *Driver) Setup(cfg *asset.BackendConfig) (asset.Backend, error)
- func (d *Driver) UnitInfo() dex.UnitInfo
- func (d *Driver) Version() uint32
- type Input
- type Output
- func (output *Output) Addresses() []string
- func (output *Output) Auth(pubkeys, sigs [][]byte, msg []byte) error
- func (output *Output) Confirmations(ctx 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 TXIO
- type Tx
- type UTXO
Constants ¶
const ( BipID = 42 BondVersion = 0 )
const ErrReorgDetected = dex.ErrorKind("reorg detected")
Variables ¶
This section is empty.
Functions ¶
func ParseBondTx ¶ added in v0.6.0
func ParseBondTx(ver uint16, rawTx []byte) (bondCoinID []byte, amt int64, bondAddr string, bondPubKeyHash []byte, lockTime int64, acct account.AccountID, err error)
ParseBondTx performs basic validation of a serialized time-locked fidelity bond transaction given the bond's P2SH redeem script.
The transaction must have at least two outputs: out 0 pays to a P2SH address (the bond), and out 1 is a nulldata output that commits to an account ID. There may also be a change output.
Returned: The bond's coin ID (i.e. encoded UTXO) of the bond output. The bond output's amount and P2SH address. The lockTime and pubkey hash data pushes from the script. The account ID from the second output is also returned.
Properly formed transactions:
- The bond output (vout 0) must be a P2SH output.
- The bond's redeem script must be of the form: <lockTime[4]> OP_CHECKLOCKTIMEVERIFY OP_DROP OP_DUP OP_HASH160 <pubkeyhash[20]> OP_EQUALVERIFY OP_CHECKSIG
- The null data output (vout 1) must have a 58-byte data push (ver | account ID | lockTime | pubkeyHash).
- The transaction must have a zero locktime and expiry.
- All inputs must have the max sequence num set (finalized).
- The transaction must pass the checks in the blockchain.CheckTransactionSanity function.
For DCR, and possibly all assets, the bond script is reconstructed from the null data output, and it is verified that the bond output pays to this script.
func ValidateXPub ¶ added in v0.6.0
ValidateXPub validates the base-58 encoded extended key, and ensures that it is an extended public, not private, key.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend is an asset backend for Decred. It has methods for fetching output 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 NewBackend ¶
func NewBackend(cfg *asset.BackendConfig) (*Backend, error)
NewBackend is the exported constructor by which the DEX will import the Backend. If configPath is an empty string, the backend will attempt to read the settings directly from the dcrd config file in its default system location.
func (*Backend) BlockChannel ¶
func (dcr *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 dcr package. Part of the asset.Backend interface.
func (*Backend) BondCoin ¶ added in v0.6.0
func (dcr *Backend) BondCoin(ctx context.Context, ver uint16, coinID []byte) (amt, lockTime, confs int64, acct account.AccountID, err error)
BondCoin locates a bond transaction output, validates the entire transaction, and returns the amount, encoded lockTime and account ID, and the confirmations of the transaction. It is a CoinNotFoundError if the transaction output is spent.
func (*Backend) CheckSwapAddress ¶ added in v0.6.0
CheckSwapAddress checks that the given address is parseable and of the required type for a swap contract script (p2pkh).
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 regular-tree output from a non-coinbase transaction is spendable immediately. Coinbase and stake tree outputs are only spendable after CoinbaseMaturity confirmations. Pubkey scripts can be P2PKH or P2SH in either regular- or stake-tree flavor. P2PKH supports two alternative signatures, Schnorr and Edwards. Multi-sig P2SH redeem scripts are supported as well.
func (*Backend) FeeCoin ¶
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 non-stake P2PKH requiring a single ECDSA-secp256k1 signature.
func (*Backend) FundingCoin ¶
func (dcr *Backend) FundingCoin(ctx context.Context, coinID []byte, redeemScript []byte) (asset.FundingCoin, error)
FundingCoin is an unspent output.
func (*Backend) Info ¶ added in v0.5.0
func (*Backend) Info() *asset.BackendInfo
Info provides some general information about the backend.
func (*Backend) ParseBondTx ¶ added in v0.6.0
func (*Backend) ParseBondTx(ver uint16, rawTx []byte) (bondCoinID []byte, amt int64, bondAddr string, bondPubKeyHash []byte, lockTime int64, acct account.AccountID, err error)
ParseBondTx makes the package-level ParseBondTx pure function accessible via a Backend instance. This performs basic validation of a serialized time-locked fidelity bond transaction given the bond's P2SH redeem script.
func (*Backend) Redemption ¶
Redemption is an input that redeems a swap contract.
func (*Backend) SendRawTransaction ¶ added in v0.6.0
SendRawTransaction broadcasts a raw transaction, returning a coin ID.
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) ValidateFeeRate ¶ added in v0.5.0
ValidateFeeRate checks that the transaction fees used to initiate the contract are sufficient.
func (*Backend) ValidateOrderFunding ¶ added in v1.0.0
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 Driver ¶
type Driver struct{}
Driver implements asset.Driver.
func (*Driver) DecodeCoinID ¶
DecodeCoinID creates a human-readable representation of a coin ID for Decred.
func (*Driver) MinBondSize ¶ added in v1.0.0
MinBondSize calculates the minimum bond size for a given fee rate that avoids dust outputs on the bond and refund txs, assuming the maxFeeRate doesn't change.
func (*Driver) MinLotSize ¶ added in v1.0.0
MinLotSize calculates the minimum bond size for a given fee rate that avoids dust outputs on the swap and refund txs, assuming the maxFeeRate doesn't change.
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.FundingCoin method.
func (*Output) Confirmations ¶
Confirmations returns the number of confirmations for a transaction output. Because it is possible for an output that was once considered valid to later be considered invalid, this method can return an error to indicate the output is no longer valid. The definition of output validity should not be confused with the validity of regular tree transactions that is voted on by stakeholders. While stakeholder approval is a part of output validity, there are other considerations as well.
func (*Output) SpendSize ¶
SpendSize returns the maximum size of the serialized TxIn that spends this Output, in bytes.
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.