Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type Driver
- type ExchangeWallet
- func (dcr *ExchangeWallet) Address() (string, error)
- func (dcr *ExchangeWallet) AuditContract(coinID, contract, txData dex.Bytes) (*asset.AuditInfo, error)
- func (dcr *ExchangeWallet) Balance() (*asset.Balance, error)
- func (dcr *ExchangeWallet) Confirmations(ctx context.Context, id dex.Bytes) (confs uint32, spent bool, err error)
- func (dcr *ExchangeWallet) Connect(ctx context.Context) (*sync.WaitGroup, error)
- func (dcr *ExchangeWallet) FindRedemption(ctx context.Context, coinID dex.Bytes) (redemptionCoin, secret dex.Bytes, err error)
- func (dcr *ExchangeWallet) FundOrder(ord *asset.Order) (asset.Coins, []dex.Bytes, error)
- func (dcr *ExchangeWallet) FundingCoins(ids []dex.Bytes) (asset.Coins, error)
- func (dcr *ExchangeWallet) Info() *asset.WalletInfo
- func (dcr *ExchangeWallet) Lock() error
- func (dcr *ExchangeWallet) Locked() bool
- func (dcr *ExchangeWallet) LocktimeExpired(contract dex.Bytes) (bool, time.Time, error)
- func (dcr *ExchangeWallet) MaxOrder(lotSize, feeSuggestion uint64, nfo *dex.Asset) (*asset.SwapEstimate, error)
- func (dcr *ExchangeWallet) OwnsAddress(address string) (bool, error)
- func (dcr *ExchangeWallet) PayFee(address string, regFee uint64) (asset.Coin, error)
- func (dcr *ExchangeWallet) PreRedeem(req *asset.PreRedeemForm) (*asset.PreRedeem, error)
- func (dcr *ExchangeWallet) PreSwap(req *asset.PreSwapForm) (*asset.PreSwap, error)
- func (dcr *ExchangeWallet) Redeem(form *asset.RedeemForm) ([]dex.Bytes, asset.Coin, uint64, error)
- func (dcr *ExchangeWallet) Refund(coinID, contract dex.Bytes) (dex.Bytes, error)
- func (dcr *ExchangeWallet) ReturnCoins(unspents asset.Coins) error
- func (dcr *ExchangeWallet) SignMessage(coin asset.Coin, msg dex.Bytes) (pubkeys, sigs []dex.Bytes, err error)
- func (dcr *ExchangeWallet) Swap(swaps *asset.Swaps) ([]asset.Receipt, asset.Coin, uint64, error)
- func (dcr *ExchangeWallet) SyncStatus() (bool, float32, error)
- func (dcr *ExchangeWallet) Unlock(pw string) error
- func (dcr *ExchangeWallet) ValidateSecret(secret, secretHash []byte) bool
- func (dcr *ExchangeWallet) Withdraw(address string, value uint64) (asset.Coin, error)
Constants ¶
const (
// BipID is the BIP-0044 asset ID.
BipID = 42
)
Variables ¶
var ( // WalletInfo defines some general information about a Decred wallet. WalletInfo = &asset.WalletInfo{ Name: "Decred", Units: "atoms", Version: version, 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"` FeeRateLimit float64 `ini:"feeratelimit"` 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 ¶
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.
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, txData 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(ctx context.Context, 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 ¶
Connect connects the wallet to the RPC server. Satisfies the dex.Connector interface. WARNING: Once stopped, it cannot reconnect, requiring NewWallet to construct a new ExchangeWallet to Connect again.
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.
This method blocks until the redemption is found, an error occurs or the provided context is canceled.
func (*ExchangeWallet) FundOrder ¶
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 ¶
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. Q: why are we ignoring RPC errors in this?
func (*ExchangeWallet) LocktimeExpired ¶
LocktimeExpired returns true if the specified contract's locktime has expired, making it possible to issue a Refund.
func (*ExchangeWallet) MaxOrder ¶ added in v0.2.0
func (dcr *ExchangeWallet) MaxOrder(lotSize, feeSuggestion uint64, nfo *dex.Asset) (*asset.SwapEstimate, error)
MaxOrder generates information about the maximum order size and associated fees that the wallet can support for the given DEX configuration. The fees are an estimate based on current network conditions, and will be <= the fees associated with nfo.MaxFeeRate. For quote assets, the caller will have to calculate lotSize based on a rate conversion from the base asset's lot size.
func (*ExchangeWallet) OwnsAddress ¶
func (dcr *ExchangeWallet) OwnsAddress(address string) (bool, error)
OwnsAddress indicates if an address belongs to the wallet.
func (*ExchangeWallet) PayFee ¶
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) PreRedeem ¶ added in v0.2.0
func (dcr *ExchangeWallet) PreRedeem(req *asset.PreRedeemForm) (*asset.PreRedeem, error)
PreRedeem generates an estimate of the range of redemption fees that could be assessed.
func (*ExchangeWallet) PreSwap ¶ added in v0.2.0
func (dcr *ExchangeWallet) PreSwap(req *asset.PreSwapForm) (*asset.PreSwap, error)
PreSwap get order estimates based on the available funds and the wallet configuration.
func (*ExchangeWallet) Redeem ¶
func (dcr *ExchangeWallet) Redeem(form *asset.RedeemForm) ([]dex.Bytes, asset.Coin, uint64, error)
Redeem sends the redemption transaction, which may contain more than one redemption.
func (*ExchangeWallet) Refund ¶
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 ¶
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.