Documentation ¶
Index ¶
- Constants
- func DecodeCoinID(name string, coinID []byte) (string, error)
- func Register(name string, driver Driver)
- func UnitInfo(name string) (dex.UnitInfo, error)
- func Version(name string) (uint32, error)
- type Addresser
- type AddresserFactory
- type BackedAsset
- type Backend
- type BlockUpdate
- type Coin
- type ConnectionError
- type Contract
- type Driver
- type FundingCoin
- type KeyIndexer
Constants ¶
const ( CoinNotFoundError = dex.ErrorKind("coin not found") ErrRequestTimeout = dex.ErrorKind("request timeout") )
CoinNotFoundError is to be returned from Contract, Redemption, and FundingCoin when the specified transaction cannot be found. Used by the server to handle network latency.
Variables ¶
This section is empty.
Functions ¶
func DecodeCoinID ¶
DecodeCoinID creates a human-readable representation of a coin ID for a named asset with a corresponding driver registered with this package.
Types ¶
type Addresser ¶ added in v0.4.0
Addresser retrieves unique addresses.
func NewAddresser ¶ added in v0.4.0
func NewAddresser(name string, acctXPub string, keyIndexer KeyIndexer, network dex.Network) (Addresser, uint32, error)
NewAddresser creates an Addresser for a named asset for deriving addresses for the given extended public key on a certain network while maintaining the address index in an external HDKeyIndex.
type AddresserFactory ¶ added in v0.4.0
type AddresserFactory interface {
NewAddresser(acctXPub string, keyIndexer KeyIndexer, network dex.Network) (Addresser, uint32, error)
}
AddresserFactory describes a type that can construct new Addressers.
type BackedAsset ¶
BackedAsset is a dex.Asset with a Backend.
type Backend ¶
type Backend interface { // It is expected that Connect from dex.Connector is called and returns // before use of the asset, and that it is only called once for the life // of the asset. dex.Connector // Contract returns a Contract only for outputs that would be spendable on // the blockchain immediately. The redeem script is required in order to // calculate sigScript length and verify pubkeys. Contract(coinID []byte, redeemScript []byte) (*Contract, error) // TxData fetches the raw transaction data for the specified coin. TxData(coinID []byte) ([]byte, error) // ValidateSecret checks that the secret satisfies the contract. ValidateSecret(secret, contract []byte) bool // Redemption returns a Coin for redemptionID, a transaction input, that // spends contract ID, an output containing the swap contract. Redemption(redemptionID, contractID []byte) (Coin, error) // FundingCoin returns the unspent coin at the specified location. Coins // with non-standard pkScripts or scripts that require zero signatures to // redeem must return an error. FundingCoin(ctx context.Context, coinID []byte, redeemScript []byte) (FundingCoin, error) // BlockChannel creates and returns a new channel on which to receive updates // when new blocks are connected. BlockChannel(size int) <-chan *BlockUpdate // InitTxSize is the size of a serialized atomic swap initialization // transaction with 1 input spending a P2PKH utxo, 1 swap contract output and // 1 change output. InitTxSize() uint32 // InitTxSizeBase is InitTxSize not including an input. InitTxSizeBase() uint32 // CheckAddress checks that the given address is parseable. CheckAddress(string) bool // ValidateCoinID checks the coinID to ensure it can be decoded, returning a // human-readable string if it is valid. ValidateCoinID(coinID []byte) (string, error) // ValidateContract ensures that the swap contract is constructed properly // for the asset. ValidateContract(contract []byte) error // VerifyUnspentCoin attempts to verify a coin ID by decoding the coin ID // and retrieving the corresponding Coin. If the coin is not found or no // longer unspent, an asset.CoinNotFoundError is returned. Use FundingCoin // for more UTXO data. VerifyUnspentCoin(ctx context.Context, coinID []byte) error // FeeRate returns the current optimal fee rate in atoms / byte. FeeRate(context.Context) (uint64, error) // Synced should return true when the blockchain is synced and ready for // fee rate estimation. Synced() (bool, error) }
Backend is a blockchain backend. TODO: Plumb every method with a cancellable request with a Context, which will prevent backend shutdown from cancelling requests, but is more idiomatic these days.
type BlockUpdate ¶
BlockUpdate is sent over the update channel when a tip change is detected.
type Coin ¶
type Coin interface { // Confirmations returns the number of confirmations for a Coin's // transaction. Because a Coin can become invalid after once being // considered valid, this condition should be checked for during // confirmation counting and an error returned if this Coin is no longer // ready to spend. An unmined transaction should have zero confirmations. A // transaction in the current best block should have one confirmation. A // negative number can be returned if error is not nil. Confirmations(context.Context) (int64, error) // ID is the coin ID. ID() []byte // TxID is a transaction identifier for the coin. TxID() string // String is a human readable representation of the Coin. String() string // Value is the coin value. Value() uint64 // FeeRate returns the transaction fee rate, in atoms/byte equivalent. FeeRate() uint64 }
Coin represents a transaction input or output.
type ConnectionError ¶
type ConnectionError error
ConnectionError error should be sent over the block update channel if a connection error is detected by the Backend.
func NewConnectionError ¶
func NewConnectionError(s string, a ...interface{}) ConnectionError
NewConnectionError is a constructor for a ConnectionError.
type Contract ¶
type Contract struct { Coin // SwapAddress is the receiving address of the swap contract. SwapAddress string // RedeemScript is the contract redeem script. RedeemScript []byte // SecretHash is the secret key hash used for this swap. This should be used // to validate a counterparty contract on another chain. SecretHash []byte // LockTime is the refund locktime. LockTime time.Time // TxData is raw transaction data. This data is provided for some assets // to aid in SPV compatibility. TxData []byte }
Contract is an atomic swap contract.
type Driver ¶
type Driver interface { // Setup should create a Backend, but not start the backend connection. Setup(configPath string, logger dex.Logger, network dex.Network) (Backend, error) DecodeCoinID(coinID []byte) (string, error) // Version returns the Backend's version number, which is used to signal // when major changes are made to internal details such as coin ID encoding // and contract structure that must be common to a client's. Version() uint32 // UnitInfo returns the dex.UnitInfo for the asset. UnitInfo() dex.UnitInfo }
Driver is the interface required of all assets. A Driver may or may not also be an AddresserFactory.
type FundingCoin ¶
type FundingCoin interface { Coin // Auth checks that the owner of the provided pubkeys can spend the // FundingCoin. The signatures (sigs) generated with the private keys // corresponding to pubkeys must validate against the pubkeys and signing // message (msg). Auth(pubkeys, sigs [][]byte, msg []byte) error // SpendSize returns the size of the serialized input that spends this // FundingCoin. SpendSize() uint32 }
FundingCoin is some unspent value on the blockchain.