Documentation ¶
Index ¶
- Constants
- func Assets() map[uint32]*RegisteredAsset
- func CreateWallet(assetID uint32, seedParams *CreateWalletParams) error
- func DecodeCoinID(assetID uint32, coinID []byte) (cid string, err error)
- func FormatAtoms(assetID uint32, atoms uint64) string
- func IncomingTxType(txType TransactionType) bool
- func MinimumLotSize(assetID uint32, maxFeeRate uint64) (minLotSize uint64, found bool)
- func Register(assetID uint32, driver Driver)
- func RegisterSPVWithdrawFunc(assetID uint32, f spvWithdrawFunc)
- func RegisterToken(tokenID uint32, token *dex.Token, walletDef *WalletDefinition, ...)
- func SPVWithdrawTx(ctx context.Context, assetID uint32, walletPW []byte, ...) ([]byte, error)
- func SetNetwork(net dex.Network)
- func UnitInfo(assetID uint32) (dex.UnitInfo, error)
- func WalletExists(assetID uint32, walletType, dataDir string, settings map[string]string, ...) (exists bool, err error)
- type Accelerator
- type AccountLocker
- type ActionRequiredNote
- type ActionResolvedNote
- type ActionTaker
- type AddressReturner
- type ApprovalStatus
- type AuditInfo
- type Authenticator
- type Balance
- type BalanceCategory
- type BalanceChangeNote
- type Bond
- type BondDetails
- type BondTxInfo
- type Bonder
- type BooleanConfig
- type Broadcaster
- type Coin
- type Coins
- type ConfigOption
- type ConfirmRedemptionStatus
- type Contract
- type CreateWalletParams
- type Creator
- type CustomBalance
- type CustomWalletNote
- type Driver
- type DynamicSwapper
- type EarlyAcceleration
- type FeeRater
- type FundsMixer
- type FundsMixingStats
- type GeocodeRedeemer
- type LiveReconfigurer
- type LogFiler
- type MaxOrderForm
- type MultiOrder
- type MultiOrderValue
- type NewAddresser
- type Order
- type OrderOption
- type PeerManager
- type PeerSource
- type PreRedeem
- type PreRedeemForm
- type PreSwap
- type PreSwapForm
- type Receipt
- type Recoverer
- type RecoveryCoin
- type RedeemEstimate
- type RedeemForm
- type Redemption
- type RegisteredAsset
- type Rescanner
- type Stances
- type SwapEstimate
- type Swaps
- type Sweeper
- type SyncStatus
- type TBAgenda
- type TBChoice
- type TBTreasurySpend
- type Ticket
- type TicketBuyer
- type TicketStakingStatus
- type TicketStats
- type TicketStatus
- type TicketTransaction
- type TipChangeNote
- type Token
- type TokenApprover
- type TokenCoin
- type TokenConfig
- type TokenMaster
- type TransactionNote
- type TransactionType
- type TxFeeEstimator
- type VotingServiceProvider
- type Wallet
- type WalletConfig
- type WalletDefinition
- type WalletEmitter
- func (e *WalletEmitter) ActionRequired(uniqueID, actionID string, payload any)
- func (e *WalletEmitter) ActionResolved(uniqueID string)
- func (e *WalletEmitter) BalanceChange(bal *Balance)
- func (e *WalletEmitter) Data(route string, payload any)
- func (e *WalletEmitter) TipChange(tip uint64, datas ...any)
- func (e *WalletEmitter) TransactionHistorySyncedNote()
- func (e *WalletEmitter) TransactionNote(tx *WalletTransaction, new bool)
- type WalletHistorian
- type WalletInfo
- type WalletNotification
- type WalletPeer
- type WalletRestoration
- type WalletRestorer
- type WalletTrait
- func (wt WalletTrait) IsAccelerator() bool
- func (wt WalletTrait) IsAccountLocker() bool
- func (wt WalletTrait) IsAuthenticator() bool
- func (wt WalletTrait) IsDynamicSwapper() bool
- func (wt WalletTrait) IsFeeRater() bool
- func (wt WalletTrait) IsFundsMixer() bool
- func (wt WalletTrait) IsHistorian() bool
- func (wt WalletTrait) IsLogFiler() bool
- func (wt WalletTrait) IsNewAddresser() bool
- func (wt WalletTrait) IsPeerManager() bool
- func (wt WalletTrait) IsRecoverer() bool
- func (wt WalletTrait) IsRescanner() bool
- func (wt WalletTrait) IsRestorer() bool
- func (wt WalletTrait) IsSweeper() bool
- func (wt WalletTrait) IsTicketBuyer() bool
- func (wt WalletTrait) IsTokenApprover() bool
- func (wt WalletTrait) IsTxFeeEstimator() bool
- func (wt WalletTrait) IsWithdrawer() bool
- type WalletTransaction
- type Withdrawer
- type XYRange
- type XYRangePoint
Constants ¶
const ( // ErrSwapNotInitiated most likely means that a swap using a contract has // not yet been mined. There is no guarantee that the swap will be mined // in the future. ErrSwapNotInitiated = dex.ErrorKind("swap not yet initiated") CoinNotFoundError = dex.ErrorKind("coin not found") // ErrTxRejected is returned when a transaction was rejected. This // generally would indicate either an internal wallet error, or potentially // a user using multiple instances of the wallet simultaneously. As such // it may or may not be advisable to try the tx again without seeking // further investigation. ErrTxRejected = dex.ErrorKind("transaction was rejected") // ErrTxLost is returned when the tx is irreparably lost, as would be the // case if it's inputs were spent by another tx first or if it is not the // accepted tx for a given nonce. These txs have incurred no fee losses, so // the caller should feel free to re-issue the tx. ErrTxLost = dex.ErrorKind("tx lost") ErrRequestTimeout = dex.ErrorKind("request timeout") ErrConnectionDown = dex.ErrorKind("wallet not connected") ErrNotImplemented = dex.ErrorKind("not implemented") ErrUnsupported = dex.ErrorKind("unsupported") // ErrSwapRefunded is returned from ConfirmRedemption when the swap has // been refunded before the user could redeem. ErrSwapRefunded = dex.ErrorKind("swap refunded") // ErrNotEnoughConfirms is returned when a transaction is confirmed, // but does not have enough confirmations to be trusted. ErrNotEnoughConfirms = dex.ErrorKind("transaction does not have enough confirmations") // ErrWalletTypeDisabled indicates that a wallet type is no longer // available. ErrWalletTypeDisabled = dex.ErrorKind("wallet type has been disabled") // ErrInsufficientBalance is returned when there is insufficient available // balance for an operation, such as reserving funds for future bonds. ErrInsufficientBalance = dex.ErrorKind("insufficient available balance") // ErrIncorrectBondKey is returned when a provided private key is incorrect // for a bond output. ErrIncorrectBondKey = dex.ErrorKind("incorrect private key") // ErrUnapprovedToken is returned when trying to fund an order using a token // that has not been approved. ErrUnapprovedToken = dex.ErrorKind("token not approved") ErrApprovalPending = dex.ErrorKind("approval pending") // InternalNodeLoggerName is the name for a logger that is used to fine // tune log levels for only loggers using this name. InternalNodeLoggerName = "INTL" // VersionNewest can be passed to some estimation methods to instruct the // wallet to use whatever is the newest version available. VersionNewest = ^uint32(0) )
CoinNotFoundError is returned when a coin cannot be found, either because it has been spent or it never existed. This error may be returned from AuditContract, Refund or Redeem as those methods expect the provided coin to exist and be unspent.
const ( BalanceCategoryShielded = "Shielded" BalanceCategoryUnmixed = "Unmixed" BalanceCategoryStaked = "Staked" )
Balance categories for custom balances These values are used as a map key for custom balances and may be recognized in the frontend to support translation. It is recommended for custom balance categories listed here to have a translation and tooltip info in client/webserver/site/src/js/wallet.js#customWalletBalanceCategory. If any of these balance categories should change, the customWalletBalanceCategory function in the wallet.js file above should be updated with the new value.
const ActionResolved = "actionResolved"
ActionResolved is sent by wallets when action is no longer required for a unique ID.
const ( // SpecialSettingActivelyUsed is a special setting that can be injected by // core that lets the wallet know that it is being actively used. A use // case is by the bitcoin SPV wallet to decide whether or not it is safe // to do a full rescan. SpecialSettingActivelyUsed = "special_activelyUsed" )
Variables ¶
This section is empty.
Functions ¶
func Assets ¶
func Assets() map[uint32]*RegisteredAsset
Assets returns a list of information about supported assets.
func CreateWallet ¶ added in v0.4.0
func CreateWallet(assetID uint32, seedParams *CreateWalletParams) error
CreateWallet creates a new wallet. Only use Create for seeded wallet types.
func DecodeCoinID ¶
DecodeCoinID creates a human-readable representation of a coin ID for a named asset with a corresponding driver registered with this package. For now, token id decoding is deferred to the parent asset.
func FormatAtoms ¶ added in v1.0.0
func IncomingTxType ¶ added in v1.0.0
func IncomingTxType(txType TransactionType) bool
IncomingTxType returns true if the wallet's balance increases due to a transaction.
func MinimumLotSize ¶ added in v1.0.0
MinimumLotSize returns the minimimum lot size for a registered asset.
func RegisterSPVWithdrawFunc ¶ added in v1.0.0
func RegisterSPVWithdrawFunc(assetID uint32, f spvWithdrawFunc)
RegisterSPVWithdrawFunc registers the function to genreate a withdraw transaction that spends funds from a deprecated SPV wallet.
func RegisterToken ¶ added in v0.5.0
func RegisterToken(tokenID uint32, token *dex.Token, walletDef *WalletDefinition, addrs map[dex.Network]string)
RegisterToken should be called to register tokens. If no nets are specified the token will be registered for all networks. The user must invoke SetNetwork to enable net-based filtering of package function output.
func SPVWithdrawTx ¶ added in v1.0.0
func SPVWithdrawTx(ctx context.Context, assetID uint32, walletPW []byte, recipient, dataDir string, net dex.Network, log dex.Logger) ([]byte, error)
SPVWithdrawTx generates a transaction that spends all funds from a deprecated spv wallet.
func SetNetwork ¶ added in v0.6.0
SetNetwork will filter registered assets for those available on the specified network. SetNetwork need only be called once during initialization.
Types ¶
type Accelerator ¶ added in v0.5.0
type Accelerator interface { // FeesForRemainingSwaps returns the fees for a certain number of // chained/grouped swaps at a given feeRate. This should be used with an // Accelerator wallet to help compute the required amount for remaining // swaps for a given trade with a mix of future and active matches, which is // only known to the consumer. This is only accurate if each swap has a // single input or chained swaps all pay the same fees. Accurate estimates // for new orders without existing funding should use PreSwap or FundOrder. FeesForRemainingSwaps(n, feeRate uint64) uint64 // 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. AccelerateOrder(swapCoins, accelerationCoins []dex.Bytes, changeCoin dex.Bytes, requiredForRemainingSwaps, newFeeRate uint64) (Coin, string, 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. AccelerationEstimate(swapCoins, accelerationCoins []dex.Bytes, changeCoin dex.Bytes, requiredForRemainingSwaps, newFeeRate uint64) (uint64, 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. PreAccelerate(swapCoins, accelerationCoins []dex.Bytes, changeCoin dex.Bytes, requiredForRemainingSwaps, feeSuggestion uint64) (uint64, *XYRange, *EarlyAcceleration, error) }
Accelerator is implemented by wallets which support acceleration of the mining of swap transactions.
type AccountLocker ¶ added in v0.5.0
type AccountLocker interface { // ReserveNRedemption is used when preparing funding for an order that // redeems to an account-based asset. The wallet will set aside the // appropriate amount of funds so that we can redeem N swaps using the // specified fee and asset version. It is an error to request funds > // spendable balance. ReserveNRedemptions(n uint64, ver uint32, maxFeeRate uint64) (uint64, error) // ReReserveRedemption is used when reconstructing existing orders on // startup. It is an error to request funds > spendable balance. ReReserveRedemption(amt uint64) error // UnlockRedemptionReserves is used to return funds reserved for redemption // when an order is canceled or otherwise completed unfilled. UnlockRedemptionReserves(uint64) // ReserveNRefunds is used when preparing funding for an order that refunds // to an account-based asset. The wallet will set aside the appropriate // amount of funds so that we can refund N swaps using the specified fee and // asset version. It is an error to request funds > spendable balance. ReserveNRefunds(n uint64, ver uint32, maxFeeRate uint64) (uint64, error) // ReReserveRefund is used when reconstructing existing orders on // startup. It is an error to request funds > spendable balance. ReReserveRefund(uint64) error // UnlockRefundReserves is used to return funds reserved for refunds // when an order was cancelled or revoked before a swap was initiated, // completed successfully, or after a refund was done. UnlockRefundReserves(uint64) }
AccountLocker is a wallet in which redemptions and refunds require a wallet to have available balance to pay fees.
type ActionRequiredNote ¶ added in v1.0.0
type ActionResolvedNote ¶ added in v1.0.0
type ActionResolvedNote struct { UniqueID string `json:"uniqueID"` // contains filtered or unexported fields }
type ActionTaker ¶ added in v1.0.0
type AddressReturner ¶ added in v1.0.0
type AddressReturner interface { // ReturnRefundContracts should be called with the Receipt.Contract() data // for any swaps that will not be refunded. ReturnRefundContracts(contracts [][]byte) // ReturnRedemptionAddress accepts a Wallet.RedemptionAddress() if the // address will not be used. ReturnRedemptionAddress(addr string) }
AddressReturner is a wallet that allows recycling of unused redemption or refund addresses. Asset implementations should log any errors internally. The caller is responsible for only returning unused addresses.
type ApprovalStatus ¶ added in v1.0.0
type ApprovalStatus uint8
const ( Approved ApprovalStatus = iota Pending NotApproved )
type AuditInfo ¶
type AuditInfo struct { // Recipient is the string-encoded recipient address. Recipient string // Expiration is the unix timestamp of the contract time lock expiration. Expiration time.Time // Coin is the coin that contains the contract. Coin Coin // Contract is the unique swap contract data. This may be a redeem script // for UTXO assets, or other information that uniquely identifies the swap // for account-based assets e.g. a contract version and secret hash for ETH. Contract dex.Bytes // SecretHash is the contract's secret hash. This is likely to be encoded in // the Contract field, which is often the redeem script or an asset-specific // encoding of the unique swap data. SecretHash dex.Bytes }
AuditInfo is audit information about a swap contract needed to audit the contract.
type Authenticator ¶ added in v1.0.0
type Authenticator interface { // Unlock unlocks the exchange wallet. Unlock(pw []byte) error // Lock locks the exchange wallet. Lock() error // Locked will be true if the wallet is currently locked. Locked() bool }
Authenticator is a wallet implementation that require authentication.
type Balance ¶
type Balance struct { // Available is the balance that is available for trading immediately. Available uint64 `json:"available"` // Immature is the balance that is not ready, but will be after some // confirmations. Immature uint64 `json:"immature"` // Locked is the total amount locked in the wallet which includes but // is not limited to funds locked for swap but not actually swapped yet. Locked uint64 `json:"locked"` // BondReserves is the amount of funds locked in the wallet for expenses // associated with bond maintenance. BondReserves uint64 `json:"bondReserves"` // ReservesDeficit is the difference between the available balance and the // amount reserved for specific purposes. ReservesDeficit uint64 `json:"reservesDeficit"` // Other is a place to list custom balance categories. It is recommended for // custom balance added here to have a translation and tooltip info in // client/webserver/site/src/js/wallet.js#customWalletBalanceCategory Other map[BalanceCategory]CustomBalance `json:"other"` }
Balance is categorized information about a wallet's balance.
type BalanceCategory ¶ added in v1.0.0
type BalanceCategory string
BalanceCategory is a string identifier for a custom balance category.
type BalanceChangeNote ¶ added in v1.0.0
type BalanceChangeNote struct { Balance *Balance // contains filtered or unexported fields }
BalanceChangeNote can be sent when the wallet detects a balance change between tip changes.
type Bond ¶ added in v0.6.0
type Bond struct { Version uint16 AssetID uint32 Amount uint64 CoinID []byte Data []byte // additional data to interpret the bond e.g. redeem script, bond contract, etc. // SignedTx and UnsignedTx are the opaque (raw bytes) signed and unsigned // bond creation transactions, in whatever encoding and funding scheme for // this asset and wallet. The unsigned one is used to pre-validate this bond // with the server prior to publishing it, thus locking funds for a long // period of time. Once the bond is pre-validated, the signed tx may then be // published by the wallet. SignedTx, UnsignedTx []byte // RedeemTx is a backup transaction that spends the bond output. Normally // the a key index will be used to derive the key when the bond expires. RedeemTx []byte }
Bond is the fidelity bond info generated for a certain account ID, amount, and lock time. These data are intended for the "post bond" request, in which the server pre-validates the unsigned transaction, the client then publishes the corresponding signed transaction, and a final request is made once the bond is fully confirmed. The caller should manage the private key.
type BondDetails ¶ added in v1.0.0
type BondDetails struct { *Bond LockTime time.Time CheckPrivKey func(priv *secp256k1.PrivateKey) bool }
BondDetails is the return from Bonder.FindBond.
type BondTxInfo ¶ added in v1.0.0
type BondTxInfo struct { // AccountID is the account is the account ID that the bond is applied to. AccountID dex.Bytes `json:"accountID"` // LockTime is the time until which the bond is locked. LockTime uint64 `json:"lockTime"` // BondID is the ID of the bond. BondID dex.Bytes `json:"bondID"` }
BondTxInfo contains information about a CreateBond or RedeemBond transaction.
type Bonder ¶ added in v0.6.0
type Bonder interface { Broadcaster // BondsFeeBuffer suggests how much extra may be required for the // transaction fees part of bond reserves when bond rotation is enabled. // This should return an amount larger than the minimum required by the // asset's reserves system for fees, if non-zero, so that a reserves // "deficit" does not appear right after the first bond is posted. The // caller may provide this value to ReserveBondFunds when actually posting // the first bond to ensure it succeeds, assuming balance was checked. BondsFeeBuffer(feeRate uint64) uint64 // SetReserves sets the bond reserve amount for the wallet. SetBondReserves(reserves uint64) // MakeBondTx authors a DEX time-locked fidelity bond transaction for the // provided amount, lock time, and dex account ID. An explicit private key // type is used to guarantee it's not bytes from something else like a // public key. If there are insufficient bond reserves, the returned error // should be of kind asset.ErrInsufficientBalance. The returned function may // be used to abandon the bond iff it has not yet been broadcast. Generally // this means unlocking the funds that are used by the transaction and // restoring consumed reserves amounts. MakeBondTx(ver uint16, amt, feeRate uint64, lockTime time.Time, privKey *secp256k1.PrivateKey, acctID []byte) (*Bond, func(), error) // RefundBond will refund the bond given the full bond output details and // private key to spend it. The bond is broadcasted. RefundBond(ctx context.Context, ver uint16, coinID, script []byte, amt uint64, privKey *secp256k1.PrivateKey) (Coin, error) // FindBond finds the bond with coinID and returns the values used to // create it. The output should be unspent with the lockTime set to // some time in the future. searchUntil is used for some wallets that // are able to pull blocks. FindBond(ctx context.Context, coinID []byte, searchUntil time.Time) (bondDetails *BondDetails, err error) }
Bonder is a wallet capable of creating and redeeming time-locked fidelity bond transaction outputs.
type BooleanConfig ¶ added in v0.5.0
type BooleanConfig struct { // Reason should summarize the difference between on/off states. Reason string `json:"reason"` }
BooleanConfig is set in a SwapOption to indicate that an options is a simple boolean.
type Broadcaster ¶ added in v0.6.0
type Broadcaster interface { // SendTransaction broadcasts a raw transaction, returning its coin ID. SendTransaction(rawTx []byte) ([]byte, error) }
Broadcaster is a wallet that can send a raw transaction on the asset network.
type Coin ¶
type Coin interface { // ID is a unique identifier for this coin. ID() dex.Bytes // String is a string representation of the coin. String() string // Value is the available quantity, in atoms/satoshi. Value() uint64 // TxID is the ID of the transaction that created the coin. TxID() string }
Coin is some amount of spendable asset. Coin provides the information needed to locate the unspent value on the blockchain.
type ConfigOption ¶
type ConfigOption struct { Key string `json:"key"` DisplayName string `json:"displayname"` Description string `json:"description"` DefaultValue any `json:"default"` // If MaxValue/MinValue are set to the string "now" for a date config, the // UI will display the current date. MaxValue any `json:"max"` MinValue any `json:"min"` Options map[string]*ConfigOption NoEcho bool `json:"noecho"` IsBoolean bool `json:"isboolean"` IsDate bool `json:"isdate"` DisableWhenActive bool `json:"disablewhenactive"` // Repeatable signals a text input that can be duplicated and submitted // multiple times, with the specified delimiter used to encode the data // in the settings map. Repeatable string `json:"repeatable"` // RepeatN signals how many times text input should be repeated, replicating // this option N times. RepeatN int32 `json:"repeatN"` Required bool `json:"required"` // DependsOn is the key of another config option that if is set to true, // this config option will be shown. DependsOn string `json:"dependsOn"` // ShowByDefault to show or not options on "hide advanced options". ShowByDefault bool `json:"showByDefault,omitempty"` }
ConfigOption is a wallet configuration option.
type ConfirmRedemptionStatus ¶ added in v0.6.0
ConfirmRedemptionStatus contains the coinID which redeemed a swap, the number of confirmations the transaction has, and the number of confirmations required for it to be considered confirmed.
type Contract ¶
type Contract struct { // Address is the receiving address. Address string // Value is the amount being traded. Value uint64 // SecretHash is the hash of the secret key. SecretHash dex.Bytes // LockTime is the contract lock time in UNIX seconds. LockTime uint64 }
Contract is a swap contract.
type CreateWalletParams ¶ added in v0.4.0
type CreateWalletParams struct { Type string Seed []byte Pass []byte Birthday uint64 Settings map[string]string DataDir string Net dex.Network Logger dex.Logger }
CreateWalletParams are the parameters for internal wallet creation. The Settings provided should be the same wallet configuration settings passed to OpenWallet.
type Creator ¶ added in v0.4.0
type Creator interface { Exists(walletType, dataDir string, settings map[string]string, net dex.Network) (bool, error) Create(*CreateWalletParams) error }
Creator defines methods for Drivers that will be called to initialize seeded wallets during CreateWallet. Only assets that provide seeded wallets need to implement Creator.
type CustomBalance ¶ added in v1.0.0
type CustomBalance struct { // Amount is the balance in the wallet for this custom category. It is // subtracted from Balance.Available above. Amount uint64 `json:"amt"` // Locked is a flag to indicate that this Amount is not included in // Balance.Available and is included in Balance.Locked. Locked bool `json:"locked"` }
CustomBalance is a balance category used to track funds for a particular purpose or for a special kind of balance (e.g Zcash Shielded wallet balances).
type CustomWalletNote ¶ added in v1.0.0
type CustomWalletNote struct { Payload any `json:"payload"` // contains filtered or unexported fields }
CustomWalletNote is any other information the wallet wishes to convey to the user.
type Driver ¶
type Driver interface { Open(*WalletConfig, dex.Logger, dex.Network) (Wallet, error) DecodeCoinID(coinID []byte) (string, error) Info() *WalletInfo }
Driver is the interface required of all exchange wallets.
type DynamicSwapper ¶ added in v1.0.0
type DynamicSwapper interface { // DynamicSwapFeesPaid returns fees for initiation transactions. DynamicSwapFeesPaid(ctx context.Context, coinID, contractData dex.Bytes) (fee uint64, secretHashes [][]byte, err error) // DynamicRedemptionFeesPaid returns fees for redemption transactions. DynamicRedemptionFeesPaid(ctx context.Context, coinID, contractData dex.Bytes) (fee uint64, secretHashes [][]byte, err error) }
DynamicSwapper defines methods that accept an initiation or redemption coinID and returns the fee spent on the transaction along with the secrets included in the tx. Returns asset.CoinNotFoundError for unmined txn. Returns asset.ErrNotEnoughConfirms for txn with too few confirmations. Will also error if the secret in the contractData is not found in the transaction secrets.
type EarlyAcceleration ¶ added in v0.5.0
type EarlyAcceleration struct { // TimePast is the amount of seconds that has past since either the previous // acceleration, or the oldest unmined swap transaction was submitted to // the blockchain. TimePast uint64 `json:"timePast"` // WasAccelerated is true if the action that took place TimePast seconds // ago was an acceleration. If false, the oldest unmined swap transaction // in the order was submitted TimePast seconds ago. WasAccelerated bool `json:"wasAccelerated"` }
EarlyAcceleration is returned from the PreAccelerate function to inform the user that either their last acceleration or oldest swap transaction happened very recently, and that they should double check that they really want to do an acceleration.
type FeeRater ¶ added in v0.4.3
type FeeRater interface {
FeeRate() uint64
}
FeeRater is capable of retrieving a non-critical fee rate estimate for an asset. Some SPV wallets, for example, cannot provide a fee rate estimate, so shouldn't implement FeeRater. However, since the mode of external wallets may not be known on construction, only connect, a zero rate may be returned. The caller should always check for zero and have a fallback rate. The rates from FeeRate should be used for rates that are not validated by the server Withdraw and Send, and will/should not be used to generate a fee suggestion for swap operations.
type FundsMixer ¶ added in v1.0.0
type FundsMixer interface { // FundsMixingStats returns the current state of the wallet's funds mixer. FundsMixingStats() (*FundsMixingStats, error) // ConfigureFundsMixer configures the wallet for funds mixing. ConfigureFundsMixer(enabled bool) error }
FundsMixer defines methods for mixing funds in a wallet.
type FundsMixingStats ¶ added in v1.0.0
type FundsMixingStats struct { // Enabled is true if the wallet is configured for funds mixing. The wallet // must be configured before mixing can be started. Enabled bool `json:"enabled"` // UnmixedBalanceThreshold is the minimum amount of unmixed funds that must // be in the wallet for mixing to happen. UnmixedBalanceThreshold uint64 `json:"unmixedBalanceThreshold"` // MixedFunds is the total amout of funds in the mixed account. MixedFunds uint64 `json:"mixedFunds"` // TradingFunds is the total amout of funds in the trading account. TradingFunds uint64 `json:"tradingFunds"` }
FundsMixingStats describes the current state of a wallet's funds mixer.
type GeocodeRedeemer ¶ added in v1.0.0
type GeocodeRedeemer interface {
RedeemGeocode(code []byte, msg string) (dex.Bytes, uint64, error)
}
A GeocodeRedeemer redeems funds from a geocode game.
type LiveReconfigurer ¶ added in v0.5.0
type LiveReconfigurer interface { // Reconfigure attempts to reconfigure the wallet. If reconfiguration // requires a restart, the Wallet should still validate as much // configuration as possible. Reconfigure(ctx context.Context, cfg *WalletConfig, currentAddress string) (restartRequired bool, err error) }
LiveReconfigurer is a wallet that can possibly handle a reconfiguration without the need for re-initialization.
type LogFiler ¶ added in v0.4.1
type LogFiler interface {
LogFilePath() string
}
LogFiler is a wallet that allows for downloading of its log file.
type MaxOrderForm ¶ added in v0.5.0
type MaxOrderForm struct { LotSize uint64 FeeSuggestion uint64 AssetVersion uint32 // the init/from asset version MaxFeeRate uint64 // max fee rate of init/from asset RedeemVersion uint32 // the redeem/to asset version RedeemAssetID uint32 // the redeem/to asset ID }
MaxOrderForm is used to get a SwapEstimate from the Wallet's MaxOrder method.
type MultiOrder ¶ added in v1.0.0
type MultiOrder struct { // Version is the asset version of the "from" asset with the init // transaction. Version uint32 Values []*MultiOrderValue // MaxFeeRate is the largest possible fee rate for the init transaction (of // this "from" asset) specific to and provided by a particular server, and // is used to calculate the funding required to cover fees. MaxFeeRate uint64 // FeeSuggestion is a suggested fee from the server. If a split transaction // is used, the fee rate used should be at least the suggested fee, else // zero-conf coins might be rejected. FeeSuggestion uint64 // Options are options that corresponds to PreSwap.Options, as well as // their values. Options map[string]string // RedeemVersion is the asset version of the "to" asset with the redeem // transaction. RedeemVersion uint32 // RedeemAssetID is the asset ID of the "to" asset. RedeemAssetID uint32 }
MultiOrder is order details needed for FundMultiOrder.
type MultiOrderValue ¶ added in v1.0.0
type MultiOrderValue struct { // Value is the amount required to satisfy the order. The Value does not // include fees. Fees will be calculated internally based on the number of // possible swaps (MaxSwapCount) and the exchange's configuration // (Exchange). Value uint64 // MaxSwapCount is the number of lots in the order, which is also the // maximum number of transactions that an order could potentially generate // in a worst-case scenario of all 1-lot matches. MaxSwapCount uint64 // uint64 for compatibility with quantity and lot size. }
MultiOrderValue is one of the placements in a multi-order.
type NewAddresser ¶ added in v0.4.1
NewAddresser is a wallet that can generate new deposit addresses.
type Order ¶
type Order struct { // Version is the asset version of the "from" asset with the init // transaction. Version uint32 // Value is the amount required to satisfy the order. The Value does not // include fees. Fees will be calculated internally based on the number of // possible swaps (MaxSwapCount) and the exchange's configuration // (Exchange). Value uint64 // MaxSwapCount is the number of lots in the order, which is also the // maximum number of transactions that an order could potentially generate // in a worst-case scenario of all 1-lot matches. MaxSwapCount uint64 // uint64 for compatibility with quantity and lot size. // MaxFeeRate is the largest possible fee rate for the init transaction (of // this "from" asset) specific to and provided by a particular server, and // is used to calculate the funding required to cover fees. MaxFeeRate uint64 // Immediate should be set to true if this is for an order that is not a // standing order, likely a market order or a limit order with immediate // time-in-force. Immediate bool // FeeSuggestion is a suggested fee from the server. If a split transaction // is used, the fee rate used should be at least the suggested fee, else // zero-conf coins might be rejected. FeeSuggestion uint64 // Options are options that corresponds to PreSwap.Options, as well as // their values. Options map[string]string // RedeemVersion is the asset version of the "to" asset with the redeem // transaction. RedeemVersion uint32 // RedeemAssetID is the asset ID of the "to" asset. RedeemAssetID uint32 }
Order is order details needed for FundOrder.
type OrderOption ¶ added in v0.5.0
type OrderOption struct { ConfigOption QuoteAssetOnly bool `json:"quoteAssetOnly"` // Boolean is a boolean option with two custom labels. Boolean *BooleanConfig `json:"boolean,omitempty"` // Range indicates a numeric input where the user can adjust the value // between a pre-defined low and high. XYRange *XYRange `json:"xyRange,omitempty"` }
OrderOption is an available option for an order.
type PeerManager ¶ added in v0.6.0
type PeerManager interface { // Peers returns a list of peers that the wallet is connected to. Peers() ([]*WalletPeer, 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. AddPeer(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 its own. RemovePeer(addr string) error }
PeerManager is a wallet which provides allows the user to see the peers the wallet is connected to and add new peers.
type PeerSource ¶ added in v0.6.0
type PeerSource uint16
PeerSource specifies how a wallet knows about a peer. It may have been hardcoded into the wallet code, added manually by the user, or discovered by communicating with the default/user added peers.
const ( WalletDefault PeerSource = iota UserAdded Discovered )
type PreRedeem ¶ added in v0.2.0
type PreRedeem struct { Estimate *RedeemEstimate `json:"estimate"` Options []*OrderOption `json:"options"` }
PreRedeem is an estimate of the fees for redemption. The struct will be expanded in in-progress work to accommodate order-time options.
type PreRedeemForm ¶ added in v0.2.0
type PreRedeemForm struct { // Version is the asset version. Most backends only support one version. Version uint32 // Lots is the number of lots in the order. Lots uint64 // FeeSuggestion is a suggested fee from the server. FeeSuggestion uint64 // SelectedOptions is any options that the user has selected. SelectedOptions map[string]string }
PreRedeemForm can be used to get a redemption estimate.
type PreSwap ¶ added in v0.2.0
type PreSwap struct { Estimate *SwapEstimate `json:"estimate"` Options []*OrderOption `json:"options"` }
PreSwap is a SwapEstimate returned from Wallet.PreSwap.
type PreSwapForm ¶ added in v0.2.0
type PreSwapForm struct { // Version is the asset version. Most backends only support one version. Version uint32 // LotSize is the lot size for the calculation. For quote assets, LotSize // should be based on either the user's limit order rate, or some measure // of the current market rate. LotSize uint64 // Lots is the number of lots in the order. Lots uint64 // MaxFeeRate is the highest possible fee rate that may be required for the // swap initialization transaction. MaxFeeRate uint64 // Immediate should be set to true if this is for an order that is not a // standing order, likely a market order or a limit order with immediate // time-in-force. Immediate bool // FeeSuggestion is a suggested fee from the server. If a split transaction // is used, the fee rate used should be at least the suggested fee, else // zero-conf coins might be rejected. FeeSuggestion uint64 // SelectedOptions is any options that the user has selected. The available // PreOrder options and values can be inter-dependent, so when a user // selects an option, a new PreOrder can be generated to updated the // options available and recalculate the effects. SelectedOptions map[string]string // RedeemVersion is the asset version of the "to" asset with the redeem // transaction. Most backends only support one version. RedeemVersion uint32 // RedeemAssetID is the asset ID of the "to" asset. RedeemAssetID uint32 }
PreSwapForm can be used to get a swap fees estimate.
type Receipt ¶
type Receipt interface { // Expiration is the time lock expiration. Expiration() time.Time // Coin is the swap initiation transaction's Coin. Coin() Coin // Contract is the unique swap contract data. This may be a redeem script // for UTXO assets, or other information that uniquely identifies the swap // for account-based assets e.g. a contract version and secret hash for ETH. Contract() dex.Bytes // String provides a human-readable representation of the swap that may // provide supplementary data to locate the swap. String() string // SignedRefund is a signed refund script that can be used to return // funds to the user in the case a contract expires. SignedRefund() dex.Bytes }
Receipt holds information about a sent swap contract.
type Recoverer ¶ added in v0.5.0
type Recoverer interface { // GetRecoveryCfg returns information that will help the wallet get back to // its previous state after it is recreated. GetRecoveryCfg() (map[string]string, error) // Move will move all wallet files to a backup directory so the wallet can // be recreated. Move(backupdir string) error }
Recoverer is a wallet implementation with recover functionality.
type RecoveryCoin ¶ added in v0.5.0
type RedeemEstimate ¶ added in v0.2.0
type RedeemEstimate struct { // RealisticBestCase is the best-case scenario fees of a single transaction // with a match covering the entire order, at the prevailing fee rate. RealisticBestCase uint64 `json:"realisticBestCase"` // RealisticWorstCase is the worst-case scenario fees of all 1-lot matches, // each with their own call to Redeem. RealisticWorstCase uint64 `json:"realisticWorstCase"` }
RedeemEstimate is an estimate of the range of fees that might realistically be assessed to the redemption transaction.
type RedeemForm ¶ added in v0.2.0
type RedeemForm struct { Redemptions []*Redemption // FeeSuggestion is a suggested fee rate. For redemptions, the suggestion is // just a fallback if an internal estimate using the wallet's redeem confirm // block target setting is not available. Since this is the redemption, // there is no obligation on the client to use the fee suggestion in any // way, but obviously fees that are too low may result in the redemption // getting stuck in mempool. FeeSuggestion uint64 Options map[string]string }
RedeemForm is a group of Redemptions. The struct will be expanded in in-progress work to accommodate order-time options.
type Redemption ¶
type Redemption struct { // Spends is the AuditInfo for the swap output being spent. Spends *AuditInfo // Secret is the secret key needed to satisfy the swap contract. Secret dex.Bytes }
Redemption is a redemption transaction that spends a counter-party's swap contract.
type RegisteredAsset ¶
type RegisteredAsset struct { ID uint32 Symbol string Info *WalletInfo Tokens map[uint32]*Token }
A registered asset is information about a supported asset.
func Asset ¶ added in v0.6.0
func Asset(assetID uint32) *RegisteredAsset
Asset gets the RegisteredAsset for the specified asset ID. Asset is for base chain assets, not tokens.
type Rescanner ¶ added in v0.4.1
type Rescanner interface { // Rescan performs a rescan and block until it is done. If no birthday is // provided, internal wallets may use a birthday concurrent with the // earliest date at which a wallet was possible, which is asset-dependent. Rescan(ctx context.Context, bday uint64) error }
Rescanner is a wallet implementation with rescan functionality.
type Stances ¶ added in v1.0.0
type Stances struct { Agendas []*TBAgenda `json:"agendas"` TreasurySpends []*TBTreasurySpend `json:"tspends"` TreasuryKeys []*dcrwalletjson.TreasuryPolicyResult `json:"treasuryKeys"` }
Stances are current policy preferences for the TicketBuyer.
type SwapEstimate ¶ added in v0.2.0
type SwapEstimate struct { // Lots is the number of lots in the order. Lots uint64 `json:"lots"` // Value is the total value of the order. Value uint64 `json:"value"` // MaxFees is the maximum possible fees that can be assessed for the order's // swaps. MaxFees uint64 `json:"maxFees"` // RealisticWorstCase is an estimation of the fees that might be assessed in // a worst-case scenario of 1 tx per 1 lot match, but at the prevailing fee // rate estimate. RealisticWorstCase uint64 `json:"realisticWorstCase"` // RealisticBestCase is an estimation of the fees that might be assessed in // a best-case scenario of 1 tx and 1 output for the entire order. RealisticBestCase uint64 `json:"realisticBestCase"` // FeeReservesPerLot is the amount that must be reserved per lot to cover // fees for swap transactions. FeeReservesPerLot uint64 `json:"feeReservesPerLot"` }
SwapEstimate is an estimate of the fees and locked amounts associated with an order.
type Swaps ¶
type Swaps struct { // Version is the asset version. Version uint32 // Inputs are the Coins being spent. Inputs Coins // Contract is the contract data. Contracts []*Contract // FeeRate is the required fee rate in atoms/byte. FeeRate uint64 // LockChange can be set to true if the change should be locked for // subsequent matches. LockChange bool // Options are OrderOptions set or selected by the user at order time. Options map[string]string }
Swaps is the details needed to broadcast a swap contract(s).
type Sweeper ¶ added in v0.4.1
Sweeper is a wallet that can clear the entire balance of the wallet/account to an address. Similar to Withdraw, but no input value is required.
type SyncStatus ¶ added in v1.0.0
type SyncStatus struct { Synced bool `json:"synced"` TargetHeight uint64 `json:"targetHeight"` StartingBlocks uint64 `json:"startingBlocks"` Blocks uint64 `json:"blocks"` Transactions *uint64 `json:"txs,omitempty"` }
SyncStatus is the status of wallet syncing.
func (*SyncStatus) BlockProgress ¶ added in v1.0.0
func (ss *SyncStatus) BlockProgress() float32
type TBAgenda ¶ added in v1.0.0
type TBAgenda struct { ID string `json:"id"` Description string `json:"description"` CurrentChoice string `json:"currentChoice"` Choices []*TBChoice `json:"choices"` }
TBAgenda is an agenda that the TicketBuyer can vote on.
type TBTreasurySpend ¶ added in v1.0.0
type TBTreasurySpend struct { Hash string `json:"hash"` Value uint64 `json:"value"` CurrentPolicy string `json:"currentPolicy"` }
TBTreasurySpend represents a treasury spend that the TicketBuyer can vote on.
type Ticket ¶ added in v1.0.0
type Ticket struct { Tx TicketTransaction `json:"tx"` Status TicketStatus `json:"status"` Spender string `json:"spender"` }
Ticket holds information about a decred ticket.
type TicketBuyer ¶ added in v1.0.0
type TicketBuyer interface { // StakeStatus returns current staking statuses such as currently owned // tickets, ticket price, and current voting preferences. StakeStatus() (*TicketStakingStatus, error) // SetVSP sets the VSP provider. SetVSP(addr string) error // PurchaseTickets starts an aysnchronous process to purchase n tickets. // Look for TicketPurchaseUpdate notifications to track the process. PurchaseTickets(n int, feeSuggestion uint64) error // SetVotingPreferences sets default voting settings for all active // tickets and future tickets. Nil maps can be provided for no change. SetVotingPreferences(choices, tSpendPolicy, treasuryPolicy map[string]string) error // ListVSPs lists known available voting service providers. ListVSPs() ([]*VotingServiceProvider, error) // TicketPage fetches a page of tickets within a range of block numbers with // a target page size and optional offset. scanStart is the block in which // to start the scan. The scan progresses in reverse block number order, // starting at scanStart and going to progressively lower blocks. scanStart // can be set to -1 to indicate the current chain tip. TicketPage(scanStart int32, n, skipN int) ([]*Ticket, error) }
TicketBuyer is a wallet that can participate in decred staking.
TODO: Consider adding (*AutoClient).ProcessUnprocessedTickets/ProcessManagedTickets to be used when restoring wallet from seed.
type TicketStakingStatus ¶ added in v1.0.0
type TicketStakingStatus struct { // TicketPrice is the current price of one ticket. Also known as the // stake difficulty. TicketPrice uint64 `json:"ticketPrice"` // VotingSubsidy is the current reward for a vote. VotingSubsidy uint64 `json:"votingSubsidy"` // VSP is the currently set VSP address and fee. VSP string `json:"vsp"` // IsRPC will be true if this is an RPC wallet, in which case we can't // set a new VSP and some other information may not be available. IsRPC bool `json:"isRPC"` // Tickets returns current active tickets up until they are voted or // revoked. Includes unconfirmed tickets. Tickets []*Ticket `json:"tickets"` // Stances returns current voting preferences. Stances Stances `json:"stances"` // Stats is statistical info about staking history. Stats TicketStats `json:"stats"` }
TicketStakingStatus holds various stake information from the wallet.
type TicketStats ¶ added in v1.0.0
type TicketStats struct { TotalRewards uint64 `json:"totalRewards"` TicketCount uint32 `json:"ticketCount"` Votes uint32 `json:"votes"` Revokes uint32 `json:"revokes"` Queued uint32 `json:"queued"` Mempool uint32 `json:"mempool"` }
TicketStats sums up some statistics for historical staking data for a TicketBuyer.
type TicketStatus ¶ added in v1.0.0
type TicketStatus uint
TicketStatus from dcrwallet.
const ( TicketStatusUnknown TicketStatus = iota TicketStatusUnmined TicketStatusImmature TicketStatusLive TicketStatusVoted TicketStatusMissed TicketStatusExpired TicketStatusUnspent TicketStatusRevoked )
Copy of wallet.TicketStatus
type TicketTransaction ¶ added in v1.0.0
type TicketTransaction struct { Hash string `json:"hash"` TicketPrice uint64 `json:"ticketPrice"` Fees uint64 `json:"fees"` Stamp uint64 `json:"stamp"` BlockHeight int64 `json:"blockHeight"` }
TicketTransaction represents a ticket transaction.
type TipChangeNote ¶ added in v1.0.0
type TipChangeNote struct { Tip uint64 `json:"tip"` Data any `json:"data"` // contains filtered or unexported fields }
TipChangeNote is the only required wallet notification. All wallets should emit a TipChangeNote when a state change occurs that might necessitate swap progression or new balance checks.
type Token ¶ added in v0.5.0
type Token struct { *dex.Token Definition *WalletDefinition `json:"definition"` ContractAddress string `json:"contractAddress"` // Set in SetNetwork }
Token combines the generic dex.Token with a WalletDefinition.
type TokenApprover ¶ added in v1.0.0
type TokenApprover interface { // ApproveToken sends an approval transaction for a specific version of // the token's swap contract. An error is returned if an approval has // already been done or is pending. The onConfirm callback is called // when the approval transaction is confirmed. ApproveToken(assetVer uint32, onConfirm func()) (string, error) // UnapproveToken removes the approval for a specific version of the // token's swap contract. UnapproveToken(assetVer uint32, onConfirm func()) (string, error) // ApprovalStatus returns the approval status for each version of the // token's swap contract. ApprovalStatus() map[uint32]ApprovalStatus // ApprovalFee returns the estimated fee for an approval transaction. ApprovalFee(assetVer uint32, approval bool) (uint64, error) }
TokenApprover is implemented by wallets that require an approval before trading.
type TokenCoin ¶ added in v1.0.0
TokenCoin extends the Coin interface to include the amount locked of the parent asset to be used for fees.
type TokenConfig ¶ added in v0.6.0
type TokenConfig struct { // AssetID of the token. AssetID uint32 // Settings correspond to Token.Definition.ConfigOpts. Settings map[string]string // Emit is a WalletEmitter that manages a channel over which an asset may // issue notifications. Emit *WalletEmitter // PeersChange will be called after the parent's PeersChange. PeersChange func(uint32, error) }
TokenConfig is required to OpenTokenWallet.
type TokenMaster ¶ added in v0.5.0
type TokenMaster interface { // CreateTokenWallet creates a wallet for the specified token asset. The // settings correspond to the Token.Definition.ConfigOpts. CreateTokenWallet(assetID uint32, settings map[string]string) error // OpenTokenWallet opens a wallet for the specified token asset. OpenTokenWallet(cfg *TokenConfig) (Wallet, error) }
TokenMaster is implemented by assets which support degenerate tokens.
type TransactionNote ¶ added in v1.0.0
type TransactionNote struct { Transaction *WalletTransaction `json:"transaction"` New bool `json:"new"` // contains filtered or unexported fields }
TransactionNote is sent when a transaction is made, seen, or updated.
type TransactionType ¶ added in v1.0.0
type TransactionType uint16
TransactionType is the type of transaction made by a wallet.
const ( Unknown TransactionType = iota Send Receive Swap Redeem Refund Split CreateBond RedeemBond ApproveToken Acceleration SelfSend RevokeTokenApproval TicketPurchase TicketVote TicketRevocation // SwapOrSend is used when a wallet scanned its historical transactions // and was unable to determine if the transaction was a swap or a send. SwapOrSend Mix )
type TxFeeEstimator ¶ added in v0.6.0
type TxFeeEstimator interface { // EstimateSendTxFee returns a tx fee estimate for sending or withdrawing // the provided amount using the provided feeRate. This uses actual utxos to // calculate the tx fee where possible and ensures the wallet has enough to // cover send value and minimum fees. EstimateSendTxFee(address string, value, feeRate uint64, subtract, maxWithdraw bool) (fee uint64, isValidAddress bool, err error) }
TxFeeEstimator is a wallet implementation with fee estimation functionality.
type VotingServiceProvider ¶ added in v1.0.0
type VotingServiceProvider struct { URL string `json:"url"` Network dex.Network `json:"network"` Launched uint64 `json:"launched"` // milliseconds LastUpdated uint64 `json:"lastUpdated"` // milliseconds APIVersions []int64 `json:"apiVersions"` FeePercentage float64 `json:"feePercentage"` Closed bool `json:"closed"` Voting int64 `json:"voting"` Voted int64 `json:"voted"` Revoked int64 `json:"revoked"` VSPDVersion string `json:"vspdVersion"` BlockHeight uint32 `json:"blockHeight"` }
VotingServiceProvider is information about a voting service provider.
type Wallet ¶
type Wallet interface { // It should be assumed that once disconnected, subsequent Connect calls // will fail, requiring a new Wallet instance. dex.Connector // Info returns a set of basic information about the wallet driver. Info() *WalletInfo // Balance should return the balance of the wallet, categorized by // available, immature, and locked. Balance takes a list of minimum // confirmations for which to calculate maturity, and returns a list of // corresponding *Balance. Balance() (*Balance, 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. The fees returned are any fees paid in the // process of funding the order, such as transaction fees for a split tx. FundOrder(*Order) (coins Coins, redeemScripts []dex.Bytes, fees uint64, err error) // MaxOrder generates information about the maximum order size and // associated fees that the wallet can support for the specified DEX. The // fees are an estimate based on current network conditions, and will be <= // the fees associated with the Asset.MaxFeeRate. For quote assets, lotSize // will be an estimate based on current market conditions. lotSize should // not be zero. MaxOrder(*MaxOrderForm) (*SwapEstimate, error) // PreSwap gets a pre-swap estimate for the specified order size. PreSwap(*PreSwapForm) (*PreSwap, error) // PreRedeem gets a pre-redeem estimate for the specified order size. PreRedeem(*PreRedeemForm) (*PreRedeem, error) // ReturnCoins unlocks coins. This would be necessary in the case of a // canceled order. A nil Coins slice indicates to unlock all coins that the // wallet may have locked, a syntax that should always be followed by // FundingCoins for any active orders, and is thus only appropriate at time // of login. Unlocking all coins is likely only useful for external wallets // whose lifetime is longer than the asset.Wallet instance. ReturnCoins(Coins) error // FundingCoins gets funding coins for the coin IDs. The coins are locked. // This method might be called to reinitialize an order from data stored // externally. This method will only return funding coins, e.g. unspent // transaction outputs. FundingCoins([]dex.Bytes) (Coins, error) // Swap sends the swaps in a single transaction. The Receipts returned can // be used to refund a failed transaction. The Input coins are unlocked // where necessary to ensure accurate balance reporting in cases where the // wallet includes spent coins as part of the locked balance just because // they were previously locked. Swap(*Swaps) (receipts []Receipt, changeCoin Coin, feesPaid uint64, err error) // Redeem sends the redemption transaction, which may contain more than one // redemption. The input coin IDs and the output Coin are returned. Redeem(redeems *RedeemForm) (ins []dex.Bytes, out Coin, feesPaid uint64, err error) // SignMessage signs the coin ID with the private key associated with the // specified Coin. A slice of pubkeys required to spend the Coin and a // signature for each pubkey are returned. SignMessage(Coin, dex.Bytes) (pubkeys, sigs []dex.Bytes, err error) // AuditContract retrieves information about a swap contract from the // provided txData and broadcasts the txData to ensure the contract is // propagated to the blockchain. The information returned would be used // to verify the counter-party's contract during a swap. It is not an // error if the provided txData cannot be broadcasted because it may // already be broadcasted. A successful audit response does not mean // the tx exists on the blockchain, use SwapConfirmations to ensure // the tx is mined. AuditContract(coinID, contract, txData dex.Bytes, rebroadcast bool) (*AuditInfo, error) // ContractLockTimeExpired returns true if the specified contract's locktime // has expired, making it possible to issue a Refund. The contract expiry // time is also returned, but reaching this time does not necessarily mean // the contract can be refunded since assets have different rules to satisfy // the lock. For example, in Bitcoin the median of the last 11 blocks must // be past the expiry time, not the current time. ContractLockTimeExpired(ctx context.Context, contract dex.Bytes) (bool, time.Time, error) // FindRedemption watches for the input that spends the specified // coin and contract, and returns the spending input and the // secret key when it finds a spender. // // For typical utxo-based blockchains, every input of every block tx // (starting at the contract block) will need to be scanned until a spending // input is found. // // FindRedemption is necessary to deal with the case of a maker redeeming // but not forwarding their redemption information. The DEX does not monitor // for this case. While it will result in the counter-party being penalized, // the input still needs to be found so the swap can be completed. // // NOTE: This could potentially be a long and expensive operation if // performed long after the swap is broadcast; might be better executed from // a goroutine. FindRedemption(ctx context.Context, coinID, contract dex.Bytes) (redemptionCoin, secret dex.Bytes, err error) // Refund refunds a contract. This can only be used after the time lock has // expired AND if the contract has not been redeemed/refunded. This method // MUST return an asset.CoinNotFoundError error if the swap is already // spent, which is used to indicate if FindRedemption should be used and the // counterparty's swap redeemed. 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. Refund(coinID, contract dex.Bytes, feeRate uint64) (dex.Bytes, error) // DepositAddress returns an address for depositing funds into Bison Wallet. DepositAddress() (string, error) // OwnsDepositAddress indicates if the provided address can be used // to deposit funds into the wallet. OwnsDepositAddress(address string) (bool, error) // RedemptionAddress gets an address for use in redeeming the counterparty's // swap. This would be included in their swap initialization. This is // presently called when each trade order is *submitted*. If these are // unique addresses and the orders are canceled, the gap limit may become a // hurdle when restoring the wallet. RedemptionAddress() (string, error) // LockTimeExpired returns true if the specified locktime has expired, // making it possible to redeem the locked coins. LockTimeExpired(ctx context.Context, lockTime time.Time) (bool, error) // SwapConfirmations gets the number of confirmations and the spend status // for the specified swap. If the swap was not funded by this wallet, and // it is already spent, you may see CoinNotFoundError. // If the coin is located, but recognized as spent, no error is returned. // If the contract is already redeemed or refunded, the confs value may not // be accurate. // The contract and matchTime are provided so that wallets may search for // the coin using light filters. SwapConfirmations(ctx context.Context, coinID dex.Bytes, contract dex.Bytes, matchTime time.Time) (confs uint32, spent bool, err error) // ValidateSecret checks that the secret hashes to the secret hash. ValidateSecret(secret, secretHash []byte) bool // SyncStatus is information about the blockchain sync status. It should // only indicate synced when there are network peers and all blocks on the // network have been processed by the wallet. SyncStatus() (*SyncStatus, error) // RegFeeConfirmations gets the confirmations for a registration fee // payment. This method need not be supported by all assets. Those assets // which do no support DEX registration fees will return an ErrUnsupported. RegFeeConfirmations(ctx context.Context, coinID dex.Bytes) (confs uint32, err error) // Send sends the exact value to the specified address. This is different // from Withdraw, which subtracts the tx fees from the amount sent. Send(address string, value, feeRate uint64) (Coin, error) // ValidateAddress checks that the provided address is valid. ValidateAddress(address string) bool // ConfirmRedemption checks the status of a redemption. It returns the // number of confirmations the redemption has, the number of confirmations // that are required for it to be considered fully confirmed, and the // CoinID used to do the redemption. If it is determined that a transaction // will not be mined, this function will submit a new transaction to // replace the old one. The caller is notified of this by having a // different CoinID in the returned asset.ConfirmRedemptionStatus as was // used to call the function. ConfirmRedemption(coinID dex.Bytes, redemption *Redemption, feeSuggestion uint64) (*ConfirmRedemptionStatus, error) // SingleLotSwapRefundFees returns the fees for a swap and refund transaction for a single lot. SingleLotSwapRefundFees(version uint32, feeRate uint64, useSafeTxSize bool) (uint64, uint64, error) // SingleLotRedeemFees returns the fees for a redeem transaction for a single lot. SingleLotRedeemFees(version uint32, feeRate uint64) (uint64, error) // StandardSendFee returns the fee for a "standard" send tx. StandardSendFee(feeRate uint64) uint64 // FundMultiOrder funds multiple orders at once. The return values will // be in the same order as the passed orders. If less values are returned // than the number of orders, then the orders at the end of the list were // not about to be funded. FundMultiOrder(ord *MultiOrder, maxLock uint64) (coins []Coins, redeemScripts [][]dex.Bytes, fundingFees uint64, err error) // MaxFundingFees returns the max fees that could be paid for funding a swap. MaxFundingFees(numTrades uint32, feeRate uint64, options map[string]string) uint64 }
Wallet is a common interface to be implemented by cryptocurrency wallet software.
func OpenWallet ¶ added in v0.4.0
func OpenWallet(assetID uint32, cfg *WalletConfig, logger dex.Logger, net dex.Network) (w Wallet, err error)
OpenWallet sets up the asset, returning the exchange wallet.
type WalletConfig ¶
type WalletConfig struct { // Type is the type of wallet, corresponding to the Type field of an // available WalletDefinition. Type string // Settings is the key-value store of wallet connection parameters. The // Settings are supplied by the user according the the WalletInfo's // ConfigOpts. Settings map[string]string // Emit is a WalletEmitter that manages a channel over which an asset may // issue notifications. Every asset is expected to issue a TipChangeNote // when a network change occurs that might require balance updates or action // on swaps. Emit *WalletEmitter // PeersChange is a function that will be called when the number of // wallet/node peers changes, or the wallet fails to get the count. This // should not be called prior to Connect of the constructed wallet. PeersChange func(uint32, error) // DataDir is a filesystem directory the wallet may use for persistent // storage. DataDir string }
WalletConfig is the configuration settings for the wallet. WalletConfig is passed to the wallet constructor.
type WalletDefinition ¶ added in v0.4.0
type WalletDefinition struct { // If seeded is true, the Create method will be called with a deterministic // seed that should be used to set the wallet key(s). This would be // true for built-in wallets. Seeded bool `json:"seeded"` // Type is a string identifying the wallet type. NOTE: There should be a // particular WalletTrait set for any given Type, but wallet construction is // presently required to discern traits. Type string `json:"type"` // Tab is a displayable string for the wallet type. One or two words. First // word capitalized. Displayed on a wallet selection tab. Tab string `json:"tab"` // Description is a short description of the wallet, suitable for a tooltip. Description string `json:"description"` // DefaultConfigPath is the default file path that the Wallet uses for its // configuration file. Probably only useful for unseeded / external wallets. DefaultConfigPath string `json:"configpath"` // ConfigOpts is a slice of expected Wallet config options, with the display // name, config key (for parsing the option from a config file/text) and // description for each option. This can be used to request config info from // users e.g. via dynamically generated GUI forms. ConfigOpts []*ConfigOption `json:"configopts"` // MultiFundingOpts are options related to funding multi-trades. MultiFundingOpts []*OrderOption `json:"multifundingopts"` // NoAuth indicates that the wallet does not implement the Authenticator // interface. A better way to check is to use the wallet traits but wallet // construction is presently required to discern traits. NoAuth bool `json:"noauth"` // GuideLink is a link to wallet configuration docs that the user may follow // when creating a new wallet or updating its settings. GuideLink string `json:"guidelink"` }
type WalletEmitter ¶ added in v1.0.0
type WalletEmitter struct {
// contains filtered or unexported fields
}
WalletEmitter handles a channel for wallet notifications and provides methods that generates notifications.
func NewWalletEmitter ¶ added in v1.0.0
func NewWalletEmitter(c chan<- WalletNotification, assetID uint32, log dex.Logger) *WalletEmitter
NewWalletEmitter constructs a WalletEmitter for an asset.
func (*WalletEmitter) ActionRequired ¶ added in v1.0.0
func (e *WalletEmitter) ActionRequired(uniqueID, actionID string, payload any)
ActionRequired is a route that will end up as a special dialogue seeking user input via (ActionTaker).TakeAction.
func (*WalletEmitter) ActionResolved ¶ added in v1.0.0
func (e *WalletEmitter) ActionResolved(uniqueID string)
func (*WalletEmitter) BalanceChange ¶ added in v1.0.0
func (e *WalletEmitter) BalanceChange(bal *Balance)
BalanceChange sends a BalanceChangeNote.
func (*WalletEmitter) Data ¶ added in v1.0.0
func (e *WalletEmitter) Data(route string, payload any)
Data sends a CustomWalletNote with the specified data payload.
func (*WalletEmitter) TipChange ¶ added in v1.0.0
func (e *WalletEmitter) TipChange(tip uint64, datas ...any)
TipChange sends a TipChangeNote with optional extra data.
func (*WalletEmitter) TransactionHistorySyncedNote ¶ added in v1.0.0
func (e *WalletEmitter) TransactionHistorySyncedNote()
TransactionHistorySyncedNote sends a TransactionHistorySyncedNote.
func (*WalletEmitter) TransactionNote ¶ added in v1.0.0
func (e *WalletEmitter) TransactionNote(tx *WalletTransaction, new bool)
TransactionNote sends a TransactionNote.
type WalletHistorian ¶ added in v1.0.0
type WalletHistorian interface { // TxHistory returns all the transactions a 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. TxHistory(n int, refID *string, past bool) ([]*WalletTransaction, error) // WalletTransaction returns a single transaction that either a wallet // has made or in which the wallet has received funds. This function may // support more transactions than are returned by TxHistory. For example, // ETH/token wallets do not return receiving transactions in TxHistory, // but WalletTransaction will return them. WalletTransaction(ctx context.Context, txID string) (*WalletTransaction, error) }
WalletHistorian is a wallet that is able to retrieve the history of all transactions it has made.
type WalletInfo ¶
type WalletInfo struct { // Name is the display name for the currency, e.g. "Decred" Name string `json:"name"` // SupportedVersions lists all supported asset versions. Several wallet // methods accept a version argument to indicate which contract to use, // however, the consumer (e.g. Core) is responsible for ensuring the // server's asset version is supported before using the Wallet. SupportedVersions []uint32 `json:"versions"` // AvailableWallets is an ordered list of available WalletDefinition. The // first WalletDefinition is considered the default, and might, for instance // be the initial form offered to the user for configuration, with others // available to select. AvailableWallets []*WalletDefinition `json:"availablewallets"` // LegacyWalletIndex should be set for assets that existed before wallets // were typed. The index should point to the WalletDefinition that should // be assumed when the type is provided as an empty string. LegacyWalletIndex int `json:"emptyidx"` // UnitInfo is the information about unit names and conversion factors for // the asset. UnitInfo dex.UnitInfo `json:"unitinfo"` // MaxSwapsInTx is the max amount of swaps that this wallet can do in a // single transaction. MaxSwapsInTx uint64 // MaxRedeemsInTx is the max amount of redemptions that this wallet can do // in a single transaction. MaxRedeemsInTx uint64 // IsAccountBased should be set to true for account-based (EVM) assets, so // that a common seed will be generated and wallets will generate the // same address. IsAccountBased bool }
WalletInfo is auxiliary information about an ExchangeWallet.
func Info ¶
func Info(assetID uint32) (*WalletInfo, error)
Info returns the WalletInfo for the specified asset, if supported. Info only returns WalletInfo for base chain assets, not tokens.
type WalletNotification ¶ added in v1.0.0
type WalletNotification any
WalletNotification can be any asynchronous information the wallet needs to convey.
type WalletPeer ¶ added in v0.6.0
type WalletPeer struct { Addr string `json:"addr"` Source PeerSource `json:"source"` Connected bool `json:"connected"` }
WalletPeer provides information about a wallet's peer.
type WalletRestoration ¶ added in v0.5.0
type WalletRestoration struct { Target string `json:"target"` Seed string `json:"seed"` // SeedName is the name of the seed used for this particular wallet, i.e // Private Key. SeedName string `json:"seedName"` Instructions string `json:"instructions"` }
WalletRestoration contains all the information needed for a user to restore their wallet in an external wallet.
type WalletRestorer ¶ added in v0.5.0
type WalletRestorer interface { // RestorationInfo returns information about how to restore the wallet in // various external wallets. RestorationInfo(seed []byte) ([]*WalletRestoration, error) }
WalletRestorer is a wallet which gives information about how to restore itself in external wallet software.
type WalletTrait ¶ added in v0.4.1
type WalletTrait uint64
WalletTrait is a bitset indicating various optional wallet features, such as the presence of auxiliary methods like Rescan, Withdraw and Sweep.
const ( WalletTraitRescanner WalletTrait = 1 << iota // The Wallet is an asset.Rescanner. WalletTraitNewAddresser // The Wallet can generate new addresses on demand with NewAddress. WalletTraitLogFiler // The Wallet allows for downloading of a log file. WalletTraitFeeRater // Wallet can provide a fee rate for non-critical transactions WalletTraitAccelerator // This wallet can accelerate transactions using the CPFP technique WalletTraitRecoverer // The wallet is an asset.Recoverer. WalletTraitWithdrawer // The Wallet can withdraw a specific amount from an exchange wallet. WalletTraitSweeper // The Wallet can sweep all the funds, leaving no change. WalletTraitRestorer // The wallet is an asset.WalletRestorer WalletTraitTxFeeEstimator // The wallet can estimate transaction fees. WalletTraitPeerManager // The wallet can manage its peers. WalletTraitAuthenticator // The wallet require authentication. WalletTraitShielded // DEPRECATED. Left for ordering WalletTraitTokenApprover // The wallet is a TokenApprover WalletTraitAccountLocker // The wallet must have enough balance for redemptions before a trade. WalletTraitTicketBuyer // The wallet can participate in decred staking. WalletTraitHistorian // This wallet can return its transaction history WalletTraitFundsMixer // The wallet can mix funds. WalletTraitDynamicSwapper // The wallet has dynamic fees. )
func DetermineWalletTraits ¶ added in v0.4.1
func DetermineWalletTraits(w Wallet) (t WalletTrait)
DetermineWalletTraits returns the WalletTrait bitset for the provided Wallet.
func (WalletTrait) IsAccelerator ¶ added in v0.5.0
func (wt WalletTrait) IsAccelerator() bool
IsAccelerator tests if the WalletTrait has the WalletTraitAccelerator bit set, which indicates the presence of an Accelerate method.
func (WalletTrait) IsAccountLocker ¶ added in v1.0.0
func (wt WalletTrait) IsAccountLocker() bool
IsAccountLocker test if WalletTrait has WalletTraitAccountLocker bit set, which indicates the wallet implements the AccountLocker interface.
func (WalletTrait) IsAuthenticator ¶ added in v1.0.0
func (wt WalletTrait) IsAuthenticator() bool
IsAuthenticator tests if WalletTrait has WalletTraitAuthenticator bit set, which indicates authentication is required by wallet.
func (WalletTrait) IsDynamicSwapper ¶ added in v1.0.0
func (wt WalletTrait) IsDynamicSwapper() bool
IsDynamicSwapper tests if a wallet has the WalletTraitDynamicSwapper bit set, which indicates the wallet implements the DynamicSwapper interface. This also indicates that the wallet will initially report a higher estimated fee for transactions then when a transaction is confirmed, the actual fee will be known.
func (WalletTrait) IsFeeRater ¶ added in v0.4.3
func (wt WalletTrait) IsFeeRater() bool
IsFeeRater tests if the WalletTrait has the WalletTraitFeeRater bit set, which indicates the presence of a FeeRate method.
func (WalletTrait) IsFundsMixer ¶ added in v1.0.0
func (wt WalletTrait) IsFundsMixer() bool
IsFundsMixer tests if the WalletTrait has the WalletTraitFundsMixer bit set, which indicates the wallet implements the FundsMixer interface.
func (WalletTrait) IsHistorian ¶ added in v1.0.0
func (wt WalletTrait) IsHistorian() bool
IsHistorian tests if the WalletTrait has the WalletTraitHistorian bit set, which indicates the wallet implements the WalletHistorian interface.
func (WalletTrait) IsLogFiler ¶ added in v0.4.1
func (wt WalletTrait) IsLogFiler() bool
IsLogFiler tests if WalletTrait has the WalletTraitLogFiler bit set.
func (WalletTrait) IsNewAddresser ¶ added in v0.4.1
func (wt WalletTrait) IsNewAddresser() bool
IsNewAddresser tests if the WalletTrait has the WalletTraitNewAddresser bit set, which indicates the presence of a NewAddress method that will generate a new address on each call. If this method does not exist, the Address method should be assumed to always return the same receiving address.
func (WalletTrait) IsPeerManager ¶ added in v0.6.0
func (wt WalletTrait) IsPeerManager() bool
IsPeerManager tests if the WalletTrait has the WalletTraitPeerManager bit set, which indicates the wallet implements the PeerManager interface.
func (WalletTrait) IsRecoverer ¶ added in v0.5.0
func (wt WalletTrait) IsRecoverer() bool
IsRecoverer tests if the WalletTrait has the WalletTraitRecoverer bit set, which indicates the wallet implements the Recoverer interface.
func (WalletTrait) IsRescanner ¶ added in v0.4.1
func (wt WalletTrait) IsRescanner() bool
IsRescanner tests if the WalletTrait has the WalletTraitRescanner bit set.
func (WalletTrait) IsRestorer ¶ added in v0.5.0
func (wt WalletTrait) IsRestorer() bool
IsRestorer tests if the WalletTrait has the WalletTraitRestorer bit set, which indicates the wallet implements the WalletRestorer interface.
func (WalletTrait) IsSweeper ¶ added in v0.5.0
func (wt WalletTrait) IsSweeper() bool
IsSweeper tests if the WalletTrait has the WalletTraitSweeper bit set, which indicates the presence of a Sweep method.
func (WalletTrait) IsTicketBuyer ¶ added in v1.0.0
func (wt WalletTrait) IsTicketBuyer() bool
IsTicketBuyer tests if the WalletTrait has the WalletTraitTicketBuyer bit set, which indicates the wallet implements the TicketBuyer interface.
func (WalletTrait) IsTokenApprover ¶ added in v1.0.0
func (wt WalletTrait) IsTokenApprover() bool
IsTokenApprover tests if the WalletTrait has the WalletTraitTokenApprover bit set, which indicates the wallet implements the TokenApprover interface.
func (WalletTrait) IsTxFeeEstimator ¶ added in v0.6.0
func (wt WalletTrait) IsTxFeeEstimator() bool
IsTxFeeEstimator tests if the WalletTrait has the WalletTraitTxFeeEstimator bit set, which indicates the wallet implements the TxFeeEstimator interface.
func (WalletTrait) IsWithdrawer ¶ added in v0.5.0
func (wt WalletTrait) IsWithdrawer() bool
IsWithdrawer tests if the WalletTrait has the WalletTraitSender bit set, which indicates the presence of a Withdraw method.
type WalletTransaction ¶ added in v1.0.0
type WalletTransaction struct { Type TransactionType `json:"type"` ID string `json:"id"` Amount uint64 `json:"amount"` Fees uint64 `json:"fees"` // BlockNumber is 0 for txs in the mempool. BlockNumber uint64 `json:"blockNumber"` // Timestamp is the time the transaction was mined. Timestamp uint64 `json:"timestamp"` // TokenID will be non-nil if the BalanceDelta applies to the balance // of a token. TokenID *uint32 `json:"tokenID,omitempty"` // Recipient will be non-nil for Send/Receive transactions, and specifies the // recipient address of the transaction. Recipient *string `json:"recipient,omitempty"` // BondInfo will be non-nil for CreateBond and RedeemBond transactions. BondInfo *BondTxInfo `json:"bondInfo,omitempty"` // AdditionalData contains asset specific information, i.e. nonce // for ETH. AdditionalData map[string]string `json:"additionalData"` // Confirmed is true when the transaction is considered finalized. // Confirmed transactions are no longer updated and will be considered // finalized forever. Confirmed bool `json:"confirmed"` // Rejected will be true the transaction was rejected and did not have any // effect, though fees were incurred. Rejected bool `json:"rejected,omitempty"` }
WalletTransaction represents a transaction that was made by a wallet.
type Withdrawer ¶ added in v0.5.0
type Withdrawer interface { // Withdraw withdraws funds to the specified address. Fees are subtracted // from the value. Withdraw(address string, value, feeRate uint64) (Coin, error) }
Withdrawer is a wallet that can withdraw a certain amount from the source wallet/account.
type XYRange ¶ added in v0.5.0
type XYRange struct { Start XYRangePoint `json:"start"` End XYRangePoint `json:"end"` XUnit string `json:"xUnit"` YUnit string `json:"yUnit"` RoundX bool `json:"roundX"` RoundY bool `json:"roundY"` }
XYRange is an option in which the user's setting of one value is reflected in the other and possible values are restricted. The assumed relationship is linear, e.g. y = mx + b. The value submitted to FundOrder/Swap/Redeem should specify the x value.
type XYRangePoint ¶ added in v0.5.0
XYRangePoint is a point specifying the start or end of an XYRange.
Directories ¶
Path | Synopsis |
---|---|
electrum
Package electrum provides a client for an ElectrumX server.
|
Package electrum provides a client for an ElectrumX server. |
Package eth implements methods to work with ethereum swap contracts and transactions.
|
Package eth implements methods to work with ethereum swap contracts and transactions. |