dcr

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2021 License: BlueOak-1.0.0 Imports: 33 Imported by: 2

Documentation

Index

Constants

View Source
const ErrReorgDetected = dex.ErrorKind("reorg detected")

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

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

Backend is an asset backend for Decred. It has methods for fetching output information and subscribing to block updates. It maintains a cache of block data for quick lookups. Backend implements asset.Backend, so provides exported methods for DEX-related blockchain info.

func NewBackend

func NewBackend(configPath string, logger dex.Logger, network dex.Network) (*Backend, error)

NewBackend is the exported constructor by which the DEX will import the Backend. The provided context.Context should be canceled when the DEX application exits. If configPath is an empty string, the backend will attempt to read the settings directly from the dcrd config file in its default system location.

func (*Backend) BlockChannel

func (dcr *Backend) BlockChannel(size int) <-chan *asset.BlockUpdate

BlockChannel creates and returns a new channel on which to receive block updates. If the returned channel is ever blocking, there will be no error logged from the dcr package. Part of the asset.Backend interface.

func (*Backend) CheckAddress

func (dcr *Backend) CheckAddress(addr string) bool

CheckAddress checks that the given address is parseable.

func (*Backend) Contract

func (dcr *Backend) Contract(coinID []byte, redeemScript []byte) (asset.Contract, error)

Contract is part of the asset.Backend interface. An asset.Contract is an output that has been validated as a swap contract for the passed redeem script. A spendable output is one that can be spent in the next block. Every regular-tree output from a non-coinbase transaction is spendable immediately. Coinbase and stake tree outputs are only spendable after CoinbaseMaturity confirmations. Pubkey scripts can be P2PKH or P2SH in either regular- or stake-tree flavor. P2PKH supports two alternative signatures, Schnorr and Edwards. Multi-sig P2SH redeem scripts are supported as well.

func (*Backend) FeeCoin

func (dcr *Backend) FeeCoin(coinID []byte) (addr string, val uint64, confs int64, err error)

FeeCoin gets the recipient address, value, and confirmations of a transaction output encoded by the given coinID. A non-nil error is returned if the output's pubkey script is not a non-stake P2PKH requiring a single ECDSA-secp256k1 signature.

func (*Backend) FeeRate

func (dcr *Backend) FeeRate() (uint64, error)

FeeRate returns the current optimal fee rate in atoms / byte.

func (*Backend) FundingCoin

func (dcr *Backend) FundingCoin(coinID []byte, redeemScript []byte) (asset.FundingCoin, error)

FundingCoin is an unspent output.

func (*Backend) InitTxSize

func (dcr *Backend) InitTxSize() uint32

InitTxSize is an asset.Backend method that must produce the max size of a standardized atomic swap initialization transaction.

func (*Backend) InitTxSizeBase

func (dcr *Backend) InitTxSizeBase() uint32

InitTxSizeBase is InitTxSize not including an input.

func (*Backend) OutputSummary

func (dcr *Backend) OutputSummary(txHash *chainhash.Hash, vout uint32) (txOut *TxOutData, confs int64, err error)

OutputSummary gets transaction output data, including recipient addresses, value, script type, and number of required signatures, plus the current confirmations of a transaction output. If the output does not exist, an error will be returned. Non-standard scripts are not an error.

func (*Backend) Redemption

func (dcr *Backend) Redemption(redemptionID, contractID []byte) (asset.Coin, error)

Redemption is an input that redeems a swap contract.

func (*Backend) Run

func (dcr *Backend) Run(ctx context.Context)

Run processes the queue and monitors the application context. The dcrd-registered handlers should perform any necessary type conversion and then deposit the payload into the anyQ channel.

func (*Backend) Synced

func (dcr *Backend) Synced() (bool, error)

Synced is true if the blockchain is ready for action.

func (*Backend) ValidateCoinID

func (dcr *Backend) ValidateCoinID(coinID []byte) (string, error)

ValidateCoinID attempts to decode the coinID.

func (*Backend) ValidateContract

func (dcr *Backend) ValidateContract(contract []byte) error

ValidateContract ensures that the swap contract is constructed properly, and contains valid sender and receiver addresses.

func (*Backend) ValidateSecret

func (dcr *Backend) ValidateSecret(secret, contract []byte) bool

ValidateSecret checks that the secret satisfies the contract.

func (*Backend) ValidateXPub

func (dcr *Backend) ValidateXPub(xpub string) error

ValidateXPub validates the base-58 encoded extended key, and ensures that it is an extended public, not private, key.

func (*Backend) VerifyUnspentCoin

func (dcr *Backend) VerifyUnspentCoin(coinID []byte) error

VerifyUnspentCoin attempts to verify a coin ID by decoding the coin ID and retrieving the corresponding UTXO. If the coin is not found or no longer unspent, an asset.CoinNotFoundError is returned.

type Contract

type Contract struct {
	*Output
	// contains filtered or unexported fields
}

Contract is a transaction output containing a swap contract.

func (*Contract) LockTime

func (contract *Contract) LockTime() time.Time

LockTime is a method on the asset.Contract interface for reading the locktime in the contract script.

func (*Contract) RedeemScript

func (contract *Contract) RedeemScript() []byte

RedeemScript returns the Contract's redeem script.

func (*Contract) RefundAddress

func (contract *Contract) RefundAddress() string

RefundAddress is the refund address of this swap contract.

func (*Contract) SwapAddress

func (contract *Contract) SwapAddress() string

SwapAddress is the receiving address of this swap contract.

type DCRConfig

type DCRConfig struct {
	// RPCUser is the RPC username provided to dcrd configuration as the rpcuser
	// parameter.
	RPCUser string `long:"rpcuser" description:"Username for RPC connections"`
	// RPCPass is the RPC password provided to dcrd configuration as the rpcpass
	// parameter.
	RPCPass string `long:"rpcpass" description:"Password for RPC connections"`
	// RPCListen is the RPC network address provided to dcrd configuration as the
	// rpclisten parameter. If the value is an empty string, it will be set
	// to a default value for the network.
	RPCListen string `long:"rpclisten" description:"dcrd interface/port for RPC connections (default port: 9109, testnet: 19109)"`
	// RPCCert is the filepath to the dcrd TLS certificate. If it is not
	// provided, the default dcrd location will be assumed.
	RPCCert string `long:"rpccert" description:"File containing the certificate file"`
	// Context should be canceled when the program exits. This will cause some
	// cleanup to be performed during shutdown.
	Context context.Context
}

DCRConfig is passed to the constructor.

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) Setup

func (d *Driver) Setup(configPath string, logger dex.Logger, network dex.Network) (asset.Backend, error)

Setup creates the DCR backend. Start the backend with its Run method.

type Input

type Input struct {
	TXIO
	// contains filtered or unexported fields
}

Input is a transaction input.

func (*Input) Confirmations

func (input *Input) Confirmations() (int64, error)

Confirmations returns the number of confirmations on this input's transaction.

func (*Input) ID

func (input *Input) ID() []byte

ID returns the coin ID.

func (*Input) String

func (input *Input) String() string

String creates a human-readable representation of a Decred transaction input in the format "{txid = [transaction hash], vin = [input index]}".

func (*Input) Value

func (input *Input) Value() uint64

Value is the value of the previous output spent by the input.

type Output

type Output struct {
	TXIO
	// contains filtered or unexported fields
}

Output represents a transaction output.

func (*Output) Addresses

func (output *Output) Addresses() []string

func (*Output) Auth

func (output *Output) Auth(pubkeys, sigs [][]byte, msg []byte) error

Auth verifies that the output pays to the supplied public key(s). This is an asset.FundingCoin method.

func (*Output) Confirmations

func (output *Output) Confirmations() (int64, error)

Confirmations returns the number of confirmations for a transaction output. Because it is possible for an output that was once considered valid to later be considered invalid, this method can return an error to indicate the output is no longer valid. The definition of output validity should not be confused with the validity of regular tree transactions that is voted on by stakeholders. While stakeholder approval is a part of output validity, there are other considerations as well.

func (*Output) ID

func (output *Output) ID() []byte

ID returns the coin ID.

func (*Output) SpendSize

func (output *Output) SpendSize() uint32

SpendSize returns the maximum size of the serialized TxIn that spends this Output, in bytes.

func (*Output) String

func (output *Output) String() string

String creates a human-readable representation of a Decred transaction output in the format "{txid = [transaction hash], vout = [output index]}".

func (*Output) Value

func (output *Output) Value() uint64

Value is the output value, in atoms.

type TXIO

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

TXIO is common information stored with an Input or Output.

func (*TXIO) FeeRate

func (txio *TXIO) FeeRate() uint64

FeeRate returns the transaction fee rate, in atoms/byte.

func (*TXIO) TxID

func (txio *TXIO) TxID() string

TxID is a string identifier for the transaction, typically a hexadecimal representation of the byte-reversed transaction hash.

type Tx

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

Tx is information about a transaction. It must satisfy the asset.DEXTx interface to be DEX-compatible.

type TxOutData

type TxOutData struct {
	Value        uint64
	Addresses    []string
	SigsRequired int
	ScriptType   dexdcr.DCRScriptType
}

TxOutData is transaction output data, including recipient addresses, value, script type, and number of required signatures.

type UTXO

type UTXO struct {
	*Output
}

A UTXO is information regarding an unspent transaction output.

func (*UTXO) Confirmations

func (utxo *UTXO) Confirmations() (int64, error)

Confirmations returns the number of confirmations on this output's transaction. See also (*Output).Confirmations. This function differs from the Output method in that it is necessary to relocate the utxo after a reorg, it may error if the output is spent.

Jump to

Keyboard shortcuts

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