Documentation ¶
Index ¶
- Constants
- Variables
- func NewWallet(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network) (asset.Wallet, error)
- func RegisterCustomWallet(constructor WalletConstructor, def *asset.WalletDefinition)
- 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) MinLotSize(maxFeeRate uint64) uint64
- 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) ConfirmRedemption(coinID dex.Bytes, redemption *asset.Redemption, feeSuggestion uint64) (*asset.ConfirmRedemptionStatus, error)
- 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) EstimateSendTxFee(address string, sendAmount, feeRate uint64, subtract, _ bool) (fee uint64, isValidAddress bool, err error)
- func (dcr *ExchangeWallet) FeeRate() uint64
- func (dcr *ExchangeWallet) FindBond(ctx context.Context, coinID []byte, searchUntil time.Time) (bond *asset.BondDetails, err error)
- func (dcr *ExchangeWallet) FindRedemption(ctx context.Context, coinID, _ dex.Bytes) (redemptionCoin, secret dex.Bytes, err error)
- func (dcr *ExchangeWallet) FundMultiOrder(mo *asset.MultiOrder, maxLock uint64) (coins []asset.Coins, redeemScripts [][]dex.Bytes, fundingFees uint64, ...)
- func (dcr *ExchangeWallet) FundOrder(ord *asset.Order) (asset.Coins, []dex.Bytes, uint64, error)
- func (dcr *ExchangeWallet) FundingCoins(ids []dex.Bytes) (asset.Coins, error)
- func (dcr *ExchangeWallet) Info() *asset.WalletInfo
- func (dcr *ExchangeWallet) ListVSPs() ([]*asset.VotingServiceProvider, error)
- 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) MaxFundingFees(numTrades uint32, feeRate uint64, options map[string]string) uint64
- 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) PurchaseTickets(n int, feeSuggestion uint64) 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) RedeemGeocode(code []byte, msg string) (dex.Bytes, 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) 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) SetBondReserves(reserves uint64)
- func (dcr *ExchangeWallet) SetVSP(url string) error
- func (dcr *ExchangeWallet) SetVotingPreferences(choices map[string]string, tspendPolicy map[string]string, ...) error
- func (dcr *ExchangeWallet) SignMessage(coin asset.Coin, msg dex.Bytes) (pubkeys, sigs []dex.Bytes, err error)
- func (dcr *ExchangeWallet) SingleLotRedeemFees(_ uint32, feeSuggestion uint64) (uint64, error)
- func (dcr *ExchangeWallet) SingleLotSwapRefundFees(_ uint32, feeSuggestion uint64, useSafeTxSize bool) (swapFees uint64, refundFees uint64, err error)
- func (dcr *ExchangeWallet) StakeStatus() (*asset.TicketStakingStatus, error)
- func (dcr *ExchangeWallet) StandardSendFee(feeRate uint64) uint64
- 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() (ss *asset.SyncStatus, err error)
- func (dcr *ExchangeWallet) TicketPage(scanStart int32, n, skipN int) ([]*asset.Ticket, error)
- func (dcr *ExchangeWallet) TxHistory(n int, refID *string, past bool) ([]*asset.WalletTransaction, 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) WalletTransaction(ctx context.Context, txID string) (*asset.WalletTransaction, error)
- func (dcr *ExchangeWallet) Withdraw(address string, value, feeRate uint64) (asset.Coin, error)
- type FeeRateEstimator
- type ListTransactionsResult
- type Mempooler
- type NativeWallet
- func (w *NativeWallet) ConfigureFundsMixer(enabled bool) (err error)
- func (w *NativeWallet) Connect(ctx context.Context) (*sync.WaitGroup, error)
- func (w *NativeWallet) FundsMixingStats() (*asset.FundsMixingStats, error)
- func (w *NativeWallet) Lock() (err error)
- func (w *NativeWallet) Rescan(ctx context.Context, bday uint64) (err error)
- type RecoveryCfg
- type TicketPurchaseUpdate
- type TipChangeCallback
- type TxOutput
- type Wallet
- type WalletConstructor
- type WalletTransaction
- type XCWalletAccounts
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", SupportedVersions: []uint32{version}, UnitInfo: dexdcr.UnitInfo, AvailableWallets: []*asset.WalletDefinition{ { Type: walletTypeSPV, Tab: "Native", Description: "Use the built-in SPV wallet", ConfigOpts: walletOpts, Seeded: true, MultiFundingOpts: multiFundingOpts, }, { Type: walletTypeDcrwRPC, Tab: "External", Description: "Connect to dcrwallet", DefaultConfigPath: defaultConfigPath, ConfigOpts: append(rpcOpts, walletOpts...), MultiFundingOpts: multiFundingOpts, }, }, } )
Functions ¶
func NewWallet ¶
func NewWallet(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network) (asset.Wallet, error)
NewWallet is the exported constructor by which the DEX will import the exchange wallet.
func RegisterCustomWallet ¶ added in v0.4.0
func RegisterCustomWallet(constructor WalletConstructor, def *asset.WalletDefinition)
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. It'll panic if callers try to register a wallet twice.
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.
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 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 (*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) ConfirmRedemption ¶ added in v1.0.0
func (dcr *ExchangeWallet) ConfirmRedemption(coinID dex.Bytes, redemption *asset.Redemption, feeSuggestion uint64) (*asset.ConfirmRedemptionStatus, error)
ConfirmRedemption returns how many confirmations a redemption has. Normally this is very straightforward. However there are two situations that have come up that this also handles. One is when the wallet can not find the redemption transaction. This is most likely because the fee was set too low and the tx was removed from the mempool. In the case where it is not found, this will send a new tx using the provided fee suggestion. The second situation this watches for is a transaction that we can find but has been sitting in the mempool for a long time. This has been observed with the wallet in SPV mode and the transaction inputs having been spent by another transaction. The wallet will not pick up on this so we could tell it to abandon the original transaction and, again, send a new one using the provided feeSuggestion, but only warning for now. This method should not be run for the same redemption concurrently as it need to watch a new redeem transaction before finishing.
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) 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) FindBond ¶ added in v1.0.0
func (dcr *ExchangeWallet) FindBond(ctx context.Context, coinID []byte, searchUntil time.Time) (bond *asset.BondDetails, err error)
FindBond finds the bond with coinID and returns the values used to create it.
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) FundMultiOrder ¶ added in v1.0.0
func (dcr *ExchangeWallet) FundMultiOrder(mo *asset.MultiOrder, maxLock uint64) (coins []asset.Coins, redeemScripts [][]dex.Bytes, fundingFees uint64, err error)
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) ListVSPs ¶ added in v1.0.0
func (dcr *ExchangeWallet) ListVSPs() ([]*asset.VotingServiceProvider, error)
ListVSPs lists known available voting service providers.
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) MaxFundingFees ¶ added in v1.0.0
func (dcr *ExchangeWallet) MaxFundingFees(numTrades uint32, feeRate uint64, options map[string]string) uint64
MaxFundingFees returns the maximum funding fees for an order/multi-order.
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) PurchaseTickets ¶ added in v1.0.0
func (dcr *ExchangeWallet) PurchaseTickets(n int, feeSuggestion uint64) error
PurchaseTickets purchases n number of tickets. Part of the asset.TicketBuyer interface.
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) RedeemGeocode ¶ added in v1.0.0
RedeemGeocode redeems funds from a geocode game tx to this wallet.
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) 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) SetBondReserves ¶ added in v1.0.0
func (dcr *ExchangeWallet) SetBondReserves(reserves uint64)
func (*ExchangeWallet) SetVSP ¶ added in v1.0.0
func (dcr *ExchangeWallet) SetVSP(url string) error
SetVSP sets the VSP provider. Ability to set can be checked with StakeStatus first. Only non-RPC (internal) wallets can be set. Part of the asset.TicketBuyer interface.
func (*ExchangeWallet) SetVotingPreferences ¶ added in v1.0.0
func (dcr *ExchangeWallet) SetVotingPreferences(choices map[string]string, tspendPolicy map[string]string, treasuryPolicy map[string]string) error
SetVotingPreferences sets the vote choices for all active tickets and future tickets. Nil maps can be provided for no change. Part of the asset.TicketBuyer interface.
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(_ uint32, feeSuggestion uint64) (uint64, error)
SingleLotRedeemFees returns the fees for a redeem transaction for a single lot.
func (*ExchangeWallet) SingleLotSwapRefundFees ¶ added in v1.0.0
func (dcr *ExchangeWallet) SingleLotSwapRefundFees(_ uint32, feeSuggestion uint64, useSafeTxSize bool) (swapFees uint64, refundFees uint64, err error)
SingleLotSwapRefundFees returns the fees for a swap and refund transaction for a single lot.
func (*ExchangeWallet) StakeStatus ¶ added in v1.0.0
func (dcr *ExchangeWallet) StakeStatus() (*asset.TicketStakingStatus, error)
func (*ExchangeWallet) StandardSendFee ¶ added in v1.0.0
func (dcr *ExchangeWallet) StandardSendFee(feeRate uint64) uint64
StandardSendFees returns the fees for a simple send tx with one input and two outputs.
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() (ss *asset.SyncStatus, err error)
SyncStatus is information about the blockchain sync status.
func (*ExchangeWallet) TicketPage ¶ added in v1.0.0
TicketPage fetches a page of tickets within a range of block numbers with a target page size and optional offset. scanStart is the block in which to start the scan. The scan progresses in reverse block number order, starting at scanStart and going to progressively lower blocks. scanStart can be set to -1 to indicate the current chain tip.
func (*ExchangeWallet) TxHistory ¶ added in v1.0.0
func (dcr *ExchangeWallet) TxHistory(n int, refID *string, past bool) ([]*asset.WalletTransaction, error)
TxHistory returns all the transactions the wallet has made. If refID is nil, then transactions starting from the most recent are returned (past is ignored). If past is true, the transactions prior to the refID are returned, otherwise the transactions after the refID are returned. n is the number of transactions to return. If n is <= 0, all the transactions will be returned.
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.
func (*ExchangeWallet) WalletTransaction ¶ added in v1.0.0
func (dcr *ExchangeWallet) WalletTransaction(ctx context.Context, txID string) (*asset.WalletTransaction, error)
WalletTransaction returns a transaction that either the wallet has made or one in which the wallet has received funds. The txID should be either a coin ID or a transaction hash in hexadecimal form.
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 ListTransactionsResult ¶ added in v1.0.0
type ListTransactionsResult struct { TxID string BlockIndex *int64 BlockTime int64 // Send set to true means that the inputs of the transaction were // controlled by the wallet. Send bool `json:"send"` Fee *float64 TxType *walletjson.ListTransactionsTxType }
ListTransactionsResult is similar to the walletjson.ListTransactionsResult, but most fields omitted.
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 NativeWallet ¶ added in v1.0.0
type NativeWallet struct { *ExchangeWallet // contains filtered or unexported fields }
NativeWallet implements optional interfaces that are only provided by the built-in SPV wallet.
func (*NativeWallet) ConfigureFundsMixer ¶ added in v1.0.0
func (w *NativeWallet) ConfigureFundsMixer(enabled bool) (err error)
ConfigureFundsMixer configures the wallet for funds mixing. The wallet must be unlocked before calling. Part of the asset.FundsMixer interface.
func (*NativeWallet) FundsMixingStats ¶ added in v1.0.0
func (w *NativeWallet) FundsMixingStats() (*asset.FundsMixingStats, error)
FundsMixingStats returns the current state of the wallet's funds mixer. Part of the asset.FundsMixer interface.
func (*NativeWallet) Lock ¶ added in v1.0.0
func (w *NativeWallet) Lock() (err error)
Lock locks all the native wallet accounts.
func (*NativeWallet) Rescan ¶ added in v1.0.0
func (w *NativeWallet) Rescan(ctx context.Context, bday uint64) (err error)
Rescan initiates a rescan of the wallet from height 0. Rescan only blocks long enough for the first asynchronous update, either an error or after the first 2000 blocks are scanned.
type RecoveryCfg ¶ added in v0.5.0
type RecoveryCfg struct { NumExternalAddresses uint32 `ini:"numexternaladdr"` NumInternalAddresses uint32 `ini:"numinternaladdr"` GapLimit uint32 `ini:"gaplimit"` }
RecoveryCfg is the information that is transferred from the old wallet to the new one when the wallet is recovered.
type TicketPurchaseUpdate ¶ added in v1.0.0
type TicketPurchaseUpdate struct { Err string `json:"err,omitempty"` Remaining uint32 `json:"remaining"` Tickets []*asset.Ticket `json:"tickets"` Stats *asset.TicketStats `json:"stats,omitempty"` }
TicketPurchaseUpdate is an update from the asynchronous ticket purchasing loop.
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 // Accounts returns the names of the accounts for use by the exchange // wallet. Accounts() XCWalletAccounts // 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) // 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) // ListSinceBlock returns all wallet transactions confirmed since the specified // height. ListSinceBlock(ctx context.Context, start int32) ([]ListTransactionsResult, 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) (*asset.SyncStatus, 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) // PurchaseTickets purchases n tickets. vspHost and vspPubKey only // needed for internal wallets. Peer-to-peer mixing can be enabled if required. PurchaseTickets(ctx context.Context, n int, vspHost, vspPubKey string, isMixing bool) ([]*asset.Ticket, error) // Tickets returns current active ticket hashes up until they are voted // or revoked. Includes unconfirmed tickets. Tickets(ctx context.Context) ([]*asset.Ticket, error) // VotingPreferences returns current voting preferences. VotingPreferences(ctx context.Context) ([]*walletjson.VoteChoice, []*asset.TBTreasurySpend, []*walletjson.TreasuryPolicyResult, error) // SetVotingPreferences sets preferences used when a ticket is chosen to // be voted on. SetVotingPreferences(ctx context.Context, choices, tspendPolicy, treasuryPolicy map[string]string) error SetTxFee(ctx context.Context, feePerKB dcrutil.Amount) error StakeInfo(ctx context.Context) (*wallet.StakeInfoData, error) Reconfigure(ctx context.Context, cfg *asset.WalletConfig, net dex.Network, currentAddress string) (restart bool, err error) WalletOwnsAddress(ctx context.Context, addr stdaddr.Address) (bool, 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 MsgTx *wire.MsgTx }
WalletTransaction is a pared down version of walletjson.GetTransactionResult.