Documentation ¶
Index ¶
- Constants
- Variables
- func BitcoreRateFetcher(ticker string) func(ctx context.Context, net dex.Network) (uint64, error)
- func CalcMedianTime(stamper chainStamper, blockHash *chainhash.Hash) (time.Time, error)
- func Call(ctx context.Context, r RawRequester, method string, args anylist, thing any) error
- func ChainOK(net dex.Network, str string) bool
- func CommonConfigOpts(symbol string, withApiFallback bool) []*asset.ConfigOption
- func FindRedemptionsInMempool(ctx context.Context, log dex.Logger, reqs map[OutPoint]*FindRedemptionReq, ...) (discovered map[OutPoint]*FindRedemptionResult)
- func IsTxNotFoundErr(err error) bool
- func NewWallet(cfg *asset.WalletConfig, logger dex.Logger, net dex.Network) (asset.Wallet, error)
- func RPCConfigOpts(name, rpcPort string) []*asset.ConfigOption
- func RegisterCustomSPVWallet(constructor CustomSPVWalletConstructor, def *asset.WalletDefinition)
- func SearchBlockForRedemptions(ctx context.Context, reqs map[OutPoint]*FindRedemptionReq, ...) (discovered map[OutPoint]*FindRedemptionResult)
- func SumUTXOs(set []*CompositeUTXO) (tot uint64)
- func ToCoinID(txHash *chainhash.Hash, vout uint32) []byte
- func TxOutFromTxBytes(txB []byte, vout uint32, deserializeTx func([]byte) (*wire.MsgTx, error), ...) (*wire.TxOut, error)
- type AddressRecycler
- type AuditInfo
- type BTCCloneCFG
- type BTCWallet
- type BTCWalletConstructor
- type BadgerTxDB
- func (db *BadgerTxDB) Connect(ctx context.Context) (*sync.WaitGroup, error)
- func (db *BadgerTxDB) GetLastReceiveTxQuery() (uint64, error)
- func (db *BadgerTxDB) GetPendingTxs() ([]*ExtendedWalletTx, error)
- func (db *BadgerTxDB) GetTx(txID string) (*asset.WalletTransaction, error)
- func (db *BadgerTxDB) GetTxs(n int, refID *string, past bool) ([]*asset.WalletTransaction, error)
- func (db *BadgerTxDB) MarkTxAsSubmitted(txID string) error
- func (db *BadgerTxDB) RemoveTx(txID string) error
- func (db *BadgerTxDB) SetLastReceiveTxQuery(block uint64) error
- func (db *BadgerTxDB) StoreTx(tx *ExtendedWalletTx) error
- type Balances
- type BlockFiltersScanner
- type BlockHeader
- type BlockNotification
- type BlockVector
- type CoinManager
- func (c *CoinManager) Fund(keep uint64, minConfs uint32, lockUnspents bool, enough EnoughFunc) (coins asset.Coins, fundingCoins map[OutPoint]*UTxO, spents []*Output, ...)
- func (c *CoinManager) FundMultiBestEffort(keep, maxLock uint64, values []*asset.MultiOrderValue, maxFeeRate uint64, ...) ([]asset.Coins, [][]dex.Bytes, map[OutPoint]*UTxO, []*Output, error)
- func (c *CoinManager) FundWithUTXOs(utxos []*CompositeUTXO, keep uint64, lockUnspents bool, enough EnoughFunc) (coins asset.Coins, fundingCoins map[OutPoint]*UTxO, spents []*Output, ...)
- func (c *CoinManager) FundingCoins(ids []dex.Bytes) (asset.Coins, error)
- func (c *CoinManager) LockOutputsMap(utxos map[OutPoint]*UTxO)
- func (c *CoinManager) LockUTXOs(utxos []*UTxO)
- func (c *CoinManager) LockedOutput(pt OutPoint) *UTxO
- func (c *CoinManager) OrderWithLeastOverFund(maxLock, feeRate uint64, orders []*asset.MultiOrderValue, ...) (orderIndex int, leastOverFundingUTXOs []*CompositeUTXO)
- func (c *CoinManager) ReturnCoins(unspents asset.Coins) error
- func (c *CoinManager) ReturnOutPoint(pt OutPoint) error
- func (c *CoinManager) SpendableUTXOs(confs uint32) ([]*CompositeUTXO, map[OutPoint]*CompositeUTXO, uint64, error)
- func (c *CoinManager) UnlockOutPoints(pts []OutPoint)
- type CompositeUTXO
- type CustomSPVWalletConstructor
- 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, settings 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 EnoughFunc
- type ExchangeWalletAccelerator
- func (btc *ExchangeWalletAccelerator) AccelerateOrder(swapCoins, accelerationCoins []dex.Bytes, changeCoin dex.Bytes, ...) (asset.Coin, string, error)
- func (btc *ExchangeWalletAccelerator) AccelerationEstimate(swapCoins, accelerationCoins []dex.Bytes, changeCoin dex.Bytes, ...) (uint64, error)
- func (btc ExchangeWalletAccelerator) Connect(ctx context.Context) (*sync.WaitGroup, error)
- func (btc ExchangeWalletAccelerator) EstimateSendTxFee(address string, sendAmount, feeRate uint64, subtract, _ bool) (fee uint64, isValidAddress bool, err error)
- func (btc ExchangeWalletAccelerator) FeesForRemainingSwaps(n, feeRate uint64) uint64
- func (btc ExchangeWalletAccelerator) FindBond(ctx context.Context, coinID []byte, searchUntil time.Time) (bond *asset.BondDetails, err error)
- func (btc ExchangeWalletAccelerator) FindRedemption(ctx context.Context, coinID, _ dex.Bytes) (redemptionCoin, secret dex.Bytes, err error)
- func (a ExchangeWalletAccelerator) Lock() error
- func (a ExchangeWalletAccelerator) Locked() bool
- func (btc *ExchangeWalletAccelerator) PreAccelerate(swapCoins, accelerationCoins []dex.Bytes, changeCoin dex.Bytes, ...) (uint64, *asset.XYRange, *asset.EarlyAcceleration, error)
- func (btc ExchangeWalletAccelerator) TxHistory(n int, refID *string, past bool) ([]*asset.WalletTransaction, error)
- func (a ExchangeWalletAccelerator) Unlock(pw []byte) error
- func (btc ExchangeWalletAccelerator) WalletTransaction(ctx context.Context, txID string) (*asset.WalletTransaction, error)
- type ExchangeWalletElectrum
- func (btc ExchangeWalletElectrum) AuditContract(coinID, contract, txData dex.Bytes, rebroadcast bool) (*asset.AuditInfo, error)
- func (btc ExchangeWalletElectrum) Balance() (*asset.Balance, error)
- func (btc ExchangeWalletElectrum) BondsFeeBuffer(feeRate uint64) uint64
- func (btc ExchangeWalletElectrum) CallRPC(method string, args []any, thing any) error
- func (btc ExchangeWalletElectrum) ConfirmRedemption(coinID dex.Bytes, redemption *asset.Redemption, feeSuggestion uint64) (*asset.ConfirmRedemptionStatus, error)
- func (btc *ExchangeWalletElectrum) Connect(ctx context.Context) (*sync.WaitGroup, error)
- func (btc ExchangeWalletElectrum) ContractLockTimeExpired(ctx context.Context, contract dex.Bytes) (bool, time.Time, error)
- func (btc *ExchangeWalletElectrum) DepositAddress() (string, error)
- func (btc ExchangeWalletElectrum) FeeRate() uint64
- func (btc ExchangeWalletElectrum) FindBond(_ context.Context, coinID []byte, _ time.Time) (bond *asset.BondDetails, err error)
- func (btc *ExchangeWalletElectrum) FindRedemption(ctx context.Context, coinID, contract dex.Bytes) (redemptionCoin, secret dex.Bytes, err error)
- func (btc ExchangeWalletElectrum) FundMultiOrder(mo *asset.MultiOrder, maxLock uint64) ([]asset.Coins, [][]dex.Bytes, uint64, error)
- func (btc ExchangeWalletElectrum) FundOrder(ord *asset.Order) (asset.Coins, []dex.Bytes, uint64, error)
- func (btc ExchangeWalletElectrum) FundingCoins(ids []dex.Bytes) (asset.Coins, error)
- func (btc ExchangeWalletElectrum) GetBestBlockHeight() (int32, error)
- func (btc ExchangeWalletElectrum) Info() *asset.WalletInfo
- func (btc ExchangeWalletElectrum) IsDust(txOut *wire.TxOut, minRelayTxFee uint64) bool
- func (a ExchangeWalletElectrum) Lock() error
- func (btc ExchangeWalletElectrum) LockTimeExpired(_ context.Context, lockTime time.Time) (bool, error)
- func (a ExchangeWalletElectrum) Locked() bool
- func (btc ExchangeWalletElectrum) MakeBondTx(ver uint16, amt, feeRate uint64, lockTime time.Time, ...) (*asset.Bond, func(), error)
- func (btc ExchangeWalletElectrum) MaxFundingFees(numTrades uint32, feeRate uint64, options map[string]string) uint64
- func (btc ExchangeWalletElectrum) MaxOrder(ord *asset.MaxOrderForm) (*asset.SwapEstimate, error)
- func (btc ExchangeWalletElectrum) NewAddress() (string, error)
- func (btc ExchangeWalletElectrum) OwnsDepositAddress(address string) (bool, error)
- func (btc ExchangeWalletElectrum) PreRedeem(form *asset.PreRedeemForm) (*asset.PreRedeem, error)
- func (btc ExchangeWalletElectrum) PreSwap(req *asset.PreSwapForm) (*asset.PreSwap, error)
- func (btc ExchangeWalletElectrum) Reconfigure(ctx context.Context, cfg *asset.WalletConfig, currentAddress string) (restart bool, err error)
- func (btc ExchangeWalletElectrum) Redeem(form *asset.RedeemForm) ([]dex.Bytes, asset.Coin, uint64, error)
- func (btc *ExchangeWalletElectrum) RedemptionAddress() (string, error)
- func (btc ExchangeWalletElectrum) Refund(coinID, contract dex.Bytes, feeRate uint64) (dex.Bytes, error)
- func (btc ExchangeWalletElectrum) RefundBond(ctx context.Context, ver uint16, coinID, script []byte, amt uint64, ...) (asset.Coin, error)
- func (btc ExchangeWalletElectrum) RegFeeConfirmations(_ context.Context, id dex.Bytes) (confs uint32, err error)
- func (btc ExchangeWalletElectrum) ReturnCoins(unspents asset.Coins) error
- func (btc ExchangeWalletElectrum) ReturnRedemptionAddress(addr string)
- func (btc ExchangeWalletElectrum) ReturnRefundContracts(contracts [][]byte)
- func (btc ExchangeWalletElectrum) Send(address string, value, feeRate uint64) (asset.Coin, error)
- func (btc ExchangeWalletElectrum) SendTransaction(rawTx []byte) ([]byte, error)
- func (btc ExchangeWalletElectrum) SetBondReserves(reserves uint64)
- func (btc ExchangeWalletElectrum) SignMessage(coin asset.Coin, msg dex.Bytes) (pubkeys, sigs []dex.Bytes, err error)
- func (btc ExchangeWalletElectrum) SingleLotRedeemFees(_ uint32, feeSuggestion uint64) (uint64, error)
- func (btc ExchangeWalletElectrum) SingleLotSwapRefundFees(_ uint32, feeSuggestion uint64, useSafeTxSize bool) (swapFees uint64, refundFees uint64, err error)
- func (btc ExchangeWalletElectrum) StandardSendFee(feeRate uint64) uint64
- func (btc ExchangeWalletElectrum) Swap(swaps *asset.Swaps) ([]asset.Receipt, asset.Coin, uint64, error)
- func (btc ExchangeWalletElectrum) SwapConfirmations(_ context.Context, id dex.Bytes, contract dex.Bytes, startTime time.Time) (uint32, bool, error)
- func (btc ExchangeWalletElectrum) SyncStatus() (*asset.SyncStatus, error)
- func (btc *ExchangeWalletElectrum) TxHistory(n int, refID *string, past bool) ([]*asset.WalletTransaction, error)
- func (a ExchangeWalletElectrum) Unlock(pw []byte) error
- func (w ExchangeWalletElectrum) UseSplitTx() bool
- func (btc ExchangeWalletElectrum) ValidateAddress(address string) bool
- func (btc ExchangeWalletElectrum) ValidateSecret(secret, secretHash []byte) bool
- func (btc *ExchangeWalletElectrum) WalletTransaction(ctx context.Context, txID string) (*asset.WalletTransaction, error)
- func (btc ExchangeWalletElectrum) Withdraw(address string, value, feeRate uint64) (asset.Coin, error)
- type ExchangeWalletFullNode
- func (btc ExchangeWalletFullNode) Connect(ctx context.Context) (*sync.WaitGroup, error)
- func (btc ExchangeWalletFullNode) EstimateSendTxFee(address string, sendAmount, feeRate uint64, subtract, _ bool) (fee uint64, isValidAddress bool, err error)
- func (btc ExchangeWalletFullNode) FeesForRemainingSwaps(n, feeRate uint64) uint64
- func (btc ExchangeWalletFullNode) FindBond(ctx context.Context, coinID []byte, searchUntil time.Time) (bond *asset.BondDetails, err error)
- func (btc ExchangeWalletFullNode) FindRedemption(ctx context.Context, coinID, _ dex.Bytes) (redemptionCoin, secret dex.Bytes, err error)
- func (a ExchangeWalletFullNode) Lock() error
- func (a ExchangeWalletFullNode) Locked() bool
- func (btc ExchangeWalletFullNode) TxHistory(n int, refID *string, past bool) ([]*asset.WalletTransaction, error)
- func (a ExchangeWalletFullNode) Unlock(pw []byte) error
- func (btc ExchangeWalletFullNode) WalletTransaction(ctx context.Context, txID string) (*asset.WalletTransaction, error)
- type ExchangeWalletNoAuth
- func (btc ExchangeWalletNoAuth) Connect(ctx context.Context) (*sync.WaitGroup, error)
- func (btc ExchangeWalletNoAuth) EstimateSendTxFee(address string, sendAmount, feeRate uint64, subtract, _ bool) (fee uint64, isValidAddress bool, err error)
- func (btc ExchangeWalletNoAuth) FeesForRemainingSwaps(n, feeRate uint64) uint64
- func (btc ExchangeWalletNoAuth) FindBond(ctx context.Context, coinID []byte, searchUntil time.Time) (bond *asset.BondDetails, err error)
- func (btc ExchangeWalletNoAuth) FindRedemption(ctx context.Context, coinID, _ dex.Bytes) (redemptionCoin, secret dex.Bytes, err error)
- func (btc ExchangeWalletNoAuth) TxHistory(n int, refID *string, past bool) ([]*asset.WalletTransaction, error)
- func (btc ExchangeWalletNoAuth) WalletTransaction(ctx context.Context, txID string) (*asset.WalletTransaction, error)
- type ExchangeWalletSPV
- func (btc *ExchangeWalletSPV) AccelerateOrder(swapCoins, accelerationCoins []dex.Bytes, changeCoin dex.Bytes, ...) (asset.Coin, string, error)
- func (btc *ExchangeWalletSPV) AccelerationEstimate(swapCoins, accelerationCoins []dex.Bytes, changeCoin dex.Bytes, ...) (uint64, error)
- func (btc *ExchangeWalletSPV) AddPeer(addr string) error
- func (btc ExchangeWalletSPV) Connect(ctx context.Context) (*sync.WaitGroup, error)
- func (btc ExchangeWalletSPV) EstimateSendTxFee(address string, sendAmount, feeRate uint64, subtract, _ bool) (fee uint64, isValidAddress bool, err error)
- func (btc ExchangeWalletSPV) FeesForRemainingSwaps(n, feeRate uint64) uint64
- func (btc ExchangeWalletSPV) FindBond(ctx context.Context, coinID []byte, searchUntil time.Time) (bond *asset.BondDetails, err error)
- func (btc ExchangeWalletSPV) FindRedemption(ctx context.Context, coinID, _ dex.Bytes) (redemptionCoin, secret dex.Bytes, err error)
- func (btc *ExchangeWalletSPV) GetRecoveryCfg() (map[string]string, error)
- func (a ExchangeWalletSPV) Lock() error
- func (a ExchangeWalletSPV) Locked() bool
- func (btc *ExchangeWalletSPV) LogFilePath() string
- func (btc *ExchangeWalletSPV) Move(backupDir string) error
- func (btc *ExchangeWalletSPV) Peers() ([]*asset.WalletPeer, error)
- func (btc *ExchangeWalletSPV) PreAccelerate(swapCoins, accelerationCoins []dex.Bytes, changeCoin dex.Bytes, ...) (uint64, *asset.XYRange, *asset.EarlyAcceleration, error)
- func (btc *ExchangeWalletSPV) RemovePeer(addr string) error
- func (btc *ExchangeWalletSPV) Rescan(_ context.Context, _ uint64) error
- func (btc ExchangeWalletSPV) TxHistory(n int, refID *string, past bool) ([]*asset.WalletTransaction, error)
- func (a ExchangeWalletSPV) Unlock(pw []byte) error
- func (btc ExchangeWalletSPV) WalletTransaction(ctx context.Context, txID string) (*asset.WalletTransaction, error)
- func (btc *ExchangeWalletSPV) WithdrawTx(ctx context.Context, walletPW []byte, addr btcutil.Address) (_ *wire.MsgTx, err error)
- type ExtendedWalletTx
- type FindRedemptionReq
- type FindRedemptionResult
- type GetAddressInfoResult
- type GetBalancesResult
- type GetBlockchainInfoResult
- type GetTransactionResult
- type GetWalletInfoResult
- type ListTransactionsResult
- type ListUnspentResult
- type OrderEstimator
- type OrderFundingThresholder
- type OutPoint
- type Output
- type PeerManagerChainService
- type RPCConfig
- type RPCOutpoint
- type RPCWalletConfig
- type RawRequester
- type RecoveryCfg
- type RedemptionFinder
- type SPVPeer
- type SPVPeerManager
- type SPVService
- type SignTxError
- type SignTxResult
- type SwapReceipt
- type TxInSigner
- type UTxO
- type Wallet
- type WalletConfig
- type XCWalletAccount
Constants ¶
const ( WalletTransactionNotFound = dex.ErrorKind("wallet transaction not found") SpentStatusUnknown = dex.ErrorKind("spend status not known") )
const (
// BipID is the BIP-0044 asset ID.
BipID = 0
)
const ErrNeverQueried = dex.ErrorKind("never queried")
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 ElectrumConfigOpts = []*asset.ConfigOption{ { Key: "rpcuser", DisplayName: "JSON-RPC Username", Description: "Electrum's 'rpcuser' setting", }, { Key: "rpcpassword", DisplayName: "JSON-RPC Password", Description: "Electrum's 'rpcpassword' setting", NoEcho: true, }, { Key: "rpcport", DisplayName: "JSON-RPC Port", Description: "Electrum's 'rpcport' (if not set with rpcbind)", }, { Key: "rpcbind", DisplayName: "JSON-RPC Address", Description: "Electrum's 'rpchost' <addr> or <addr>:<port>", DefaultValue: "127.0.0.1", }, { Key: "walletname", DisplayName: "Wallet File", Description: "Full path to the wallet file (empty is default_wallet)", DefaultValue: "", }, } DefaultWalletBirthday = time.Unix(int64(defaultWalletBirthdayUnix), 0) MultiFundingOpts = []*asset.OrderOption{ { ConfigOption: asset.ConfigOption{ Key: multiSplitKey, DisplayName: "Allow multi split", Description: "Allow split funding transactions that pre-size outputs to " + "prevent excessive overlock.", IsBoolean: true, DefaultValue: true, }, }, { ConfigOption: asset.ConfigOption{ Key: multiSplitBufferKey, DisplayName: "Multi split buffer", Description: "Add an integer percent buffer to split output amounts to " + "facilitate output reuse. This is only required for quote assets.", DefaultValue: 5, DependsOn: multiSplitKey, }, QuoteAssetOnly: true, XYRange: &asset.XYRange{ Start: asset.XYRangePoint{ Label: "0%", X: 0, Y: 0, }, End: asset.XYRangePoint{ Label: "100%", X: 100, Y: 100, }, XUnit: "%", YUnit: "%", RoundX: true, RoundY: true, }, }, } // WalletInfo defines some general information about a Bitcoin wallet. WalletInfo = &asset.WalletInfo{ Name: "Bitcoin", SupportedVersions: []uint32{version}, UnitInfo: dexbtc.UnitInfo, AvailableWallets: []*asset.WalletDefinition{ spvWalletDefinition, rpcWalletDefinition, electrumWalletDefinition, }, LegacyWalletIndex: 1, } )
Functions ¶
func BitcoreRateFetcher ¶ added in v1.0.0
BitcoreRateFetcher generates a rate fetching function for the bitcore.io API.
func CalcMedianTime ¶ added in v1.0.0
CalcMedianTime calculates the median time of the previous 11 block headers. The median time is used for validating time-locked transactions. See notes in btcd/blockchain (*blockNode).CalcPastMedianTime() regarding incorrectly calculated median time for blocks 1, 3, 5, 7, and 9.
func ChainOK ¶ added in v1.0.0
ChainOK is for screening the chain field of the getblockchaininfo result.
func CommonConfigOpts ¶ added in v0.6.0
func CommonConfigOpts(symbol string, withApiFallback bool) []*asset.ConfigOption
CommonConfigOpts are the common options that the Wallets recognize.
func FindRedemptionsInMempool ¶ added in v1.0.0
func FindRedemptionsInMempool( ctx context.Context, log dex.Logger, reqs map[OutPoint]*FindRedemptionReq, getMempool func() ([]*chainhash.Hash, error), getTx func(txHash *chainhash.Hash) (*wire.MsgTx, error), segwit bool, hashTx func(*wire.MsgTx) *chainhash.Hash, chainParams *chaincfg.Params, ) (discovered map[OutPoint]*FindRedemptionResult)
func IsTxNotFoundErr ¶ added in v1.0.0
IsTxNotFoundErr will return true if the error indicates that the requested transaction is not known. The error must be dcrjson.RPCError with a numeric code equal to btcjson.ErrRPCNoTxInfo. WARNING: This is specific to errors from an RPC to a bitcoind (or clone) using dcrd's rpcclient!
func NewWallet ¶
NewWallet is the exported constructor by which the DEX will import the exchange wallet.
func RPCConfigOpts ¶ added in v0.6.0
func RPCConfigOpts(name, rpcPort string) []*asset.ConfigOption
RPCConfigOpts are the settings that are used to connect to an external RPC wallet.
func RegisterCustomSPVWallet ¶ added in v1.0.0
func RegisterCustomSPVWallet(constructor CustomSPVWalletConstructor, def *asset.WalletDefinition)
RegisterCustomSPVWallet registers a function that should be used in creating a BTCWallet implementation that the ExchangeWalletSPV will use in place of the default spv wallet implementation. External consumers can use this function to provide alternative BTCWallet implementations, and must do so before attempting to create an ExchangeWalletSPV instance of this type. It'll panic if callers try to register a wallet twice.
func SearchBlockForRedemptions ¶ added in v1.0.0
func SumUTXOs ¶ added in v1.0.0
func SumUTXOs(set []*CompositeUTXO) (tot uint64)
Types ¶
type AddressRecycler ¶ added in v1.0.0
type AddressRecycler struct {
// contains filtered or unexported fields
}
func NewAddressRecycler ¶ added in v1.0.0
func NewAddressRecycler(recyclePath string, log dex.Logger) (*AddressRecycler, error)
func (*AddressRecycler) Address ¶ added in v1.0.0
func (a *AddressRecycler) Address() string
func (*AddressRecycler) ReturnAddresses ¶ added in v1.0.0
func (a *AddressRecycler) ReturnAddresses(addrs []string)
func (*AddressRecycler) WriteRecycledAddrsToFile ¶ added in v1.0.0
func (a *AddressRecycler) WriteRecycledAddrsToFile()
WriteRecycledAddrsToFile writes the recycled address cache to file.
type AuditInfo ¶ added in v1.0.0
type AuditInfo struct { Output *Output Recipient btcutil.Address // caution: use stringAddr, not the Stringer // contains filtered or unexported fields }
AuditInfo is information about a swap contract on that blockchain.
func ConvertAuditInfo ¶ added in v1.0.0
func ConvertAuditInfo(ai *asset.AuditInfo, decodeAddr dexbtc.AddressDecoder, chainParams *chaincfg.Params) (*AuditInfo, error)
ConvertAuditInfo converts from the common *asset.AuditInfo type to our internal *auditInfo type.
func (*AuditInfo) Expiration ¶ added in v1.0.0
Expiration returns the expiration time of the contract, which is the earliest time that a refund can be issued for an un-redeemed contract.
func (*AuditInfo) SecretHash ¶ added in v1.0.0
SecretHash is the contract's secret hash.
type BTCCloneCFG ¶
type BTCCloneCFG struct { WalletCFG *asset.WalletConfig MinNetworkVersion uint64 MinElectrumVersion dex.Semver WalletInfo *asset.WalletInfo Symbol string Logger dex.Logger Network dex.Network ChainParams *chaincfg.Params // Ports is the default wallet RPC tcp ports used when undefined in // WalletConfig. Ports dexbtc.NetPorts DefaultFallbackFee uint64 // sats/byte DefaultFeeRateLimit uint64 // sats/byte // LegacyBalance is for clones that don't yet support the 'getbalances' RPC // call. LegacyBalance bool // BalanceFunc is a custom function for getting the wallet's balance. // BalanceFunc precludes any other methods of balance retrieval. BalanceFunc func(ctx context.Context, locked uint64) (*asset.Balance, error) // If segwit is false, legacy addresses and contracts will be used. This // setting must match the configuration of the server's asset backend. Segwit bool // LegacyRawFeeLimit can be true if the RPC only supports the boolean // allowHighFees argument to the sendrawtransaction RPC. LegacyRawFeeLimit bool // InitTxSize is the size of a swap initiation transaction with a single // input i.e. chained swaps. InitTxSize uint32 // InitTxSizeBase is the size of a swap initiation transaction with no // inputs. This is used to accurately determine the size of the first swap // in a chain when considered with the actual inputs. InitTxSizeBase uint32 // PrivKeyFunc is an optional function to get a private key for an address // from the wallet. If not given the usual dumpprivkey RPC will be used. PrivKeyFunc func(addr string) (*btcec.PrivateKey, error) // AddressDecoder is an optional argument that can decode an address string // into btcutil.Address. If AddressDecoder is not supplied, // btcutil.DecodeAddress will be used. AddressDecoder dexbtc.AddressDecoder // string => btcutil.Address // AddressStringer is an optional argument that can encode a btcutil.Address // into an address string. If AddressStringer is not supplied, the // (btcutil.Address).String method will be used. AddressStringer dexbtc.AddressStringer // btcutil.Address => string, may be an override or just the String method // BlockDeserializer can be used in place of (*wire.MsgBlock).Deserialize. BlockDeserializer func([]byte) (*wire.MsgBlock, error) // ArglessChangeAddrRPC can be true if the getrawchangeaddress takes no // address-type argument. ArglessChangeAddrRPC bool // NonSegwitSigner can be true if the transaction signature hash data is not // the standard for non-segwit Bitcoin. If nil, txscript. NonSegwitSigner TxInSigner // ConnectFunc, if provided, is called by the RPC client at the end of the // (*rpcClient).connect method. Errors returned by ConnectFunc will preclude // the starting of goroutines associated with block and peer monitoring. ConnectFunc func() error // FeeEstimator provides a way to get fees given an RawRequest-enabled // client and a confirmation target. FeeEstimator func(context.Context, RawRequester, uint64) (uint64, error) // ExternalFeeEstimator should be supplied if the clone provides the // apifeefallback ConfigOpt. TODO: confTarget uint64 ExternalFeeEstimator func(context.Context, dex.Network) (uint64, error) // ExternalFeeShelfLife can be set to adjust the time to staleness of // external fee rates. Default is 5 minutes. ExternalFeeShelfLife time.Duration // OmitAddressType causes the address type (bech32, legacy) to be omitted // from calls to getnewaddress. OmitAddressType bool // LegacySignTxRPC causes the RPC client to use the signrawtransaction // endpoint instead of the signrawtransactionwithwallet endpoint. LegacySignTxRPC bool // BooleanGetBlockRPC causes the RPC client to use a boolean second argument // for the getblock endpoint, instead of Bitcoin's numeric. BooleanGetBlockRPC bool // LegacyValidateAddressRPC uses the validateaddress endpoint instead of // getaddressinfo in order to discover ownership of an address. LegacyValidateAddressRPC bool // SingularWallet signals that the node software supports only one wallet, // so the RPC endpoint does not have a /wallet/{walletname} path. SingularWallet bool // UnlockSpends manually unlocks outputs as they are spent. Most assets will // unlock wallet outputs automatically as they are spent. UnlockSpends bool // TxDeserializer is an optional function used to deserialize a transaction. TxDeserializer func([]byte) (*wire.MsgTx, error) // TxSerializer is an optional function used to serialize a transaction. TxSerializer func(*wire.MsgTx) ([]byte, error) // TxHasher is a function that generates a tx hash from a MsgTx. TxHasher func(*wire.MsgTx) *chainhash.Hash // TxSizeCalculator is an optional function that will be used to calculate // the size of a transaction. TxSizeCalculator func(*wire.MsgTx) uint64 // NumericGetRawRPC uses a numeric boolean indicator for the // getrawtransaction RPC. NumericGetRawRPC bool // TxVersion is an optional function that returns a version to use for // new transactions. TxVersion func() int32 // ManualMedianTime causes the median time to be calculated manually. ManualMedianTime bool // ConstantDustLimit is used if an asset enforces a dust limit (minimum // output value) that doesn't depend on the serialized size of the output. // If ConstantDustLimit is zero, dexbtc.IsDust is used. ConstantDustLimit uint64 // OmitRPCOptionsArg is for clones that don't take an options argument. OmitRPCOptionsArg bool // AssetID is the asset ID of the clone. AssetID uint32 }
BTCCloneCFG holds clone specific parameters.
type BTCWallet ¶ added in v0.6.0
type BTCWallet interface { PublishTransaction(tx *wire.MsgTx, label string) error CalculateAccountBalances(account uint32, confirms int32) (wallet.Balances, error) ListUnspent(minconf, maxconf int32, acctName string) ([]*btcjson.ListUnspentResult, error) FetchInputInfo(prevOut *wire.OutPoint) (*wire.MsgTx, *wire.TxOut, *psbt.Bip32Derivation, int64, error) ResetLockedOutpoints() LockOutpoint(op wire.OutPoint) UnlockOutpoint(op wire.OutPoint) LockedOutpoints() []btcjson.TransactionInput NewChangeAddress(account uint32, scope waddrmgr.KeyScope) (btcutil.Address, error) NewAddress(account uint32, scope waddrmgr.KeyScope) (btcutil.Address, error) PrivKeyForAddress(a btcutil.Address) (*btcec.PrivateKey, error) Unlock(passphrase []byte, lock <-chan time.Time) error Lock() Locked() bool SendOutputs(outputs []*wire.TxOut, keyScope *waddrmgr.KeyScope, account uint32, minconf int32, satPerKb btcutil.Amount, coinSelectionStrategy wallet.CoinSelectionStrategy, label string) (*wire.MsgTx, error) HaveAddress(a btcutil.Address) (bool, error) WaitForShutdown() ChainSynced() bool // currently unused AccountProperties(scope waddrmgr.KeyScope, acct uint32) (*waddrmgr.AccountProperties, error) // AccountInfo returns the account information of the wallet for use by the // exchange wallet. AccountInfo() XCWalletAccount // The below methods are not implemented by *wallet.Wallet, so must be // implemented by the BTCWallet implementation. WalletTransaction(txHash *chainhash.Hash) (*wtxmgr.TxDetails, error) SyncedTo() waddrmgr.BlockStamp SignTx(*wire.MsgTx) error BlockNotifications(context.Context) <-chan *BlockNotification RescanAsync() error ForceRescan() Start() (SPVService, error) Stop() Birthday() time.Time Peers() ([]*asset.WalletPeer, error) AddPeer(string) error RemovePeer(string) error GetTransactions(startHeight, endHeight int32, accountName string, cancel <-chan struct{}) (*wallet.GetTransactionsResult, error) }
BTCWallet is roughly the (btcwallet/wallet.*Wallet) interface, with some additional required methods added.
type BTCWalletConstructor ¶ added in v0.6.0
type BTCWalletConstructor func(dir string, cfg *WalletConfig, chainParams *chaincfg.Params, log dex.Logger) BTCWallet
BTCWalletConstructor is a function to construct a BTCWallet.
type BadgerTxDB ¶ added in v1.0.0
func NewBadgerTxDB ¶ added in v1.0.0
func NewBadgerTxDB(filePath string, log dex.Logger) *BadgerTxDB
func (*BadgerTxDB) GetLastReceiveTxQuery ¶ added in v1.0.0
func (db *BadgerTxDB) GetLastReceiveTxQuery() (uint64, error)
GetLastReceiveTxQuery retrieves the last time the wallet was queried for receive transactions.
func (*BadgerTxDB) GetPendingTxs ¶ added in v1.0.0
func (db *BadgerTxDB) GetPendingTxs() ([]*ExtendedWalletTx, error)
GetPendingTxs returns all transactions that have not yet been confirmed.
func (*BadgerTxDB) GetTx ¶ added in v1.0.0
func (db *BadgerTxDB) GetTx(txID string) (*asset.WalletTransaction, error)
GetTx retrieves a transaction by its ID. If the transaction is not in the database, asset.CoinNotFoundError is returned.
func (*BadgerTxDB) GetTxs ¶ added in v1.0.0
func (db *BadgerTxDB) GetTxs(n int, refID *string, past bool) ([]*asset.WalletTransaction, error)
GetTxs retrieves n transactions from the database. refID optionally takes a transaction ID, and returns that transaction and the at most (n - 1) transactions that were made either before or after it, depending on the value of past. If refID is nil, the most recent n transactions are returned, and the value of past is ignored. If the transaction with ID refID is not in the database, asset.CoinNotFoundError is returned. Unsubmitted transactions are not returned.
func (*BadgerTxDB) MarkTxAsSubmitted ¶ added in v1.0.0
func (db *BadgerTxDB) MarkTxAsSubmitted(txID string) error
MarkTxAsSubmitted should be called when a previously stored transaction that had not yet been sent to the network is sent to the network. asset.CoinNotFoundError is returned if the transaction is not in the database.
func (*BadgerTxDB) RemoveTx ¶ added in v1.0.0
func (db *BadgerTxDB) RemoveTx(txID string) error
RemoveTx removes a transaction from the database. If the transaction is not in the database, asset.CoinNotFoundError is returned.
func (*BadgerTxDB) SetLastReceiveTxQuery ¶ added in v1.0.0
func (db *BadgerTxDB) SetLastReceiveTxQuery(block uint64) error
SetLastReceiveTxQuery stores the last time the wallet was queried for receive transactions. This is required to know how far back to query for incoming transactions that were received while the wallet is offline.
func (*BadgerTxDB) StoreTx ¶ added in v1.0.0
func (db *BadgerTxDB) StoreTx(tx *ExtendedWalletTx) error
StoreTx stores a transaction in the database.
type Balances ¶ added in v0.4.0
type Balances struct { Trusted float64 `json:"trusted"` Untrusted float64 `json:"untrusted_pending"` Immature float64 `json:"immature"` Used *float64 `json:"used,omitempty"` }
Balances is a categorical balance breakdown.
type BlockFiltersScanner ¶ added in v1.0.0
type BlockFiltersScanner struct {
// contains filtered or unexported fields
}
BlockFiltersScanner is a utility tool for searching for an output and its spending input by scanning BIP158 compact filters. Used by SPV wallets to locate non-wallet transactions.
func NewBlockFiltersScanner ¶ added in v1.0.0
func NewBlockFiltersScanner(blkInfoRdr blockInfoReader, log dex.Logger) *BlockFiltersScanner
NewBlockFiltersScanner creates a BlockFiltersScanner.
func (*BlockFiltersScanner) CleanCaches ¶ added in v1.0.0
func (s *BlockFiltersScanner) CleanCaches(expiration time.Duration)
CleanCaches removes cached tx and filter scan results that have not been accessed since the specified duration. Should be called periodically from a goroutine.
func (*BlockFiltersScanner) ScanFilters ¶ added in v1.0.0
func (s *BlockFiltersScanner) ScanFilters(txHash *chainhash.Hash, vout uint32, pkScript []byte, walletTip int32, startTime time.Time, blockHash *chainhash.Hash) (*filterScanResult, error)
ScanFilters enables searching for an output and its spending input by scanning BIP158 compact filters. Caller should supply either blockHash or startTime. blockHash takes precedence. If blockHash is supplied, the scan will start at that block and continue to the current blockchain tip, or until both the output and a spending transaction is found. if startTime is supplied, and the blockHash for the output is not known to the wallet, a candidate block will be selected with findBlockTime.
type BlockHeader ¶ added in v1.0.0
type BlockHeader struct { Hash string `json:"hash"` Confirmations int64 `json:"confirmations"` Height int64 `json:"height"` Time int64 `json:"time"` PreviousBlockHash string `json:"previousblockhash"` MedianTime int64 `json:"mediantime"` }
BlockHeader is a partial btcjson.GetBlockHeaderVerboseResult with mediantime included.
type BlockNotification ¶ added in v0.6.0
BlockNotification is block hash and height delivered by a BTCWallet when it is finished processing a block.
type BlockVector ¶ added in v1.0.0
type CoinManager ¶ added in v1.0.0
type CoinManager struct {
// contains filtered or unexported fields
}
CoinManager provides utilities for working with unspent transaction outputs. In addition to translation to and from custom wallet types, there are CoinManager methods to help pick UTXOs for funding in various contexts.
func NewCoinManager ¶ added in v1.0.0
func NewCoinManager( log dex.Logger, chainParams *chaincfg.Params, orderEnough OrderFundingThresholder, listUnspent func() ([]*ListUnspentResult, error), lockUnspent func(unlock bool, ops []*Output) error, listLocked func() ([]*RPCOutpoint, error), getTxOut func(txHash *chainhash.Hash, vout uint32) (*wire.TxOut, error), stringAddr func(btcutil.Address) (string, error), ) *CoinManager
func (*CoinManager) Fund ¶ added in v1.0.0
func (c *CoinManager) Fund( keep uint64, minConfs uint32, lockUnspents bool, enough EnoughFunc, ) (coins asset.Coins, fundingCoins map[OutPoint]*UTxO, spents []*Output, redeemScripts []dex.Bytes, size, sum uint64, err error)
Fund attempts to satisfy the given EnoughFunc with all available UTXOs. For situations where Fund might be called repeatedly, the caller should instead do SpendableUTXOs and use the results in FundWithUTXOs.
func (*CoinManager) FundMultiBestEffort ¶ added in v1.0.0
func (c *CoinManager) FundMultiBestEffort(keep, maxLock uint64, values []*asset.MultiOrderValue, maxFeeRate uint64, splitAllowed bool) ([]asset.Coins, [][]dex.Bytes, map[OutPoint]*UTxO, []*Output, error)
fundMultiBestEffort makes a best effort to fund every order. If it is not possible, it returns coins for the orders that could be funded. The coins that fund each order are returned in the same order as the values that were passed in. If a split is allowed and all orders cannot be funded, nil slices are returned.
func (*CoinManager) FundWithUTXOs ¶ added in v1.0.0
func (c *CoinManager) FundWithUTXOs( utxos []*CompositeUTXO, keep uint64, lockUnspents bool, enough EnoughFunc, ) (coins asset.Coins, fundingCoins map[OutPoint]*UTxO, spents []*Output, redeemScripts []dex.Bytes, size, sum uint64, err error)
FundWithUTXOs attempts to find the best combination of UTXOs to satisfy the given EnoughFunc while respecting the specified keep reserves (if non-zero).
func (*CoinManager) FundingCoins ¶ added in v1.0.0
FundingCoins attempts to find the specified utxos and locks them.
func (*CoinManager) LockOutputsMap ¶ added in v1.0.0
func (c *CoinManager) LockOutputsMap(utxos map[OutPoint]*UTxO)
LockOutputs locks the utxos in the provided mapping.
func (*CoinManager) LockUTXOs ¶ added in v1.0.0
func (c *CoinManager) LockUTXOs(utxos []*UTxO)
LockUTXOs locks the specified utxos. TODO: Move lockUnspent calls into this method instead of the caller doing it at every callsite, and because that's what we do with unlocking.
func (*CoinManager) LockedOutput ¶ added in v1.0.0
func (c *CoinManager) LockedOutput(pt OutPoint) *UTxO
LockedOutput returns the currently locked utxo represented by the provided outpoint, or nil if there is no record of the utxo in the local map.
func (*CoinManager) OrderWithLeastOverFund ¶ added in v1.0.0
func (c *CoinManager) OrderWithLeastOverFund(maxLock, feeRate uint64, orders []*asset.MultiOrderValue, utxos []*CompositeUTXO) (orderIndex int, leastOverFundingUTXOs []*CompositeUTXO)
OrderWithLeastOverFund returns the index of the order from a slice of orders that requires the least over-funding without using more than maxLock. It also returns the UTXOs that were used to fund the order. If none can be funded without using more than maxLock, -1 is returned.
func (*CoinManager) ReturnCoins ¶ added in v1.0.0
func (c *CoinManager) ReturnCoins(unspents asset.Coins) error
ReturnCoins makes the locked utxos available for use again.
func (*CoinManager) ReturnOutPoint ¶ added in v1.0.0
func (c *CoinManager) ReturnOutPoint(pt OutPoint) error
ReturnOutPoint makes the UTXO represented by the OutPoint available for use again.
func (*CoinManager) SpendableUTXOs ¶ added in v1.0.0
func (c *CoinManager) SpendableUTXOs(confs uint32) ([]*CompositeUTXO, map[OutPoint]*CompositeUTXO, uint64, error)
SpendableUTXOs filters the RPC utxos for those that are spendable with regards to the DEX's configuration, and considered safe to spend according to confirmations and coin source. The UTXOs will be sorted by ascending value. spendableUTXOs should only be called with the fundingMtx RLock'ed.
func (*CoinManager) UnlockOutPoints ¶ added in v1.0.0
func (c *CoinManager) UnlockOutPoints(pts []OutPoint)
UnlockOutPoints unlocks the utxos represented by the provided outpoints.
type CompositeUTXO ¶ added in v1.0.0
CompositeUTXO combines utxo info with the spending input information.
func UTxOSetDiff ¶ added in v1.0.0
func UTxOSetDiff(set, sub []*CompositeUTXO) []*CompositeUTXO
UTxOSetDiff performs the setdiff(set,sub) of two UTXO sets. That is, any UTXOs that are both sets are removed from the first. The comparison is done *by pointer*, with no regard to the values of the CompositeUTXO elements.
type CustomSPVWalletConstructor ¶ added in v1.0.0
type Driver ¶
type Driver struct{}
Driver implements asset.Driver.
func (*Driver) Create ¶ added in v0.4.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 Bitcoin.
func (*Driver) Exists ¶ added in v0.4.0
func (d *Driver) Exists(walletType, dataDir string, settings map[string]string, net dex.Network) (bool, error)
Exists checks the existence of the wallet. Part of the Creator interface, so only used for wallets with WalletDefinition.Seeded = true.
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 EnoughFunc ¶ added in v1.0.0
EnoughFunc considers information about funding inputs and indicates whether it is enough to fund an order. EnoughFunc is bound to an order by the OrderFundingThresholder.
type ExchangeWalletAccelerator ¶ added in v0.5.0
type ExchangeWalletAccelerator struct {
*ExchangeWalletFullNode
}
ExchangeWalletAccelerator implements the Accelerator interface on an ExchangeWalletFullNode.
func (*ExchangeWalletAccelerator) AccelerateOrder ¶ added in v0.5.0
func (btc *ExchangeWalletAccelerator) AccelerateOrder(swapCoins, accelerationCoins []dex.Bytes, changeCoin dex.Bytes, requiredForRemainingSwaps, newFeeRate uint64) (asset.Coin, string, error)
AccelerateOrder uses the Child-Pays-For-Parent technique to accelerate a chain of swap transactions and previous accelerations. It broadcasts a new transaction with a fee high enough so that the average fee of all the unconfirmed transactions in the chain and the new transaction will have an average fee rate of newFeeRate. The changeCoin argument is the latest change in the order. It must be the input in the acceleration transaction in order for the order to be accelerated. requiredForRemainingSwaps is the amount of funds required to complete the rest of the swaps in the order. The change output of the acceleration transaction will have at least this amount.
The returned change coin may be nil, and should be checked before use.
func (*ExchangeWalletAccelerator) AccelerationEstimate ¶ added in v0.5.0
func (btc *ExchangeWalletAccelerator) AccelerationEstimate(swapCoins, accelerationCoins []dex.Bytes, changeCoin dex.Bytes, requiredForRemainingSwaps, newFeeRate uint64) (uint64, error)
AccelerationEstimate takes the same parameters as AccelerateOrder, but instead of broadcasting the acceleration transaction, it just returns the amount of funds that will need to be spent in order to increase the average fee rate to the desired amount.
func (ExchangeWalletAccelerator) Connect ¶ added in v0.5.0
Connect connects the wallet to the btc.Wallet backend and starts monitoring blocks and peers. Satisfies the dex.Connector interface.
func (ExchangeWalletAccelerator) EstimateSendTxFee ¶ added in v0.6.0
func (btc ExchangeWalletAccelerator) 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 (ExchangeWalletAccelerator) FeesForRemainingSwaps ¶ added in v0.6.0
FeesForRemainingSwaps returns the fees for a certain number of swaps at a given feeRate. This is only accurate if each swap has a single input. Accurate estimates should use PreSwap or FundOrder.
func (ExchangeWalletAccelerator) FindBond ¶ added in v1.0.0
func (btc ExchangeWalletAccelerator) 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. The intermediate wallet is able to brute force finding blocks.
func (ExchangeWalletAccelerator) FindRedemption ¶ added in v0.5.0
func (btc ExchangeWalletAccelerator) 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 (ExchangeWalletAccelerator) Lock ¶ added in v1.0.0
func (a ExchangeWalletAccelerator) Lock() error
Lock locks the underlying bitcoind wallet. It implements asset.authenticator.
func (ExchangeWalletAccelerator) Locked ¶ added in v1.0.0
func (a ExchangeWalletAccelerator) Locked() bool
Locked will be true if the wallet is currently locked. It implements asset.authenticator.
func (*ExchangeWalletAccelerator) PreAccelerate ¶ added in v0.5.0
func (btc *ExchangeWalletAccelerator) PreAccelerate(swapCoins, accelerationCoins []dex.Bytes, changeCoin dex.Bytes, requiredForRemainingSwaps, feeSuggestion uint64) (uint64, *asset.XYRange, *asset.EarlyAcceleration, error)
PreAccelerate returns the current average fee rate of the unmined swap initiation and acceleration transactions, and also returns a suggested range that the fee rate should be increased to in order to expedite mining. The feeSuggestion argument is the current prevailing network rate. It is used to help determine the suggestedRange, which is a range meant to give the user a good amount of flexibility in determining the post acceleration effective fee rate, but still not allowing them to pick something outrageously high.
func (ExchangeWalletAccelerator) TxHistory ¶ added in v1.0.0
func (btc ExchangeWalletAccelerator) 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 (ExchangeWalletAccelerator) Unlock ¶ added in v1.0.0
Unlock unlocks the underlying wallet. The pw supplied should be the same as the password for the underlying bitcoind wallet which will also be unlocked. It implements asset.authenticator.
func (ExchangeWalletAccelerator) WalletTransaction ¶ added in v1.0.0
func (btc ExchangeWalletAccelerator) 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 can be either a byte reversed tx hash or a hex encoded coin ID.
type ExchangeWalletElectrum ¶ added in v0.5.0
type ExchangeWalletElectrum struct {
// contains filtered or unexported fields
}
ExchangeWalletElectrum is the asset.Wallet for an external Electrum wallet.
func ElectrumWallet ¶ added in v0.5.0
func ElectrumWallet(cfg *BTCCloneCFG) (*ExchangeWalletElectrum, error)
ElectrumWallet creates a new ExchangeWalletElectrum for the provided configuration, which must contain the necessary details for accessing the Electrum wallet's RPC server in the WalletCFG.Settings map.
func (ExchangeWalletElectrum) AuditContract ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) AuditContract(coinID, contract, txData dex.Bytes, rebroadcast bool) (*asset.AuditInfo, error)
AuditContract retrieves information about a swap contract from the provided txData. The extracted information would be used to audit the counter-party's contract during a swap. 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.
func (ExchangeWalletElectrum) Balance ¶ added in v0.5.0
Balance should return the total available funds in the wallet.
func (ExchangeWalletElectrum) BondsFeeBuffer ¶ added in v0.6.0
BondsFeeBuffer suggests how much extra may be required for the transaction fees part of required bond reserves when bond rotation is enabled. The provided fee rate may be zero, in which case the wallet will use it's own estimate or fallback value.
func (ExchangeWalletElectrum) CallRPC ¶ added in v0.6.1
CallRPC is a method for making RPC calls directly on an underlying RPC client. CallRPC is not part of the wallet interface. Its intended use is for clone wallets to implement custom functionality.
func (ExchangeWalletElectrum) ConfirmRedemption ¶ added in v1.0.0
func (btc ExchangeWalletElectrum) 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, with fluxuating fees, there's the possibility that the tx is never mined and eventually purged from the mempool. In that case we use the provided fee suggestion to create and send a new redeem transaction, returning the new transactions hash.
func (*ExchangeWalletElectrum) Connect ¶ added in v0.5.0
Connect connects to the Electrum wallet's RPC server and an electrum server directly. Goroutines are started to monitor for new blocks and server connection changes. Satisfies the dex.Connector interface.
func (ExchangeWalletElectrum) ContractLockTimeExpired ¶ added in v0.6.0
func (btc ExchangeWalletElectrum) 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 (*ExchangeWalletElectrum) DepositAddress ¶ added in v0.5.0
func (btc *ExchangeWalletElectrum) DepositAddress() (string, error)
DepositAddress returns an address for depositing funds into the exchange wallet. The address will be unused but not necessarily new. Use NewAddress to request a new address, but it should be used immediately.
func (ExchangeWalletElectrum) FeeRate ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) FeeRate() uint64
FeeRate satisfies asset.FeeRater.
func (ExchangeWalletElectrum) FindBond ¶ added in v1.0.0
func (btc ExchangeWalletElectrum) FindBond(_ context.Context, coinID []byte, _ time.Time) (bond *asset.BondDetails, err error)
FindBond finds the bond with coinID and returns the values used to create it.
func (*ExchangeWalletElectrum) FindRedemption ¶ added in v0.5.0
func (btc *ExchangeWalletElectrum) FindRedemption(ctx context.Context, coinID, contract dex.Bytes) (redemptionCoin, secret dex.Bytes, err error)
FindRedemption locates a swap contract output's redemption transaction input and the secret key used to spend the output.
func (ExchangeWalletElectrum) FundMultiOrder ¶ added in v1.0.0
func (btc ExchangeWalletElectrum) FundMultiOrder(mo *asset.MultiOrder, maxLock uint64) ([]asset.Coins, [][]dex.Bytes, uint64, error)
FundMultiOrder funds multiple orders in one shot. MaxLock is the maximum amount that the wallet can lock for these orders. If maxLock == 0, then there is no limit. An error is returned if the wallet does not have enough available balance to fund each of the orders, however, if splitting is not enabled and all of the orders cannot be funded due to mismatches in UTXO sizes, the orders that can be funded are funded. It will fail on the first order that cannot be funded. The returned values will always be in the same order as the Values in the parameter. If the length of the returned orders is shorter than what was passed in, it means that the orders at the end of the list were unable to be funded.
func (ExchangeWalletElectrum) FundOrder ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) FundOrder(ord *asset.Order) (asset.Coins, []dex.Bytes, uint64, 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 (ExchangeWalletElectrum) FundingCoins ¶ added in v0.5.0
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 (ExchangeWalletElectrum) GetBestBlockHeight ¶ added in v0.5.0
GetBestBlockHeight is exported for use by clone wallets. Not part of the asset.Wallet interface.
func (ExchangeWalletElectrum) Info ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) Info() *asset.WalletInfo
Info returns basic information about the wallet and asset.
func (ExchangeWalletElectrum) IsDust ¶ added in v0.5.0
IsDust checks if the tx output's value is dust. If the dustLimit is set, it is compared against that, otherwise the formula in dexbtc.IsDust is used.
func (ExchangeWalletElectrum) Lock ¶ added in v0.5.0
func (a ExchangeWalletElectrum) Lock() error
Lock locks the underlying bitcoind wallet. It implements asset.authenticator.
func (ExchangeWalletElectrum) LockTimeExpired ¶ added in v0.6.0
func (btc ExchangeWalletElectrum) LockTimeExpired(_ context.Context, lockTime time.Time) (bool, error)
LockTimeExpired returns true if the specified locktime has expired, making it possible to refund the locked coins.
func (ExchangeWalletElectrum) Locked ¶ added in v0.5.0
func (a ExchangeWalletElectrum) Locked() bool
Locked will be true if the wallet is currently locked. It implements asset.authenticator.
func (ExchangeWalletElectrum) MakeBondTx ¶ added in v0.6.0
func (btc ExchangeWalletElectrum) 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 (ExchangeWalletElectrum) MaxFundingFees ¶ added in v1.0.0
func (btc ExchangeWalletElectrum) MaxFundingFees(numTrades uint32, feeRate uint64, options map[string]string) uint64
MaxFundingFees returns the maximum funding fees for an order/multi-order.
func (ExchangeWalletElectrum) MaxOrder ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) 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 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. lotSize must not be zero and will cause a panic if so.
func (ExchangeWalletElectrum) NewAddress ¶ added in v0.5.0
NewAddress returns a new address from the wallet. This satisfies the NewAddresser interface.
func (ExchangeWalletElectrum) OwnsDepositAddress ¶ added in v0.5.0
OwnsDepositAddress indicates if the provided address can be used to deposit funds into the wallet.
func (ExchangeWalletElectrum) PreRedeem ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) PreRedeem(form *asset.PreRedeemForm) (*asset.PreRedeem, error)
PreRedeem generates an estimate of the range of redemption fees that could be assessed.
func (ExchangeWalletElectrum) PreSwap ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) PreSwap(req *asset.PreSwapForm) (*asset.PreSwap, error)
PreSwap get order estimates and order options based on the available funds and user-selected options.
func (ExchangeWalletElectrum) Reconfigure ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) Reconfigure(ctx context.Context, cfg *asset.WalletConfig, currentAddress string) (restart bool, err error)
Reconfigure attempts to reconfigure the wallet.
func (ExchangeWalletElectrum) Redeem ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) Redeem(form *asset.RedeemForm) ([]dex.Bytes, asset.Coin, uint64, error)
Redeem sends the redemption transaction, completing the atomic swap.
func (*ExchangeWalletElectrum) RedemptionAddress ¶ added in v0.5.0
func (btc *ExchangeWalletElectrum) RedemptionAddress() (string, error)
RedemptionAddress gets an address for use in redeeming the counterparty's swap. This would be included in their swap initialization. The address will be unused but not necessarily new because these addresses often go unused.
func (ExchangeWalletElectrum) Refund ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) Refund(coinID, contract dex.Bytes, feeRate uint64) (dex.Bytes, error)
Refund revokes 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. 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 (ExchangeWalletElectrum) RefundBond ¶ added in v0.6.0
func (btc ExchangeWalletElectrum) 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 (ExchangeWalletElectrum) RegFeeConfirmations ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) RegFeeConfirmations(_ context.Context, id dex.Bytes) (confs uint32, err error)
RegFeeConfirmations gets the number of confirmations for the specified output by first checking for a unspent output, and if not found, searching indexed wallet transactions.
func (ExchangeWalletElectrum) ReturnCoins ¶ added in v0.5.0
ReturnCoins unlocks coins. This would be used in the case of a canceled or partially filled order. Part of the asset.Wallet interface.
func (ExchangeWalletElectrum) ReturnRedemptionAddress ¶ added in v1.0.0
func (btc ExchangeWalletElectrum) ReturnRedemptionAddress(addr string)
ReturnRedemptionAddress accepts a Wallet.RedemptionAddress() if the address will not be used.
func (ExchangeWalletElectrum) ReturnRefundContracts ¶ added in v1.0.0
func (btc ExchangeWalletElectrum) ReturnRefundContracts(contracts [][]byte)
ReturnRefundContracts should be called with the Receipt.Contract() data for any swaps that will not be refunded.
func (ExchangeWalletElectrum) 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 sats/byte.
func (ExchangeWalletElectrum) SendTransaction ¶ added in v0.6.0
SendTransaction broadcasts a valid fully-signed transaction.
func (ExchangeWalletElectrum) SetBondReserves ¶ added in v1.0.0
func (btc ExchangeWalletElectrum) SetBondReserves(reserves uint64)
func (ExchangeWalletElectrum) SignMessage ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) 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 unspent coin. A slice of pubkeys required to spend the coin and a signature for each pubkey are returned.
func (ExchangeWalletElectrum) SingleLotRedeemFees ¶ added in v0.6.0
func (btc ExchangeWalletElectrum) SingleLotRedeemFees(_ uint32, feeSuggestion uint64) (uint64, error)
SingleLotRedeemFees returns the fees for a redeem transaction for a single lot.
func (ExchangeWalletElectrum) SingleLotSwapRefundFees ¶ added in v1.0.0
func (btc ExchangeWalletElectrum) 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 (ExchangeWalletElectrum) StandardSendFee ¶ added in v1.0.0
StandardSendFees returns the fees for a simple send tx with one input and two outputs.
func (ExchangeWalletElectrum) Swap ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) Swap(swaps *asset.Swaps) ([]asset.Receipt, asset.Coin, uint64, error)
Swap sends the swaps in a single transaction and prepares the receipts. The Receipts returned can be used to refund a failed transaction. The Input coins are NOT manually unlocked because they're auto-unlocked when the transaction is broadcasted.
func (ExchangeWalletElectrum) SwapConfirmations ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) SwapConfirmations(_ context.Context, id dex.Bytes, contract dex.Bytes, startTime time.Time) (uint32, bool, error)
SwapConfirmations gets the number of confirmations for the specified swap by first checking for a unspent output, and if not found, searching indexed wallet transactions.
func (ExchangeWalletElectrum) SyncStatus ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) SyncStatus() (*asset.SyncStatus, error)
SyncStatus is information about the blockchain sync status.
func (*ExchangeWalletElectrum) TxHistory ¶ added in v1.0.0
func (btc *ExchangeWalletElectrum) 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 (ExchangeWalletElectrum) Unlock ¶ added in v0.5.0
Unlock unlocks the underlying wallet. The pw supplied should be the same as the password for the underlying bitcoind wallet which will also be unlocked. It implements asset.authenticator.
func (ExchangeWalletElectrum) UseSplitTx ¶ added in v1.0.0
func (w ExchangeWalletElectrum) UseSplitTx() bool
func (ExchangeWalletElectrum) ValidateAddress ¶ added in v0.6.0
ValidateAddress checks that the provided address is valid.
func (ExchangeWalletElectrum) ValidateSecret ¶ added in v0.5.0
ValidateSecret checks that the secret satisfies the contract.
func (*ExchangeWalletElectrum) WalletTransaction ¶ added in v1.0.0
func (btc *ExchangeWalletElectrum) 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 can be either a byte reversed tx hash or a hex encoded coin ID.
func (ExchangeWalletElectrum) Withdraw ¶ added in v0.5.0
func (btc ExchangeWalletElectrum) Withdraw(address string, value, feeRate uint64) (asset.Coin, error)
Withdraw withdraws funds to the specified address. Fees are subtracted from the value. feeRate is in units of sats/byte. Withdraw satisfies asset.Withdrawer.
type ExchangeWalletFullNode ¶ added in v0.4.3
type ExchangeWalletFullNode struct {
// contains filtered or unexported fields
}
ExchangeWalletFullNode implements Wallet and adds the FeeRate method.
func BTCCloneWallet ¶
func BTCCloneWallet(cfg *BTCCloneCFG) (*ExchangeWalletFullNode, error)
BTCCloneWallet creates a wallet backend for a set of network parameters and default network ports. A BTC clone can use this method, possibly in conjunction with ReadCloneParams, to create a ExchangeWallet for other assets with minimal coding.
func (ExchangeWalletFullNode) Connect ¶ added in v0.4.3
Connect connects the wallet to the btc.Wallet backend and starts monitoring blocks and peers. Satisfies the dex.Connector interface.
func (ExchangeWalletFullNode) EstimateSendTxFee ¶ added in v0.6.0
func (btc ExchangeWalletFullNode) 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 (ExchangeWalletFullNode) FeesForRemainingSwaps ¶ added in v0.6.0
FeesForRemainingSwaps returns the fees for a certain number of swaps at a given feeRate. This is only accurate if each swap has a single input. Accurate estimates should use PreSwap or FundOrder.
func (ExchangeWalletFullNode) FindBond ¶ added in v1.0.0
func (btc ExchangeWalletFullNode) 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. The intermediate wallet is able to brute force finding blocks.
func (ExchangeWalletFullNode) FindRedemption ¶ added in v0.4.3
func (btc ExchangeWalletFullNode) 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 (ExchangeWalletFullNode) Lock ¶ added in v0.4.3
func (a ExchangeWalletFullNode) Lock() error
Lock locks the underlying bitcoind wallet. It implements asset.authenticator.
func (ExchangeWalletFullNode) Locked ¶ added in v0.4.3
func (a ExchangeWalletFullNode) Locked() bool
Locked will be true if the wallet is currently locked. It implements asset.authenticator.
func (ExchangeWalletFullNode) TxHistory ¶ added in v1.0.0
func (btc ExchangeWalletFullNode) 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 (ExchangeWalletFullNode) Unlock ¶ added in v0.4.3
Unlock unlocks the underlying wallet. The pw supplied should be the same as the password for the underlying bitcoind wallet which will also be unlocked. It implements asset.authenticator.
func (ExchangeWalletFullNode) WalletTransaction ¶ added in v1.0.0
func (btc ExchangeWalletFullNode) 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 can be either a byte reversed tx hash or a hex encoded coin ID.
type ExchangeWalletNoAuth ¶ added in v1.0.0
type ExchangeWalletNoAuth struct {
// contains filtered or unexported fields
}
func BTCCloneWalletNoAuth ¶ added in v1.0.0
func BTCCloneWalletNoAuth(cfg *BTCCloneCFG) (*ExchangeWalletNoAuth, error)
BTCCloneWalletNoAuth is like BTCCloneWallet but the wallet created does not implement asset.Authenticator.
func (ExchangeWalletNoAuth) Connect ¶ added in v1.0.0
Connect connects the wallet to the btc.Wallet backend and starts monitoring blocks and peers. Satisfies the dex.Connector interface.
func (ExchangeWalletNoAuth) EstimateSendTxFee ¶ added in v1.0.0
func (btc ExchangeWalletNoAuth) 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 (ExchangeWalletNoAuth) FeesForRemainingSwaps ¶ added in v1.0.0
FeesForRemainingSwaps returns the fees for a certain number of swaps at a given feeRate. This is only accurate if each swap has a single input. Accurate estimates should use PreSwap or FundOrder.
func (ExchangeWalletNoAuth) FindBond ¶ added in v1.0.0
func (btc ExchangeWalletNoAuth) 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. The intermediate wallet is able to brute force finding blocks.
func (ExchangeWalletNoAuth) FindRedemption ¶ added in v1.0.0
func (btc ExchangeWalletNoAuth) 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 (ExchangeWalletNoAuth) TxHistory ¶ added in v1.0.0
func (btc ExchangeWalletNoAuth) 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 (ExchangeWalletNoAuth) WalletTransaction ¶ added in v1.0.0
func (btc ExchangeWalletNoAuth) 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 can be either a byte reversed tx hash or a hex encoded coin ID.
type ExchangeWalletSPV ¶ added in v0.4.1
type ExchangeWalletSPV struct {
// contains filtered or unexported fields
}
ExchangeWalletSPV embeds a ExchangeWallet, but also provides the Rescan method to implement asset.Rescanner.
func OpenSPVWallet ¶ added in v0.6.0
func OpenSPVWallet(cfg *BTCCloneCFG, walletConstructor BTCWalletConstructor) (*ExchangeWalletSPV, error)
OpenSPVWallet opens the previously created native SPV wallet.
func (*ExchangeWalletSPV) AccelerateOrder ¶ added in v0.5.0
func (btc *ExchangeWalletSPV) AccelerateOrder(swapCoins, accelerationCoins []dex.Bytes, changeCoin dex.Bytes, requiredForRemainingSwaps, newFeeRate uint64) (asset.Coin, string, error)
AccelerateOrder uses the Child-Pays-For-Parent technique to accelerate a chain of swap transactions and previous accelerations. It broadcasts a new transaction with a fee high enough so that the average fee of all the unconfirmed transactions in the chain and the new transaction will have an average fee rate of newFeeRate. The changeCoin argument is the latest change in the order. It must be the input in the acceleration transaction in order for the order to be accelerated. requiredForRemainingSwaps is the amount of funds required to complete the rest of the swaps in the order. The change output of the acceleration transaction will have at least this amount.
The returned change coin may be nil, and should be checked before use.
func (*ExchangeWalletSPV) AccelerationEstimate ¶ added in v0.5.0
func (btc *ExchangeWalletSPV) AccelerationEstimate(swapCoins, accelerationCoins []dex.Bytes, changeCoin dex.Bytes, requiredForRemainingSwaps, newFeeRate uint64) (uint64, error)
AccelerationEstimate takes the same parameters as AccelerateOrder, but instead of broadcasting the acceleration transaction, it just returns the amount of funds that will need to be spent in order to increase the average fee rate to the desired amount.
func (*ExchangeWalletSPV) AddPeer ¶ added in v0.6.0
func (btc *ExchangeWalletSPV) AddPeer(addr string) error
AddPeer connects the wallet to a new peer. The peer's address will be persisted and connected to each time the wallet is started up.
func (ExchangeWalletSPV) Connect ¶ added in v0.4.3
Connect connects the wallet to the btc.Wallet backend and starts monitoring blocks and peers. Satisfies the dex.Connector interface.
func (ExchangeWalletSPV) EstimateSendTxFee ¶ added in v0.6.0
func (btc ExchangeWalletSPV) 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 (ExchangeWalletSPV) FeesForRemainingSwaps ¶ added in v0.6.0
FeesForRemainingSwaps returns the fees for a certain number of swaps at a given feeRate. This is only accurate if each swap has a single input. Accurate estimates should use PreSwap or FundOrder.
func (ExchangeWalletSPV) FindBond ¶ added in v1.0.0
func (btc ExchangeWalletSPV) 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. The intermediate wallet is able to brute force finding blocks.
func (ExchangeWalletSPV) FindRedemption ¶ added in v0.4.3
func (btc ExchangeWalletSPV) 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 (*ExchangeWalletSPV) GetRecoveryCfg ¶ added in v0.5.0
func (btc *ExchangeWalletSPV) GetRecoveryCfg() (map[string]string, error)
GetRecoveryCfg returns information that will help the wallet get back to its previous state after it is recreated. Part of the Recoverer interface.
func (ExchangeWalletSPV) Lock ¶ added in v0.4.3
func (a ExchangeWalletSPV) Lock() error
Lock locks the underlying bitcoind wallet. It implements asset.authenticator.
func (ExchangeWalletSPV) Locked ¶ added in v0.4.3
func (a ExchangeWalletSPV) Locked() bool
Locked will be true if the wallet is currently locked. It implements asset.authenticator.
func (*ExchangeWalletSPV) LogFilePath ¶ added in v0.4.1
func (btc *ExchangeWalletSPV) LogFilePath() string
LogFilePath returns the path to the neutrino log file.
func (*ExchangeWalletSPV) Move ¶ added in v0.5.0
func (btc *ExchangeWalletSPV) Move(backupDir string) error
Destroy will delete all the wallet files so the wallet can be recreated. Part of the Recoverer interface.
func (*ExchangeWalletSPV) Peers ¶ added in v0.6.0
func (btc *ExchangeWalletSPV) Peers() ([]*asset.WalletPeer, error)
Peers returns a list of peers that the wallet is connected to.
func (*ExchangeWalletSPV) PreAccelerate ¶ added in v0.5.0
func (btc *ExchangeWalletSPV) PreAccelerate(swapCoins, accelerationCoins []dex.Bytes, changeCoin dex.Bytes, requiredForRemainingSwaps, feeSuggestion uint64) (uint64, *asset.XYRange, *asset.EarlyAcceleration, error)
PreAccelerate returns the current average fee rate of the unmined swap initiation and acceleration transactions, and also returns a suggested range that the fee rate should be increased to in order to expedite mining. The feeSuggestion argument is the current prevailing network rate. It is used to help determine the suggestedRange, which is a range meant to give the user a good amount of flexibility in determining the post acceleration effective fee rate, but still not allowing them to pick something outrageously high.
func (*ExchangeWalletSPV) RemovePeer ¶ added in v0.6.0
func (btc *ExchangeWalletSPV) RemovePeer(addr string) error
RemovePeer will remove a peer that was added by AddPeer. This peer may still be connected to by the wallet if it discovers it on it's own.
func (*ExchangeWalletSPV) Rescan ¶ added in v0.4.1
func (btc *ExchangeWalletSPV) Rescan(_ context.Context, _ uint64) error
Rescan satisfies the asset.Rescanner interface, and issues a rescan wallet command if the backend is an SPV wallet.
func (ExchangeWalletSPV) TxHistory ¶ added in v1.0.0
func (btc ExchangeWalletSPV) 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 (ExchangeWalletSPV) Unlock ¶ added in v0.4.3
Unlock unlocks the underlying wallet. The pw supplied should be the same as the password for the underlying bitcoind wallet which will also be unlocked. It implements asset.authenticator.
func (ExchangeWalletSPV) WalletTransaction ¶ added in v1.0.0
func (btc ExchangeWalletSPV) 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 can be either a byte reversed tx hash or a hex encoded coin ID.
type ExtendedWalletTx ¶ added in v1.0.0
type ExtendedWalletTx struct { *asset.WalletTransaction // Create bond transactions are added to the store before // they are submitted. Submitted bool `json:"submitted"` }
type FindRedemptionReq ¶ added in v1.0.0
type FindRedemptionReq struct {
// contains filtered or unexported fields
}
FindRedemptionReq represents a request to find a contract's redemption, which is submitted to the RedemptionFinder.
type FindRedemptionResult ¶ added in v1.0.0
type FindRedemptionResult struct {
// contains filtered or unexported fields
}
FindRedemptionResult models the result of a find redemption attempt.
type GetAddressInfoResult ¶
type GetAddressInfoResult struct { IsMine bool `json:"ismine"` Descriptor string `json:"desc"` // e.g. "wpkh([b940190e/84'/1'/0'/0/0]0300034...)#0pfw7rck" ParentDesc string `json:"parent_desc"` // e.g. "wpkh([b940190e/84'/1'/0']tpubDCo.../0/*)#xn4kr3dw" meaning range of external addresses HDKeyPath string `json:"hdkeypath"` // e.g. "m/84'/1'/0'/0/0" HDMasterFingerprint string `json:"hdmasterfingerprint"` // e.g. "b940190e" }
GetAddressInfoResult models some of the data from the getaddressinfo command.
type GetBalancesResult ¶
GetBalancesResult models a successful response from the getbalances request.
type GetBlockchainInfoResult ¶ added in v1.0.0
type GetBlockchainInfoResult struct { Chain string `json:"chain"` Blocks int64 `json:"blocks"` Headers int64 `json:"headers"` BestBlockHash string `json:"bestblockhash"` // InitialBlockDownload will be true if the node is still in the initial // block download mode. InitialBlockDownload *bool `json:"initialblockdownload"` // InitialBlockDownloadComplete will be true if this node has completed its // initial block download and is expected to be synced to the network. // Zcash uses this terminology instead of initialblockdownload. InitialBlockDownloadComplete *bool `json:"initial_block_download_complete"` }
GetBlockchainInfoResult models the data returned from the getblockchaininfo command.
func (*GetBlockchainInfoResult) Syncing ¶ added in v1.0.0
func (r *GetBlockchainInfoResult) Syncing() bool
type GetTransactionResult ¶
type GetTransactionResult struct { // The meaning of Amount and Fee for "wallet" transactions is iffy (and they // are unused), so we are going to ignore them. We have the raw tx (Hex) if // it is necessary to compute amounts from the inputs and outputs. // Amount float64 `json:"amount"` // Fee float64 `json:"fee"` Confirmations uint64 `json:"confirmations"` BlockHash string `json:"blockhash"` BlockIndex int64 `json:"blockindex"` // unused, consider commenting BlockTime uint64 `json:"blocktime"` // BlockHeight uint64 `json:"blockheight"` // unused, potentially work to obtain TxID string `json:"txid"` Time uint64 `json:"time"` TimeReceived uint64 `json:"timereceived"` Bytes dex.Bytes `json:"hex"` // []byte, although it marshals/unmarshals a hex string }
GetTransactionResult models the required data from the gettransaction command. Several fields from the bitcoind/btcwallet response that are both unneeded and difficult to satisfy are omitted. e.g. the native btcwallet and the external Electrum backends must jump through hoops to reproduce certain fields that are not strictly necessary.
type GetWalletInfoResult ¶
type GetWalletInfoResult struct { WalletName string `json:"walletname"` WalletVersion uint32 `json:"walletversion"` Format string `json:"format"` Balance float64 `json:"balance"` UnconfirmedBalance float64 `json:"unconfirmed_balance"` ImmatureBalance float64 `json:"immature_balance"` TxCount uint32 `json:"txcount"` KeyPoolOldest uint64 `json:"keypoololdest"` KeyPoolSize uint32 `json:"keypoolsize"` KeyPoolSizeHDInternal uint32 `json:"keypoolsize_hd_internal"` PayTxFee float64 `json:"paytxfee"` HdSeedID string `json:"hdseedid"` // UnlockedUntil is a pointer because for encrypted locked wallets, it will // be zero, but for unencrypted wallets the field won't be present in the // response. UnlockedUntil *int64 `json:"unlocked_until"` // HDMasterKeyID is dropped in Bitcoin Core 0.18 HdMasterKeyID string `json:"hdmasterkeyid"` PriveyKeysEnabled bool `json:"private_keys_enabled"` // AvoidReuse and Scanning were added in Bitcoin Core 0.19 AvoidReuse bool `json:"avoid_reuse"` // Scanning is either a struct or boolean false, and since we're not using // it, commenting avoids having to deal with marshaling for now. // Scanning struct { // Duration uint32 `json:"duration"` // Progress float32 `json:"progress"` // } `json:"scanning"` Descriptors bool `json:"descriptors"` // Descriptor wallets that do not support dumpprivkey }
GetWalletInfoResult models the data from the getwalletinfo command.
type ListTransactionsResult ¶ added in v1.0.0
type ListTransactionsResult struct { BlockHeight uint32 `json:"blockheight"` BlockTime uint64 `json:"blocktime"` Fee *float64 `json:"fee,omitempty"` // Send set to true means that the inputs of the transaction were // controlled by the wallet. Send bool `json:"send"` TxID string `json:"txid"` }
ListTransactionsResult is similar to the btcjson.ListTransactionsResult, but most fields omitted.
type ListUnspentResult ¶
type ListUnspentResult struct { TxID string `json:"txid"` Vout uint32 `json:"vout"` Address string `json:"address"` Label string `json:"label"` ScriptPubKey dex.Bytes `json:"scriptPubKey"` Amount float64 `json:"amount"` Confirmations uint32 `json:"confirmations"` RedeemScript dex.Bytes `json:"redeemScript"` Spendable bool `json:"spendable"` Solvable bool `json:"solvable"` SafePtr *bool `json:"safe"` }
ListUnspentResult models a successful response from the listunspent request.
func (*ListUnspentResult) Safe ¶
func (l *ListUnspentResult) Safe() bool
type OrderEstimator ¶ added in v1.0.0
OrderEstimator is a function that accepts information about an order and estimates the total required funds needed for the order.
type OrderFundingThresholder ¶ added in v1.0.0
type OrderFundingThresholder func(val, lots, maxFeeRate uint64, reportChange bool) EnoughFunc
OrderFundingThresholder accepts information about an order and generates an EnoughFunc that can be used to test funding input combinations.
type OutPoint ¶ added in v1.0.0
OutPoint is the hash and output index of a transaction output.
func NewOutPoint ¶ added in v1.0.0
NewOutPoint is the constructor for a new OutPoint.
type Output ¶ added in v1.0.0
Output is information about a transaction Output. Output satisfies the asset.Coin interface.
func ConvertCoin ¶ added in v1.0.0
ConvertCoin converts the asset.Coin to an Output.
func (*Output) ID ¶ added in v1.0.0
ID is the Output's coin ID. Part of the asset.Coin interface. For BTC, the coin ID is 36 bytes = 32 bytes tx hash + 4 bytes big-endian vout.
func (*Output) Value ¶ added in v1.0.0
Value returns the value of the Output. Part of the asset.Coin interface.
func (*Output) WireOutPoint ¶ added in v1.0.0
WireOutPoint creates and returns a new *wire.OutPoint for the output.
type PeerManagerChainService ¶ added in v0.6.0
type PeerManagerChainService interface { AddPeer(addr string) error RemovePeer(addr string) error Peers() []SPVPeer }
PeerManagerChainService are the functions needed for an SPVPeerManager to communicate with a chain service.
type RPCOutpoint ¶
RPCOutpoint is used to specify outputs to lock in calls to lockunspent.
type RPCWalletConfig ¶ added in v0.4.0
type RPCWalletConfig struct { RPCConfig `ini:",extends"` WalletConfig `ini:",extends"` }
RPCWalletConfig is a combination of RPCConfig and WalletConfig. Used for a wallet based on a bitcoind-like RPC API.
type RawRequester ¶ added in v0.2.0
type RawRequester interface {
RawRequest(context.Context, string, []json.RawMessage) (json.RawMessage, error)
}
RawRequester defines decred's rpcclient RawRequest func where all RPC requests sent through. For testing, it can be satisfied by a stub.
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 RedemptionFinder ¶ added in v1.0.0
type RedemptionFinder struct {
// contains filtered or unexported fields
}
RedemptionFinder searches on-chain for the redemption of a swap transactions.
func NewRedemptionFinder ¶ added in v1.0.0
func NewRedemptionFinder( log dex.Logger, getWalletTransaction func(txHash *chainhash.Hash) (*GetTransactionResult, error), getBlockHeight func(*chainhash.Hash) (int32, error), getBlock func(h chainhash.Hash) (*wire.MsgBlock, error), getBlockHeader func(blockHash *chainhash.Hash) (hdr *BlockHeader, mainchain bool, err error), hashTx func(*wire.MsgTx) *chainhash.Hash, deserializeTx func([]byte) (*wire.MsgTx, error), getBestBlockHeight func() (int32, error), searchBlockForRedemptions func(ctx context.Context, reqs map[OutPoint]*FindRedemptionReq, blockHash chainhash.Hash) (discovered map[OutPoint]*FindRedemptionResult), getBlockHash func(blockHeight int64) (*chainhash.Hash, error), findRedemptionsInMempool func(ctx context.Context, reqs map[OutPoint]*FindRedemptionReq) (discovered map[OutPoint]*FindRedemptionResult), ) *RedemptionFinder
func (*RedemptionFinder) CancelRedemptionSearches ¶ added in v1.0.0
func (r *RedemptionFinder) CancelRedemptionSearches()
func (*RedemptionFinder) FindRedemption ¶ added in v1.0.0
func (*RedemptionFinder) ReportNewTip ¶ added in v1.0.0
func (r *RedemptionFinder) ReportNewTip(ctx context.Context, prevTip, newTip *BlockVector)
ReportNewTip sets the currentTip. The tipChange callback function is invoked and a goroutine is started to check if any contracts in the findRedemptionQueue are redeemed in the new blocks.
type SPVPeer ¶ added in v0.6.0
SPVPeer is satisfied by *neutrino.ServerPeer, but is generalized to accommodate underlying implementations other than lightninglabs/neutrino.
type SPVPeerManager ¶ added in v0.6.0
type SPVPeerManager struct {
// contains filtered or unexported fields
}
SPVPeerManager implements peer management functionality for all bitcoin clone SPV wallets.
func NewSPVPeerManager ¶ added in v0.6.0
func NewSPVPeerManager(cs PeerManagerChainService, defaultPeers []string, dir string, log dex.Logger, defaultPort string) *SPVPeerManager
NewSPVPeerManager creates a new SPVPeerManager.
func (*SPVPeerManager) AddPeer ¶ added in v0.6.0
func (s *SPVPeerManager) AddPeer(addr string) error
AddPeer connects to a new peer and stores it in the db.
func (*SPVPeerManager) ConnectToInitialWalletPeers ¶ added in v0.6.0
func (s *SPVPeerManager) ConnectToInitialWalletPeers()
ConnectToInitialWalletPeers connects to the default peers and the peers that were added by the user and persisted in the db.
func (*SPVPeerManager) Peers ¶ added in v0.6.0
func (s *SPVPeerManager) Peers() ([]*asset.WalletPeer, error)
Peers returns the list of peers that the wallet is connected to. It also returns the peers that the user added that the wallet may not currently be connected to.
func (*SPVPeerManager) RemovePeer ¶ added in v0.6.0
func (s *SPVPeerManager) RemovePeer(addr string) error
RemovePeer disconnects from a peer added by the user and removes it from the db.
type SPVService ¶ added in v0.6.0
type SPVService interface { GetBlockHash(int64) (*chainhash.Hash, error) BestBlock() (*headerfs.BlockStamp, error) Peers() []SPVPeer AddPeer(addr string) error GetBlockHeight(hash *chainhash.Hash) (int32, error) GetBlockHeader(*chainhash.Hash) (*wire.BlockHeader, error) GetCFilter(blockHash chainhash.Hash, filterType wire.FilterType, options ...neutrino.QueryOption) (*gcs.Filter, error) GetBlock(blockHash chainhash.Hash, options ...neutrino.QueryOption) (*btcutil.Block, error) Stop() error }
SPVService is satisfied by *neutrino.ChainService, with the exception of the Peers method, which has a generic interface in place of neutrino.ServerPeer.
type SignTxError ¶
type SignTxError struct { TxID string `json:"txid"` Vout uint32 `json:"vout"` ScriptSig dex.Bytes `json:"scriptSig"` Sequence uint64 `json:"sequence"` Error string `json:"error"` }
SignTxError models the data that contains script verification errors from the signrawtransaction request
type SignTxResult ¶
type SignTxResult struct { Hex dex.Bytes `json:"hex"` Complete bool `json:"complete"` Errors []*SignTxError `json:"errors"` }
SignTxResult models the data from the signrawtransaction command.
type SwapReceipt ¶ added in v1.0.0
type SwapReceipt struct { Output *Output SwapContract []byte SignedRefundBytes []byte ExpirationTime time.Time }
SwapReceipt is information about a swap contract that was broadcast by this wallet. Satisfies the asset.Receipt interface.
func (*SwapReceipt) Coin ¶ added in v1.0.0
func (r *SwapReceipt) Coin() asset.Coin
Coin is the output information as an asset.Coin. Part of the asset.Receipt interface.
func (*SwapReceipt) Contract ¶ added in v1.0.0
func (r *SwapReceipt) Contract() dex.Bytes
Contract is the contract script. Part of the asset.Receipt interface.
func (*SwapReceipt) Expiration ¶ added in v1.0.0
func (r *SwapReceipt) Expiration() time.Time
Expiration is the time that the contract will expire, allowing the user to issue a refund transaction. Part of the asset.Receipt interface.
func (*SwapReceipt) SignedRefund ¶ added in v1.0.0
func (r *SwapReceipt) SignedRefund() dex.Bytes
SignedRefund is a signed refund script that can be used to return funds to the user in the case a contract expires.
func (*SwapReceipt) String ¶ added in v1.0.0
func (r *SwapReceipt) String() string
String provides a human-readable representation of the contract's Coin.
type TxInSigner ¶ added in v0.2.0
type TxInSigner func(tx *wire.MsgTx, idx int, subScript []byte, hashType txscript.SigHashType, key *btcec.PrivateKey, vals []int64, prevScripts [][]byte) ([]byte, error)
TxInSigner is a transaction input signer. In addition to the standard Bitcoin arguments, TxInSigner receives all values and pubkey scripts for previous outpoints spent in this transaction.
type Wallet ¶ added in v0.4.0
type Wallet interface { RawRequester // for localFeeRate/rpcFeeRate calls // contains filtered or unexported methods }
Wallet is the interface that BTC wallet backends must implement. TODO: plumb all requests with a context.Context.
type WalletConfig ¶ added in v0.4.0
type WalletConfig struct { UseSplitTx bool `ini:"txsplit"` FallbackFeeRate float64 `ini:"fallbackfee"` FeeRateLimit float64 `ini:"feeratelimit"` RedeemConfTarget uint64 `ini:"redeemconftarget"` ActivelyUsed bool `ini:"special_activelyUsed"` // injected by core ApiFeeFallback bool `ini:"apifeefallback"` }
WalletConfig are wallet-level configuration settings.
type XCWalletAccount ¶ added in v1.0.0
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package electrum provides a client for an ElectrumX server.
|
Package electrum provides a client for an ElectrumX server. |