Documentation ¶
Index ¶
- Constants
- Variables
- func RegisterCustomWallet(constructor WalletConstructor, def *asset.WalletDefinition) error
- type AddressInfo
- type BlockHeader
- type Driver
- func (d *Driver) Create(params *asset.CreateWalletParams) error
- func (d *Driver) DecodeCoinID(coinID []byte) (string, error)
- func (d *Driver) Exists(walletType, dataDir string, _ map[string]string, net dex.Network) (bool, error)
- func (d *Driver) Info() *asset.WalletInfo
- func (d *Driver) Open(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network) (asset.Wallet, error)
- type ExchangeWallet
- func (dcr *ExchangeWallet) AuditContract(coinID, contract, txData dex.Bytes, rebroadcast bool) (*asset.AuditInfo, error)
- func (dcr *ExchangeWallet) Balance() (*asset.Balance, error)
- func (dcr *ExchangeWallet) BondsFeeBuffer(feeRate uint64) uint64
- func (dcr *ExchangeWallet) Connect(ctx context.Context) (*sync.WaitGroup, error)
- func (dcr *ExchangeWallet) ContractLockTimeExpired(ctx context.Context, contract dex.Bytes) (bool, time.Time, error)
- func (dcr *ExchangeWallet) DepositAddress() (string, error)
- func (dcr *ExchangeWallet) EstimateRegistrationTxFee(feeRate uint64) uint64
- func (dcr *ExchangeWallet) EstimateSendTxFee(address string, sendAmount, feeRate uint64, subtract bool) (fee uint64, isValidAddress bool, err error)
- func (dcr *ExchangeWallet) FeeRate() uint64
- 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) LockTimeExpired(ctx context.Context, lockTime time.Time) (bool, error)
- func (dcr *ExchangeWallet) Locked() bool
- func (dcr *ExchangeWallet) MakeBondTx(ver uint16, amt, feeRate uint64, lockTime time.Time, ...) (*asset.Bond, func(), error)
- func (dcr *ExchangeWallet) MaxOrder(ord *asset.MaxOrderForm) (*asset.SwapEstimate, error)
- func (dcr *ExchangeWallet) NewAddress() (string, error)
- func (dcr *ExchangeWallet) OwnsDepositAddress(address string) (bool, error)
- func (dcr *ExchangeWallet) PreRedeem(req *asset.PreRedeemForm) (*asset.PreRedeem, error)
- func (dcr *ExchangeWallet) PreSwap(req *asset.PreSwapForm) (*asset.PreSwap, error)
- func (dcr *ExchangeWallet) Reconfigure(ctx context.Context, cfg *asset.WalletConfig, currentAddress string) (restart bool, err error)
- func (dcr *ExchangeWallet) Redeem(form *asset.RedeemForm) ([]dex.Bytes, asset.Coin, uint64, error)
- func (dcr *ExchangeWallet) RedemptionAddress() (string, error)
- func (dcr *ExchangeWallet) Refund(coinID, contract dex.Bytes, feeRate uint64) (dex.Bytes, error)
- func (dcr *ExchangeWallet) RefundBond(ctx context.Context, ver uint16, coinID, script []byte, amt uint64, ...) (asset.Coin, error)
- func (dcr *ExchangeWallet) RegFeeConfirmations(ctx context.Context, coinID dex.Bytes) (confs uint32, err error)
- func (dcr *ExchangeWallet) RegisterUnspent(inBonds uint64)
- func (dcr *ExchangeWallet) ReserveBondFunds(future int64, feeBuffer uint64, respectBalance bool) bool
- func (dcr *ExchangeWallet) ReturnCoins(unspents asset.Coins) error
- func (dcr *ExchangeWallet) Send(address string, value, feeRate uint64) (asset.Coin, error)
- func (dcr *ExchangeWallet) SendTransaction(rawTx []byte) ([]byte, error)
- func (dcr *ExchangeWallet) SignMessage(coin asset.Coin, msg dex.Bytes) (pubkeys, sigs []dex.Bytes, err error)
- func (dcr *ExchangeWallet) SingleLotRedeemFees(req *asset.PreRedeemForm) (uint64, error)
- func (dcr *ExchangeWallet) SingleLotSwapFees(form *asset.PreSwapForm) (fees uint64, err error)
- func (dcr *ExchangeWallet) Swap(swaps *asset.Swaps) ([]asset.Receipt, asset.Coin, uint64, error)
- func (dcr *ExchangeWallet) SwapConfirmations(ctx context.Context, coinID, contract dex.Bytes, matchTime time.Time) (confs uint32, spent bool, err error)
- func (dcr *ExchangeWallet) SyncStatus() (bool, float32, error)
- func (dcr *ExchangeWallet) Unlock(pw []byte) error
- func (dcr *ExchangeWallet) ValidateAddress(address string) bool
- func (dcr *ExchangeWallet) ValidateSecret(secret, secretHash []byte) bool
- func (dcr *ExchangeWallet) Withdraw(address string, value, feeRate uint64) (asset.Coin, error)
- type FeeRateEstimator
- type Mempooler
- type RecoveryCfg
- type TipChangeCallback
- type TxOutput
- type Wallet
- type WalletConstructor
- type WalletTransaction
Constants ¶
const (
// BipID is the BIP-0044 asset ID.
BipID = 42
)
Variables ¶
var ( // ContractSearchLimit is how far back in time AuditContract in SPV mode // will search for a contract if no txData is provided. This should be a // positive duration. ContractSearchLimit = 48 * time.Hour // WalletInfo defines some general information about a Decred wallet. WalletInfo = &asset.WalletInfo{ Name: "Decred", Version: version, SupportedVersions: []uint32{version}, UnitInfo: dexdcr.UnitInfo, AvailableWallets: []*asset.WalletDefinition{ { Type: walletTypeSPV, Tab: "Native", Description: "Use the built-in SPV wallet", ConfigOpts: append(spvOpts, walletOpts...), Seeded: true, }, { Type: walletTypeDcrwRPC, Tab: "External", Description: "Connect to dcrwallet", DefaultConfigPath: defaultConfigPath, ConfigOpts: append(rpcOpts, walletOpts...), }, }, } )
Functions ¶
func RegisterCustomWallet ¶ added in v0.4.0
func RegisterCustomWallet(constructor WalletConstructor, def *asset.WalletDefinition) error
RegisterCustomWallet registers a function that should be used in creating a Wallet implementation that the ExchangeWallet of the specified type will use in place of the default rpcWallet implementation. External consumers can use this function to provide alternative Wallet implementations, and must do so before attempting to create an ExchangeWallet instance of this type.
Types ¶
type AddressInfo ¶ added in v0.5.0
AddressInfo is the source account and branch info for an address.
type BlockHeader ¶ added in v0.5.0
type BlockHeader struct { *wire.BlockHeader MedianTime int64 Confirmations int64 NextHash *chainhash.Hash }
BlockHeader is a wire.BlockHeader with the addition of a MedianTime field. Implementations must fill in the MedianTime field when returning a BlockHeader.
type Driver ¶
type Driver struct{}
Driver implements asset.Driver.
func (*Driver) Create ¶ added in v0.5.0
func (d *Driver) Create(params *asset.CreateWalletParams) error
Create creates a new SPV wallet.
func (*Driver) DecodeCoinID ¶
DecodeCoinID creates a human-readable representation of a coin ID for Decred.
func (*Driver) Exists ¶ added in v0.5.0
func (d *Driver) Exists(walletType, dataDir string, _ map[string]string, net dex.Network) (bool, error)
Exists checks the existence of the wallet. Part of the Creator interface.
func (*Driver) Info ¶
func (d *Driver) Info() *asset.WalletInfo
Info returns basic information about the wallet and asset.
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.
func (*ExchangeWallet) AuditContract ¶
func (dcr *ExchangeWallet) AuditContract(coinID, contract, txData dex.Bytes, rebroadcast bool) (*asset.AuditInfo, error)
AuditContract retrieves information about a swap contract from the provided txData if it represents a valid transaction that pays to the contract at the specified coinID. The txData may be empty to attempt retrieval of the transaction output from the network, but it is only ensured to succeed for a full node or, if the tx is confirmed, an SPV wallet. Normally the server should communicate this txData, and the caller can decide to require it. The ability to work with an empty txData is a convenience for recovery tools and testing, and it may change in the future if a GetTxData method is added for this purpose. Optionally, attempt is also made to broadcasted the txData to the blockchain network but it is not necessary that the broadcast succeeds since the contract may have already been broadcasted.
func (*ExchangeWallet) Balance ¶
func (dcr *ExchangeWallet) Balance() (*asset.Balance, error)
Balance should return the total available funds in the wallet.
func (*ExchangeWallet) BondsFeeBuffer ¶ added in v0.6.0
func (dcr *ExchangeWallet) BondsFeeBuffer(feeRate uint64) uint64
BondsFeeBuffer suggests how much extra may be required for the transaction fees part of required bond reserves when bond rotation is enabled.
func (*ExchangeWallet) Connect ¶
Connect connects the wallet to the RPC server. Satisfies the dex.Connector interface.
func (*ExchangeWallet) ContractLockTimeExpired ¶ added in v0.6.0
func (dcr *ExchangeWallet) ContractLockTimeExpired(ctx context.Context, contract dex.Bytes) (bool, time.Time, error)
ContractLockTimeExpired returns true if the specified contract's locktime has expired, making it possible to issue a Refund.
func (*ExchangeWallet) DepositAddress ¶ added in v0.5.0
func (dcr *ExchangeWallet) DepositAddress() (string, error)
DepositAddress returns an address for depositing funds into the exchange wallet.
func (*ExchangeWallet) EstimateRegistrationTxFee ¶ added in v0.4.3
func (dcr *ExchangeWallet) EstimateRegistrationTxFee(feeRate uint64) uint64
EstimateRegistrationTxFee returns an estimate for the tx fee needed to pay the registration fee using the provided feeRate.
func (*ExchangeWallet) EstimateSendTxFee ¶ added in v0.6.0
func (dcr *ExchangeWallet) EstimateSendTxFee(address string, sendAmount, feeRate uint64, subtract bool) (fee uint64, isValidAddress bool, err error)
EstimateSendTxFee returns a tx fee estimate for sending or withdrawing the provided amount using the provided feeRate.
func (*ExchangeWallet) FeeRate ¶ added in v0.4.3
func (dcr *ExchangeWallet) FeeRate() uint64
FeeRate satisfies asset.FeeRater.
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) LockTimeExpired ¶ added in v0.6.0
LockTimeExpired returns true if the specified locktime has expired, making it possible to redeem the locked coins.
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) MakeBondTx ¶ added in v0.6.0
func (dcr *ExchangeWallet) MakeBondTx(ver uint16, amt, feeRate uint64, lockTime time.Time, bondKey *secp256k1.PrivateKey, acctID []byte) (*asset.Bond, func(), error)
MakeBondTx creates a time-locked fidelity bond transaction. The V0 transaction has two required outputs:
Output 0 is a the time-locked bond output of type P2SH with the provided value. The redeem script looks similar to the refund path of an atomic swap script, but with a pubkey hash:
<locktime> OP_CHECKLOCKTIMEVERIFY OP_DROP OP_DUP OP_HASH160 <pubkeyhash[20]> OP_EQUALVERIFY OP_CHECKSIG
The pubkey referenced by the script is provided by the caller.
Output 1 is a DEX Account commitment. This is an OP_RETURN output that references the provided account ID.
OP_RETURN <2-byte version> <32-byte account ID> <4-byte locktime> <20-byte pubkey hash>
Having the account ID in the raw allows the txn alone to identify the account without the bond output's redeem script.
Output 2 is change, if any.
The bond output's redeem script, which is needed to spend the bond output, is returned as the Data field of the Bond. The bond output pays to a pubkeyhash script for a wallet address. Bond.RedeemTx is a backup transaction that spends the bond output after lockTime passes, paying to an address for the current underlying wallet; the bond private key should normally be used to author a new transaction paying to a new address instead.
func (*ExchangeWallet) MaxOrder ¶ added in v0.2.0
func (dcr *ExchangeWallet) MaxOrder(ord *asset.MaxOrderForm) (*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 provided FeeSuggestion is used directly, and should be an estimate based on current network conditions. For quote assets, the caller will have to calculate lotSize based on a rate conversion from the base asset's lot size. lotSize must not be zero and will cause a panic if so.
func (*ExchangeWallet) NewAddress ¶ added in v0.4.1
func (dcr *ExchangeWallet) NewAddress() (string, error)
NewAddress returns a new address from the wallet. This satisfies the NewAddresser interface.
func (*ExchangeWallet) OwnsDepositAddress ¶ added in v0.5.0
func (dcr *ExchangeWallet) OwnsDepositAddress(address string) (bool, error)
OwnsDepositAddress indicates if the provided address can be used to deposit funds into the wallet.
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) Reconfigure ¶ added in v0.5.3
func (dcr *ExchangeWallet) Reconfigure(ctx context.Context, cfg *asset.WalletConfig, currentAddress string) (restart bool, err error)
Reconfigure attempts to reconfigure the wallet.
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. FeeSuggestion is just a fallback if an internal estimate using the wallet's redeem confirm block target setting is not available.
func (*ExchangeWallet) RedemptionAddress ¶ added in v0.5.0
func (dcr *ExchangeWallet) RedemptionAddress() (string, error)
RedemptionAddress gets an address for use in redeeming the counterparty's swap. This would be included in their swap initialization.
func (*ExchangeWallet) Refund ¶
Refund refunds a contract. This can only be used after the time lock has expired. This MUST return an asset.CoinNotFoundError error if the coin is spent. If the provided fee rate is zero, an internal estimate will be used, otherwise it will be used directly, but this behavior may change. 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) RefundBond ¶ added in v0.6.0
func (dcr *ExchangeWallet) RefundBond(ctx context.Context, ver uint16, coinID, script []byte, amt uint64, privKey *secp256k1.PrivateKey) (asset.Coin, error)
RefundBond refunds a bond output to a new wallet address given the redeem script and private key. After broadcasting, the output paying to the wallet is returned.
func (*ExchangeWallet) RegFeeConfirmations ¶ added in v0.4.0
func (dcr *ExchangeWallet) RegFeeConfirmations(ctx context.Context, coinID dex.Bytes) (confs uint32, err error)
RegFeeConfirmations gets the number of confirmations for the specified output.
func (*ExchangeWallet) RegisterUnspent ¶ added in v0.6.0
func (dcr *ExchangeWallet) RegisterUnspent(inBonds uint64)
RegisterUnspent should be called once for every configured DEX with existing unspent bond amounts, prior to login, which is when reserves for future bonds are then added given the actual account tier, target tier, and this combined existing bonds amount. This must be used before ReserveBondFunds, which begins reserves enforcement provided a future amount that may be required before the existing bonds are refunded. No reserves enforcement is enabled until ReserveBondFunds is called, even with a future value of 0. A wallet that is not enforcing reserves, but which has unspent bonds should use this method to facilitate switching to the wallet for bonds in future.
func (*ExchangeWallet) ReserveBondFunds ¶ added in v0.6.0
func (dcr *ExchangeWallet) ReserveBondFunds(future int64, feeBuffer uint64, respectBalance bool) bool
ReserveBondFunds increases the bond reserves to accommodate a certain nominal amount of future bonds, or reduces the amount if a negative value is provided. If indicated, updating the reserves will require sufficient available balance, otherwise reserves will be adjusted regardless and the funds are pre-reserved. This returns false if the available balance was insufficient iff the caller requested it be respected, otherwise it always returns true (success).
The reserves enabled with this method are enforced when funding transactions (e.g. regular withdraws/sends or funding orders), and deducted from available balance. Amounts may be reserved beyond the available balance, but only the amount that is offset by the available balance is reflected in the locked balance category. Like funds locked in swap contracts, the caller must supplement balance reporting with known bond amounts. However, via RegisterUnspent, the wallet is made aware of pre-existing unspent bond amounts (cumulative) that will eventually be spent with RefundBond.
If this wallet is enforcing reserves (this method has been called, even with a future value of zero), when new bonds are created the nominal bond amount is deducted from the enforced reserves; when bonds are spent with RefundBond, the nominal bond amount is added back into the enforced reserves. That is, when there are no active bonds, the locked balance category will reflect the entire amount requested with ReserveBondFunds (plus a fee buffer, see below), and when bonds are created with MakeBondTx, the locked amount decreases since that portion of the reserves are now held in inaccessible UTXOs, the amounts of which the caller tracks independently. When spent with RefundBond, that same *nominal* bond value is added back to the enforced reserves amount.
The amounts requested for bond reserves should be the nominal amounts of the bonds, but the reserved amount reflected in the locked balance category will include a considerable buffer for transaction fees. Therefore when the full amount of the reserves are presently locked in unspent bonds, the locked balance will include this fee buffer while the wallet is enforcing reserves.
Until this method is called, reserves enforcement is disabled, and any unspent bonds registered with RegisterUnspent do not go into the enforced reserves when spent. In this way, all Bonder wallets remain aware of the total nominal value of unspent bonds even if the wallet is not presently being used to maintain a target bonding amount that necessitates reserves enforcement.
A negative value may be provided to reduce allocated reserves. When the amount is reduced by the same amount it was previously increased by both ReserveBondFunds and RegisterUnspent, reserves enforcement including fee padding is disabled. Consider the following example: on startup, 20 DCR of existing unspent bonds are registered via RegisterUnspent, then on login and auth with the relevant DEX host, 40 DCR of future bond reserves are requested with ReserveBondFunds to maintain a configured target tier given the current tier and amounts of the existing unspent bonds. To disable reserves, the client would call ReserveBondFunds with -60 DCR, which the wallet's internal accounting recognizes as complete removal of the reserves.
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. Coins belonging to the tradingAcct, if configured, are transferred to the unmixed account with the exception of unspent split tx outputs which are kept in the tradingAcct and may later be used to fund future orders. If called with a nil slice, all coins are returned and none are moved to the unmixed account.
func (*ExchangeWallet) Send ¶ added in v0.5.0
Send sends the exact value to the specified address. This is different from Withdraw, which subtracts the tx fees from the amount sent. feeRate is in units of atoms/byte.
func (*ExchangeWallet) SendTransaction ¶ added in v0.6.0
func (dcr *ExchangeWallet) SendTransaction(rawTx []byte) ([]byte, error)
SendTransaction broadcasts a valid fully-signed transaction.
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) SingleLotRedeemFees ¶ added in v0.6.0
func (dcr *ExchangeWallet) SingleLotRedeemFees(req *asset.PreRedeemForm) (uint64, error)
SingleLotRedeemFees is a fallback for PreRedeem that uses estimation when funds aren't available. The returned fees are the RealisticWorstCase.
func (*ExchangeWallet) SingleLotSwapFees ¶ added in v0.6.0
func (dcr *ExchangeWallet) SingleLotSwapFees(form *asset.PreSwapForm) (fees uint64, err error)
SingleLotSwapFees is a fallback for PreSwap that uses estimation when funds aren't available. The returned fees are the RealisticWorstCase. The Lots field of the PreSwapForm is ignored and assumed to be a single lot.
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) SwapConfirmations ¶ added in v0.4.0
func (dcr *ExchangeWallet) SwapConfirmations(ctx context.Context, coinID, contract dex.Bytes, matchTime time.Time) (confs uint32, spent bool, err error)
SwapConfirmations gets the number of confirmations and the spend status for the specified swap. The contract and matchTime are provided so that wallets may search for the coin using light filters.
For a non-SPV wallet, if the swap appears spent but it cannot be located in a block with a cfilters scan, this will return asset.CoinNotFoundError. For SPV wallets, it is not an error if the transaction cannot be located SPV wallets cannot see non-wallet transactions until they are mined.
If the coin is located, but recognized as spent, no error is returned.
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 []byte) error
Unlock unlocks the exchange wallet.
func (*ExchangeWallet) ValidateAddress ¶ added in v0.6.0
func (dcr *ExchangeWallet) ValidateAddress(address string) bool
ValidateAddress checks that the provided address is valid.
func (*ExchangeWallet) ValidateSecret ¶
func (dcr *ExchangeWallet) ValidateSecret(secret, secretHash []byte) bool
ValidateSecret checks that the secret satisfies the contract.
type FeeRateEstimator ¶ added in v0.5.0
type FeeRateEstimator interface { // EstimateSmartFeeRate returns a smart feerate estimate. EstimateSmartFeeRate(ctx context.Context, confTarget int64, mode chainjson.EstimateSmartFeeMode) (float64, error) }
FeeRateEstimator is satisfied by a Wallet that can provide fee rate estimates.
type Mempooler ¶ added in v0.5.0
type Mempooler interface { // GetRawMempool returns hashes for all txs in a node's mempool. GetRawMempool(ctx context.Context) ([]*chainhash.Hash, error) }
Mempooler is satisfied by a Wallet that can provide mempool info.
type RecoveryCfg ¶ added in v0.5.0
type RecoveryCfg struct { NumExternalAddresses uint32 `ini:"numexternaladdr"` NumInternalAddresses uint32 `ini:"numinternaladdr"` }
RecoveryCfg is the information that is transferred from the old wallet to the new one when the wallet is recovered.
type TipChangeCallback ¶ added in v0.4.0
type TxOutput ¶ added in v0.4.0
TxOutput defines properties of a transaction output, including the details of the block containing the tx, if mined.
type Wallet ¶ added in v0.4.0
type Wallet interface { // Connect establishes a connection to the wallet. Connect(ctx context.Context) error // Disconnect shuts down access to the wallet. Disconnect() // SpvMode returns true if the wallet is connected to the Decred // network via SPV peers. SpvMode() bool // NotifyOnTipChange registers a callback function that the should be // invoked when the wallet sees new mainchain blocks. The return value // indicates if this notification can be provided. Where this tip change // notification is unimplemented, monitorBlocks should be used to track // tip changes. NotifyOnTipChange(ctx context.Context, cb TipChangeCallback) bool // AddressInfo returns information for the provided address. It is an error // if the address is not owned by the wallet. AddressInfo(ctx context.Context, address string) (*AddressInfo, error) // AccountOwnsAddress checks if the provided address belongs to the // specified account. AccountOwnsAddress(ctx context.Context, addr stdaddr.Address, acctName string) (bool, error) // AccountBalance returns the balance breakdown for the specified account. AccountBalance(ctx context.Context, confirms int32, acctName string) (*walletjson.GetAccountBalanceResult, error) // LockedOutputs fetches locked outputs for the Wallet. LockedOutputs(ctx context.Context, acctName string) ([]chainjson.TransactionInput, error) // Unspents fetches unspent outputs for the Wallet. Unspents(ctx context.Context, acctName string) ([]*walletjson.ListUnspentResult, error) // LockUnspent locks or unlocks the specified outpoint. LockUnspent(ctx context.Context, unlock bool, ops []*wire.OutPoint) error // UnspentOutput returns information about an unspent tx output, if found // and unspent. Use wire.TxTreeUnknown if the output tree is unknown, the // correct tree will be returned if the unspent output is found. // This method is only guaranteed to return results for outputs that pay to // the wallet, although wallets connected to a full node may return results // for non-wallet outputs. Returns asset.CoinNotFoundError if the unspent // output cannot be located. UnspentOutput(ctx context.Context, txHash *chainhash.Hash, index uint32, tree int8) (*TxOutput, error) // ExternalAddress returns a new external address. ExternalAddress(ctx context.Context, acctName string) (stdaddr.Address, error) // InternalAddress returns a change address from the Wallet. InternalAddress(ctx context.Context, acctName string) (stdaddr.Address, error) // SignRawTransaction signs the provided transaction. SignRawTransaction // is not used for redemptions, so previous outpoints and scripts should // be known by the wallet. // SignRawTransaction should not mutate the input transaction. SignRawTransaction(context.Context, *wire.MsgTx) (*wire.MsgTx, error) // SendRawTransaction broadcasts the provided transaction to the Decred // network. SendRawTransaction(ctx context.Context, tx *wire.MsgTx, allowHighFees bool) (*chainhash.Hash, error) // GetBlockHeader generates a *BlockHeader for the specified block hash. The // returned block header is a wire.BlockHeader with the addition of the // block's median time. GetBlockHeader(ctx context.Context, blockHash *chainhash.Hash) (*BlockHeader, error) // GetBlock returns the *wire.MsgBlock. GetBlock(ctx context.Context, blockHash *chainhash.Hash) (*wire.MsgBlock, error) // GetTransaction returns the details of a wallet tx, if the wallet contains a // tx with the provided hash. Returns asset.CoinNotFoundError if the tx is not // found in the wallet. GetTransaction(ctx context.Context, txHash *chainhash.Hash) (*WalletTransaction, error) // GetRawTransaction returns details of the tx with the provided hash. // Returns asset.CoinNotFoundError if the tx is not found. GetRawTransaction(ctx context.Context, txHash *chainhash.Hash) (*wire.MsgTx, error) // GetBestBlock returns the hash and height of the wallet's best block. GetBestBlock(ctx context.Context) (*chainhash.Hash, int64, error) // GetBlockHash returns the hash of the mainchain block at the specified height. GetBlockHash(ctx context.Context, blockHeight int64) (*chainhash.Hash, error) // MatchAnyScript looks for any of the provided scripts in the block specified. MatchAnyScript(ctx context.Context, blockHash *chainhash.Hash, scripts [][]byte) (bool, error) // AccountUnlocked returns true if the account is unlocked. AccountUnlocked(ctx context.Context, acctName string) (bool, error) // LockAccount locks the account. LockAccount(ctx context.Context, acctName string) error // UnlockAccount unlocks the account. UnlockAccount(ctx context.Context, passphrase []byte, acctName string) error // SyncStatus returns the wallet's sync status. SyncStatus(ctx context.Context) (bool, float32, error) // PeerCount returns the number of network peers to which the wallet or its // backing node are connected. PeerCount(ctx context.Context) (uint32, error) // AddressPrivKey fetches the privkey for the specified address. AddressPrivKey(ctx context.Context, address stdaddr.Address) (*secp256k1.PrivateKey, error) Reconfigure(ctx context.Context, cfg *asset.WalletConfig, net dex.Network, currentAddress, depositAccount string) (restart bool, err error) }
Wallet defines methods that the ExchangeWallet uses for communicating with a Decred wallet and blockchain.
type WalletConstructor ¶ added in v0.4.0
type WalletConstructor func(settings map[string]string, chainParams *chaincfg.Params, logger dex.Logger) (Wallet, error)
WalletConstructor defines a function that can be invoked to create a custom implementation of the Wallet interface.
type WalletTransaction ¶ added in v0.5.0
type WalletTransaction struct { Confirmations int64 BlockHash string Details []walletjson.GetTransactionDetailsResult Hex string }
WalletTransaction is a pared down version of walletjson.GetTransactionResult.