dcr

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2021 License: BlueOak-1.0.0 Imports: 35 Imported by: 10

Documentation

Index

Constants

View Source
const (

	// BipID is the BIP-0044 asset ID.
	BipID = 42
)

Variables

View Source
var (

	// WalletInfo defines some general information about a Decred wallet.
	WalletInfo = &asset.WalletInfo{
		Name:              "Decred",
		Units:             "atoms",
		Version:           version,
		DefaultConfigPath: defaultConfigPath,
		ConfigOpts:        configOpts,
	}
)

Functions

This section is empty.

Types

type Config

type Config struct {
	RPCUser          string  `ini:"username"`
	RPCPass          string  `ini:"password"`
	RPCListen        string  `ini:"rpclisten"`
	RPCCert          string  `ini:"rpccert"`
	UseSplitTx       bool    `ini:"txsplit"`
	FallbackFeeRate  float64 `ini:"fallbackfee"`
	FeeRateLimit     float64 `ini:"feeratelimit"`
	RedeemConfTarget uint64  `ini:"redeemconftarget"`
	// Context should be canceled when the application exits. This will cause
	// some cleanup to be performed during shutdown.
	Context context.Context `ini:"-"`
}

Config holds the parameters needed to initialize an RPC connection to a dcr wallet. Default values are used for RPCListen and/or RPCCert if not set.

type Driver

type Driver struct{}

Driver implements asset.Driver.

func (*Driver) DecodeCoinID

func (d *Driver) DecodeCoinID(coinID []byte) (string, error)

DecodeCoinID creates a human-readable representation of a coin ID for Decred.

func (*Driver) Info

func (d *Driver) Info() *asset.WalletInfo

Info returns basic information about the wallet and asset. WARNING: An ExchangeWallet instance may have different DefaultFeeRate set, so use (*ExchangeWallet).Info when possible.

func (*Driver) Setup

func (d *Driver) Setup(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network) (asset.Wallet, error)

Setup creates the DCR exchange wallet. Start the wallet with its Run method.

type ExchangeWallet

type ExchangeWallet struct {
	// contains filtered or unexported fields
}

ExchangeWallet is a wallet backend for Decred. The backend is how the DEX client app communicates with the Decred blockchain and wallet. ExchangeWallet satisfies the dex.Wallet interface.

func NewWallet

func NewWallet(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network) (*ExchangeWallet, error)

NewWallet is the exported constructor by which the DEX will import the exchange wallet. The wallet will shut down when the provided context is canceled.

func (*ExchangeWallet) Address

func (dcr *ExchangeWallet) Address() (string, error)

Address returns an address for the exchange wallet.

func (*ExchangeWallet) AuditContract

func (dcr *ExchangeWallet) AuditContract(coinID, contract, txData dex.Bytes) (*asset.AuditInfo, error)

AuditContract retrieves information about a swap contract on the blockchain. This would be used to verify the counter-party's contract during a swap.

func (*ExchangeWallet) Balance

func (dcr *ExchangeWallet) Balance() (*asset.Balance, error)

Balance should return the total available funds in the wallet. Note that after calling Fund, the amount returned by Balance may change by more than the value funded. Part of the asset.Wallet interface. TODO: Since this includes potentially untrusted 0-conf utxos, consider prioritizing confirmed utxos when funding an order.

func (*ExchangeWallet) Confirmations

func (dcr *ExchangeWallet) Confirmations(ctx context.Context, id dex.Bytes) (confs uint32, spent bool, err error)

Confirmations gets the number of confirmations for the specified coin ID by first checking for a unspent output, and if not found, searching indexed wallet transactions.

func (*ExchangeWallet) Connect

func (dcr *ExchangeWallet) Connect(ctx context.Context) (*sync.WaitGroup, error)

Connect connects the wallet to the RPC server. Satisfies the dex.Connector interface. WARNING: Once stopped, it cannot reconnect, requiring NewWallet to construct a new ExchangeWallet to Connect again.

func (*ExchangeWallet) FindRedemption

func (dcr *ExchangeWallet) FindRedemption(ctx context.Context, coinID dex.Bytes) (redemptionCoin, secret dex.Bytes, err error)

FindRedemption watches for the input that spends the specified contract coin, and returns the spending input and the contract's secret key when it finds a spender.

This method blocks until the redemption is found, an error occurs or the provided context is canceled.

func (*ExchangeWallet) FundOrder

func (dcr *ExchangeWallet) FundOrder(ord *asset.Order) (asset.Coins, []dex.Bytes, 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 (*ExchangeWallet) FundingCoins

func (dcr *ExchangeWallet) FundingCoins(ids []dex.Bytes) (asset.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.

func (*ExchangeWallet) Info

func (dcr *ExchangeWallet) Info() *asset.WalletInfo

Info returns basic information about the wallet and asset.

func (*ExchangeWallet) Lock

func (dcr *ExchangeWallet) Lock() error

Lock locks the exchange wallet.

func (*ExchangeWallet) Locked

func (dcr *ExchangeWallet) Locked() bool

Locked will be true if the wallet is currently locked. Q: why are we ignoring RPC errors in this?

func (*ExchangeWallet) LocktimeExpired

func (dcr *ExchangeWallet) LocktimeExpired(contract dex.Bytes) (bool, time.Time, error)

LocktimeExpired returns true if the specified contract's locktime has expired, making it possible to issue a Refund.

func (*ExchangeWallet) MaxOrder added in v0.2.0

func (dcr *ExchangeWallet) MaxOrder(lotSize, feeSuggestion uint64, nfo *dex.Asset) (*asset.SwapEstimate, error)

MaxOrder generates information about the maximum order size and associated fees that the wallet can support for the given DEX configuration. The fees are an estimate based on current network conditions, and will be <= the fees associated with nfo.MaxFeeRate. For quote assets, the caller will have to calculate lotSize based on a rate conversion from the base asset's lot size. lotSize must not be zero and will cause a panic if so.

func (*ExchangeWallet) OwnsAddress

func (dcr *ExchangeWallet) OwnsAddress(address string) (bool, error)

OwnsAddress indicates if an address belongs to the wallet.

func (*ExchangeWallet) PayFee

func (dcr *ExchangeWallet) PayFee(address string, regFee uint64) (asset.Coin, error)

PayFee sends the dex registration fee. Transaction fees are in addition to the registration fee, and the fee rate is taken from the DEX configuration.

func (*ExchangeWallet) PreRedeem added in v0.2.0

func (dcr *ExchangeWallet) PreRedeem(req *asset.PreRedeemForm) (*asset.PreRedeem, error)

PreRedeem generates an estimate of the range of redemption fees that could be assessed.

func (*ExchangeWallet) PreSwap added in v0.2.0

func (dcr *ExchangeWallet) PreSwap(req *asset.PreSwapForm) (*asset.PreSwap, error)

PreSwap get order estimates based on the available funds and the wallet configuration.

func (*ExchangeWallet) Redeem

func (dcr *ExchangeWallet) Redeem(form *asset.RedeemForm) ([]dex.Bytes, asset.Coin, uint64, error)

Redeem sends the redemption transaction, which may contain more than one redemption.

func (*ExchangeWallet) Refund

func (dcr *ExchangeWallet) Refund(coinID, contract dex.Bytes) (dex.Bytes, error)

Refund refunds a contract. This can only be used after the time lock has expired. NOTE: The contract cannot be retrieved from the unspent coin info as the wallet does not store it, even though it was known when the init transaction was created. The client should store this information for persistence across sessions.

func (*ExchangeWallet) ReturnCoins

func (dcr *ExchangeWallet) ReturnCoins(unspents asset.Coins) error

ReturnCoins unlocks coins. This would be necessary in the case of a canceled order.

func (*ExchangeWallet) SignMessage

func (dcr *ExchangeWallet) SignMessage(coin asset.Coin, msg dex.Bytes) (pubkeys, sigs []dex.Bytes, err error)

SignMessage signs the message with the private key associated with the specified funding Coin. A slice of pubkeys required to spend the Coin and a signature for each pubkey are returned.

func (*ExchangeWallet) Swap

func (dcr *ExchangeWallet) Swap(swaps *asset.Swaps) ([]asset.Receipt, asset.Coin, uint64, error)

Swap sends the swaps in a single transaction. The Receipts returned can be used to refund a failed transaction. The Input coins are manually unlocked because they're not auto-unlocked by the wallet and therefore inaccurately included as part of the locked balance despite being spent.

func (*ExchangeWallet) SyncStatus

func (dcr *ExchangeWallet) SyncStatus() (bool, float32, error)

SyncStatus is information about the blockchain sync status.

func (*ExchangeWallet) Unlock

func (dcr *ExchangeWallet) Unlock(pw string) error

Unlock unlocks the exchange wallet.

func (*ExchangeWallet) ValidateSecret

func (dcr *ExchangeWallet) ValidateSecret(secret, secretHash []byte) bool

ValidateSecret checks that the secret satisfies the contract.

func (*ExchangeWallet) Withdraw

func (dcr *ExchangeWallet) Withdraw(address string, value uint64) (asset.Coin, error)

Withdraw withdraws funds to the specified address. Fees are subtracted from the value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL