Documentation

Index

Constants

View Source
const (
	// BipID is the BIP-0044 asset ID.
	BipID = 42
)

Variables

View Source
var (

	// WalletInfo defines some general information about a Decred wallet.
	WalletInfo = &asset.WalletInfo{
		Name:              "Decred",
		Units:             "atoms",
		DefaultConfigPath: defaultConfigPath,
		ConfigOpts:        configOpts,
	}
)

Functions

This section is empty.

Types

type Config

type Config struct {
	RPCUser          string  `ini:"username"`
	RPCPass          string  `ini:"password"`
	RPCListen        string  `ini:"rpclisten"`
	RPCCert          string  `ini:"rpccert"`
	UseSplitTx       bool    `ini:"txsplit"`
	FallbackFeeRate  float64 `ini:"fallbackfee"`
	RedeemConfTarget uint64  `ini:"redeemconftarget"`
	// Context should be canceled when the application exits. This will cause
	// some cleanup to be performed during shutdown.
	Context context.Context `ini:"-"`
}

    Config holds the parameters needed to initialize an RPC connection to a dcr wallet. Default values are used for RPCListen and/or RPCCert if not set.

    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 Decred.

        func (*Driver) Info

        func (d *Driver) Info() *asset.WalletInfo

          Info returns basic information about the wallet and asset. WARNING: An ExchangeWallet instance may have different DefaultFeeRate set, so use (*ExchangeWallet).Info when possible.

          func (*Driver) Setup

          func (d *Driver) Setup(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network) (asset.Wallet, error)

            Setup creates the DCR exchange wallet. Start the wallet with its Run method.

            type ExchangeWallet

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

              ExchangeWallet is a wallet backend for Decred. The backend is how the DEX client app communicates with the Decred blockchain and wallet. ExchangeWallet satisfies the dex.Wallet interface.

              func NewWallet

              func NewWallet(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network) (*ExchangeWallet, error)

                NewWallet is the exported constructor by which the DEX will import the exchange wallet. The wallet will shut down when the provided context is canceled.

                func (*ExchangeWallet) Address

                func (dcr *ExchangeWallet) Address() (string, error)

                  Address returns an address for the exchange wallet.

                  func (*ExchangeWallet) AuditContract

                  func (dcr *ExchangeWallet) AuditContract(coinID, contract dex.Bytes) (asset.AuditInfo, error)

                    AuditContract retrieves information about a swap contract on the blockchain. This would be used to verify the counter-party's contract during a swap.

                    func (*ExchangeWallet) Balance

                    func (dcr *ExchangeWallet) Balance() (*asset.Balance, error)

                      Balance should return the total available funds in the wallet. Note that after calling Fund, the amount returned by Balance may change by more than the value funded. Part of the asset.Wallet interface. TODO: Since this includes potentially untrusted 0-conf utxos, consider prioritizing confirmed utxos when funding an order.

                      func (*ExchangeWallet) Confirmations

                      func (dcr *ExchangeWallet) Confirmations(id dex.Bytes) (confs uint32, spent bool, err error)

                        Confirmations gets the number of confirmations for the specified coin ID by first checking for a unspent output, and if not found, searching indexed wallet transactions.

                        func (*ExchangeWallet) Connect

                        func (dcr *ExchangeWallet) Connect(ctx context.Context) (*sync.WaitGroup, error)

                          Connect connects the wallet to the RPC server. Satisfies the dex.Connector interface.

                          func (*ExchangeWallet) FindRedemption

                          func (dcr *ExchangeWallet) FindRedemption(ctx context.Context, coinID dex.Bytes) (redemptionCoin, secret dex.Bytes, err error)

                            FindRedemption watches for the input that spends the specified contract coin, and returns the spending input and the contract's secret key when it finds a spender. If the coin is unmined, an initial search goroutine is started to scan all mempool tx inputs in an attempt to find the input that spends the contract coin. If the contract is mined, the initial search goroutine scans every input of every block starting at the block in which the contract was mined up till the current best block, including mempool txs if redemption info is not found in the searched block txs. More search goroutines are started for every detected tip change, to handle cases where the contract is redeemed in a transaction mined after the current best block. When any of the search goroutines finds an input that spends this contract, the input and the contract's secret key are communicated to this method via a redemption result channel created specifically for this contract. This method waits on that channel before returning a response to the caller.

                            TODO: Improve redemption search in mined blocks by scanning block filters rather than every input of every tx in a block.

                            func (*ExchangeWallet) FundOrder

                            func (dcr *ExchangeWallet) FundOrder(ord *asset.Order) (asset.Coins, []dex.Bytes, error)

                              FundOrder selects coins for use in an order. The coins will be locked, and will not be returned in subsequent calls to FundOrder or calculated in calls to Available, unless they are unlocked with ReturnCoins. The returned []dex.Bytes contains the redeem scripts for the selected coins. Equal number of coins and redeemed scripts must be returned. A nil or empty dex.Bytes should be appended to the redeem scripts collection for coins with no redeem script.

                              func (*ExchangeWallet) FundingCoins

                              func (dcr *ExchangeWallet) FundingCoins(ids []dex.Bytes) (asset.Coins, error)

                                FundingCoins gets funding coins for the coin IDs. The coins are locked. This method might be called to reinitialize an order from data stored externally. This method will only return funding coins, e.g. unspent transaction outputs.

                                func (*ExchangeWallet) Info

                                func (dcr *ExchangeWallet) Info() *asset.WalletInfo

                                  Info returns basic information about the wallet and asset.

                                  func (*ExchangeWallet) Lock

                                  func (dcr *ExchangeWallet) Lock() error

                                    Lock locks the exchange wallet.

                                    func (*ExchangeWallet) Locked

                                    func (dcr *ExchangeWallet) Locked() bool

                                      Locked will be true if the wallet is currently locked.

                                      func (*ExchangeWallet) LocktimeExpired

                                      func (dcr *ExchangeWallet) LocktimeExpired(contract dex.Bytes) (bool, time.Time, error)

                                        LocktimeExpired returns true if the specified contract's locktime has expired, making it possible to issue a Refund.

                                        func (*ExchangeWallet) OwnsAddress

                                        func (dcr *ExchangeWallet) OwnsAddress(address string) (bool, error)

                                          OwnsAddress indicates if an address belongs to the wallet.

                                          func (*ExchangeWallet) PayFee

                                          func (dcr *ExchangeWallet) PayFee(address string, regFee uint64) (asset.Coin, error)

                                            PayFee sends the dex registration fee. Transaction fees are in addition to the registration fee, and the fee rate is taken from the DEX configuration.

                                            func (*ExchangeWallet) Redeem

                                            func (dcr *ExchangeWallet) Redeem(redemptions []*asset.Redemption) ([]dex.Bytes, asset.Coin, uint64, error)

                                              Redeem sends the redemption transaction, which may contain more than one redemption.

                                              func (*ExchangeWallet) Refund

                                              func (dcr *ExchangeWallet) Refund(coinID, contract dex.Bytes) (dex.Bytes, error)

                                                Refund refunds a contract. This can only be used after the time lock has expired. NOTE: The contract cannot be retrieved from the unspent coin info as the wallet does not store it, even though it was known when the init transaction was created. The client should store this information for persistence across sessions.

                                                func (*ExchangeWallet) ReturnCoins

                                                func (dcr *ExchangeWallet) ReturnCoins(unspents asset.Coins) error

                                                  ReturnCoins unlocks coins. This would be necessary in the case of a canceled order.

                                                  func (*ExchangeWallet) SignMessage

                                                  func (dcr *ExchangeWallet) SignMessage(coin asset.Coin, msg dex.Bytes) (pubkeys, sigs []dex.Bytes, err error)

                                                    SignMessage signs the message with the private key associated with the specified funding Coin. A slice of pubkeys required to spend the Coin and a signature for each pubkey are returned.

                                                    func (*ExchangeWallet) Swap

                                                    func (dcr *ExchangeWallet) Swap(swaps *asset.Swaps) ([]asset.Receipt, asset.Coin, uint64, error)

                                                      Swap sends the swaps in a single transaction. The Receipts returned can be used to refund a failed transaction. The Input coins are manually unlocked because they're not auto-unlocked by the wallet and therefore inaccurately included as part of the locked balance despite being spent.

                                                      func (*ExchangeWallet) SyncStatus

                                                      func (dcr *ExchangeWallet) SyncStatus() (bool, float32, error)

                                                        SyncStatus is information about the blockchain sync status.

                                                        func (*ExchangeWallet) Unlock

                                                        func (dcr *ExchangeWallet) Unlock(pw string) error

                                                          Unlock unlocks the exchange wallet.

                                                          func (*ExchangeWallet) ValidateSecret

                                                          func (dcr *ExchangeWallet) ValidateSecret(secret, secretHash []byte) bool

                                                            ValidateSecret checks that the secret satisfies the contract.

                                                            func (*ExchangeWallet) Withdraw

                                                            func (dcr *ExchangeWallet) Withdraw(address string, value uint64) (asset.Coin, error)

                                                              Withdraw withdraws funds to the specified address. Fees are subtracted from the value.

                                                              Source Files