dcrwallet

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// UnconfirmedHeight is the special case end height that is used to
	// obtain unconfirmed transactions from ListTransactionDetails.
	UnconfirmedHeight int32 = -1
)

Variables

View Source
var (
	// ErrOutputSpent is returned by the GetUtxo method if the target output
	// for lookup has already been spent.
	ErrOutputSpent = errors.New("target output has been spent")

	// ErrUnconnected is returned when an IO operation was requested by the
	// backend is not connected to the network.
	//
	// TODO(decred) this should probably be exported by lnwallet and
	// expected by the BlockChainIO interface.
	ErrUnconnected = errors.New("unconnected to the network")
)

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func GetUtxoWithHistorical added in v0.5.0

func GetUtxoWithHistorical(ctx context.Context, historical *chainscan.Historical, op *wire.OutPoint,
	pkScript []byte, heightHint uint32) (*wire.TxOut, error)

GetUtxoWithHistorical returns the original output referenced by the passed outpoint that created the target pkScript, searched for using the passed historical chain scanner.

func NetworkDir

func NetworkDir(dataDir string, chainParams *chaincfg.Params) string

NetworkDir returns the directory name of a network directory to hold wallet files.

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using slog.

Types

type Config

type Config struct {
	// DataDir is the name of the directory where the wallet's persistent
	// state should be stored.
	DataDir string

	// LogDir is the name of the directory which should be used to store
	// generated log files.
	LogDir string

	// PrivatePass is the private password to the underlying dcrwallet
	// instance. Without this, the wallet cannot be decrypted and operated.
	PrivatePass []byte

	// PublicPass is the optional public password to dcrwallet. This is
	// optionally used to encrypt public material such as public keys and
	// scripts.
	PublicPass []byte

	// HdSeed is an optional seed to feed into the wallet. If this is
	// unspecified, a new seed will be generated.
	HdSeed []byte

	// Birthday specifies the time at which this wallet was initially
	// created. It is used to bound rescans for used addresses.
	Birthday time.Time

	// FeeEstimator is an instance of the fee estimator interface which
	// will be used by the wallet to dynamically set transaction fees when
	// crafting transactions.
	FeeEstimator chainfee.Estimator

	// RecoveryWindow specifies the address look-ahead for which to scan
	// when restoring a wallet. The recovery window will apply to all
	// default BIP44 derivation paths.
	RecoveryWindow uint32

	// Syncer stores a specific implementation of a WalletSyncer (either an
	// RPC syncer or a SPV syncer) capabale of maintaining the wallet
	// backend synced to the chain.
	Syncer WalletSyncer

	// ChainIO is a direct connection to the blockchain IO driver needed by
	// the wallet.
	//
	// TODO(decred) Ideally this should be performed by wallet operations
	// but not all operations needed by the drivers are currently
	// implemented in the wallet.
	ChainIO lnwallet.BlockChainIO

	// NetParams is the net parameters for the target chain.
	NetParams *chaincfg.Params

	// Wallet is an unlocked wallet instance that is set if the
	// UnlockerService has already opened and unlocked the wallet. If this
	// is nil, then a wallet might have just been created or is simply not
	// encrypted at all, in which case it should be attempted to be loaded
	// normally when creating the DcrWallet.
	Wallet *wallet.Wallet

	// Loader is the loader used to initialize the Wallet field. If Wallet
	// is specified, then Loader MUST be specified as well.
	Loader *walletloader.Loader

	// BlockCache is an optional in-memory block cache.
	BlockCache *blockcache.BlockCache

	DB *channeldb.DB
}

Config is a struct which houses configuration parameters which modify the instance of DcrWallet generated by the New() function.

type DcrWallet

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

DcrWallet is an implementation of the lnwallet.WalletController interface backed by an active instance of dcrwallet. At the time of the writing of this documentation, this implementation requires a full dcrd node to operate.

This struct implements the input.input.Signer, lnWallet.Messageinput.Signer, keychain.SecretKeyRing and keychain.KeyRing interfaces.

Note that most of its functions might produce errors or panics until the wallet has been fully synced.

func New

func New(cfg Config) (*DcrWallet, error)

New returns a new fully initialized instance of DcrWallet given a valid configuration struct.

func (*DcrWallet) AbandonDoubleSpends added in v0.3.0

func (b *DcrWallet) AbandonDoubleSpends(spentOutpoints ...*wire.OutPoint) error

AbandonDoubleSpends abandons any unconfirmed transaction that also spends any of the specified outpoints.

This is part of the WalletController interface.

func (*DcrWallet) AddressInfo added in v0.6.0

AddressInfo returns info about a wallet address.

func (*DcrWallet) BackEnd

func (b *DcrWallet) BackEnd() string

BackEnd returns the underlying ChainService's name as a string.

This is a part of the WalletController interface.

func (*DcrWallet) BestBlock added in v0.2.0

func (b *DcrWallet) BestBlock() (int64, chainhash.Hash, int64, error)

func (*DcrWallet) ComputeInputScript

func (b *DcrWallet) ComputeInputScript(tx *wire.MsgTx,
	signDesc *input.SignDescriptor) (*input.Script, error)

ComputeInputScript generates a complete InputScript for the passed transaction with the signature as defined within the passed input.SignDescriptor. This method is capable of generating the proper input script only for regular p2pkh outputs.

This is a part of the WalletController interface.

func (*DcrWallet) ConfirmedBalance

func (b *DcrWallet) ConfirmedBalance(confs int32, accountName string) (dcrutil.Amount, error)

ConfirmedBalance returns the sum of all the wallet's unspent outputs that have at least confs confirmations. If confs is set to zero, then all unspent outputs, including those currently in the mempool will be included in the final sum.

This is a part of the WalletController interface.

TODO(matheusd) Remove witness argument, given that's not applicable to decred

func (*DcrWallet) CreateSimpleTx added in v0.2.0

func (b *DcrWallet) CreateSimpleTx(outputs []*wire.TxOut,
	feeRate chainfee.AtomPerKByte, minConfs int32, dryRun bool) (*txauthor.AuthoredTx, error)

CreateSimpleTx creates a Bitcoin transaction paying to the specified outputs. The transaction is not broadcasted to the network, but a new change address might be created in the wallet database. In the case the wallet has insufficient funds, or the outputs are non-standard, an error should be returned. This method also takes the target fee expressed in sat/kw that should be used when crafting the transaction.

NOTE: The dryRun argument can be set true to create a tx that doesn't alter the database. A tx created with this set to true SHOULD NOT be broadcasted.

This is a part of the WalletController interface.

func (*DcrWallet) DeriveNextAccount added in v0.3.8

func (b *DcrWallet) DeriveNextAccount(name string) error

func (*DcrWallet) ExportPrivKey added in v0.3.8

func (b *DcrWallet) ExportPrivKey(addr stdaddr.Address) (*secp256k1.PrivateKey, error)

func (*DcrWallet) FetchInputInfo

func (b *DcrWallet) FetchInputInfo(prevOut *wire.OutPoint) (*lnwallet.Utxo, error)

FetchInputInfo queries for the WalletController's knowledge of the passed outpoint. If the base wallet determines this output is under its control, then the original txout should be returned. Otherwise, a non-nil error value of ErrNotMine should be returned instead.

This is a part of the WalletController interface.

func (*DcrWallet) FetchTx added in v0.6.0

func (b *DcrWallet) FetchTx(txid chainhash.Hash) (*wire.MsgTx, error)

FetchTx attempts to fetch a transaction in the wallet's database identified by the passed transaction hash. If the transaction can't be found, then a nil pointer is returned.

This is a part of the WalletController interface.

func (*DcrWallet) FinalizePsbt added in v0.5.0

func (b *DcrWallet) FinalizePsbt(_ *psbt.Packet) error

FinalizePsbt currently does nothing.

func (*DcrWallet) FundPsbt added in v0.5.0

func (b *DcrWallet) FundPsbt(_ *psbt.Packet, _ int32,
	_ chainfee.AtomPerKByte, _ string) (int32, error)

FundPsbt currently does nothing.

func (*DcrWallet) GetBestBlock added in v0.3.0

func (b *DcrWallet) GetBestBlock() (*chainhash.Hash, int32, error)

GetBestBlock returns the current height and hash of the best known block within the main chain.

This method is a part of the lnwallet.BlockChainIO interface.

func (*DcrWallet) GetBlock added in v0.3.0

func (b *DcrWallet) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error)

GetBlock returns a raw block from the server given its hash.

This method is a part of the lnwallet.BlockChainIO interface.

func (*DcrWallet) GetBlockHash added in v0.3.0

func (b *DcrWallet) GetBlockHash(blockHeight int64) (*chainhash.Hash, error)

GetBlockHash returns the hash of the block in the best blockchain at the given height.

This method is a part of the lnwallet.BlockChainIO interface.

func (*DcrWallet) GetRecoveryInfo added in v0.3.0

func (b *DcrWallet) GetRecoveryInfo() (bool, float64, error)

GetRecoveryInfo returns the current status of the recovery of the wallet.

This is a part of the WalletController interface.

func (*DcrWallet) GetUtxo added in v0.3.0

func (b *DcrWallet) GetUtxo(op *wire.OutPoint, pkScript []byte,
	heightHint uint32, cancel <-chan struct{}) (*wire.TxOut, error)

GetUtxo returns the original output referenced by the passed outpoint that created the target pkScript.

This method is a part of the lnwallet.BlockChainIO interface.

func (*DcrWallet) GetWalletTransaction added in v0.4.0

func (b *DcrWallet) GetWalletTransaction(txh chainhash.Hash) (*lnwallet.WalletTransaction, error)

func (*DcrWallet) ImportAccount added in v0.3.8

func (b *DcrWallet) ImportAccount(name string, accountPubKey *hdkeychain.ExtendedKey, dryRun bool) (
	*wallet.AccountProperties, []stdaddr.Address, []stdaddr.Address, error)

ImportAccount imports the specified xpub into the wallet.

This is a part of the WalletController interface.

func (*DcrWallet) ImportPublicKey added in v0.3.8

func (b *DcrWallet) ImportPublicKey(pubKey *secp256k1.PublicKey) error

ImportPublicKey imports the specified public key into the wallet.

This is a part of the WalletController interface.

func (*DcrWallet) InitialSyncChannel added in v0.2.0

func (b *DcrWallet) InitialSyncChannel() <-chan struct{}

InitialSyncChannel returns the channel used to signal that wallet init has finished.

This is a part of the WalletController interface.

func (*DcrWallet) InternalWallet

func (b *DcrWallet) InternalWallet() *base.Wallet

InternalWallet returns a pointer to the internal base wallet which is the core of dcrwallet.

func (*DcrWallet) IsOurAddress

func (b *DcrWallet) IsOurAddress(a stdaddr.Address) bool

IsOurAddress checks if the passed address belongs to this wallet

This is a part of the WalletController interface.

func (*DcrWallet) IsSynced

func (b *DcrWallet) IsSynced() (bool, int64, error)

IsSynced returns a boolean indicating if from the PoV of the wallet, it has fully synced to the current best block in the main chain.

This is a part of the WalletController interface.

func (*DcrWallet) LabelTransaction added in v0.3.0

func (b *DcrWallet) LabelTransaction(hash chainhash.Hash, label string, overwrite bool) error

LabelTransaction adds the given external label to the specified transaction.

This is a part of the WalletController interface.

func (*DcrWallet) LastUnusedAddress added in v0.2.0

func (b *DcrWallet) LastUnusedAddress(addrType lnwallet.AddressType, accountName string) (
	stdaddr.Address, error)

LastUnusedAddress returns the last *unused* address known by the wallet. An address is unused if it hasn't received any payments. This can be useful in UIs in order to continually show the "freshest" address without having to worry about "address inflation" caused by continual refreshing. Similar to NewAddress it can derive a specified address type, and also optionally a change address.

func (*DcrWallet) LeaseOutput added in v0.3.0

LeaseOutput markes the output as used for some time.

This is a part of the WalletController interface.

func (*DcrWallet) ListAccounts added in v0.3.8

func (b *DcrWallet) ListAccounts(accountName string) ([]base.AccountProperties, error)

ListAccount lists existing wallet accounts.

This is a part of the WalletController interface.

func (*DcrWallet) ListLeasedOutputs added in v0.5.0

func (b *DcrWallet) ListLeasedOutputs() ([]*lnwallet.LockedOutput, error)

ListLeasedOutputs lists leased wallet outputs.

This is a part of the WalletController interface.

func (*DcrWallet) ListTransactionDetails

func (b *DcrWallet) ListTransactionDetails(startHeight,
	endHeight int32, accountName string) ([]*lnwallet.TransactionDetail, error)

ListTransactionDetails returns a list of all transactions which are relevant to the wallet.

This is a part of the WalletController interface.

func (*DcrWallet) ListUnspentWitness

func (b *DcrWallet) ListUnspentWitness(minConfs, maxConfs int32, accountName string) (
	[]*lnwallet.Utxo, error)

ListUnspentWitness returns a slice of all the unspent outputs the wallet controls which pay to witness programs either directly or indirectly.

This is a part of the WalletController interface.

func (*DcrWallet) LockOutpoint

func (b *DcrWallet) LockOutpoint(o wire.OutPoint)

LockOutpoint marks an outpoint as locked meaning it will no longer be deemed as eligible for coin selection. Locking outputs are utilized in order to avoid race conditions when selecting inputs for usage when funding a channel.

This is a part of the WalletController interface.

func (*DcrWallet) NewAddress

func (b *DcrWallet) NewAddress(t lnwallet.AddressType, change bool, accountName string) (stdaddr.Address, error)

NewAddress returns the next external or internal address for the wallet dictated by the value of the `change` parameter. If change is true, then an internal address will be returned, otherwise an external address should be returned.

This is a part of the WalletController interface.

func (*DcrWallet) PublishTransaction

func (b *DcrWallet) PublishTransaction(tx *wire.MsgTx, label string) error

PublishTransaction performs cursory validation (dust checks, etc), then finally broadcasts the passed transaction to the Decred network. If publishing the transaction fails, an error describing the reason is returned (currently ErrDoubleSpend). If the transaction is already published to the network (either in the mempool or chain) no error will be returned.

func (*DcrWallet) ReleaseOutput added in v0.3.0

func (b *DcrWallet) ReleaseOutput(lnwallet.LockID, wire.OutPoint) error

ReleaseOutput marks the output as unused.

This is a part of the WalletController interface.

func (*DcrWallet) RemoveDescendants added in v0.6.0

func (b *DcrWallet) RemoveDescendants(*wire.MsgTx) error

RemoveDescendants attempts to remove any transaction from the wallet's tx store (that may be unconfirmed) that spends outputs created by the passed transaction. This remove propagates recursively down the chain of descendent transactions.

This is a part of the WalletController interface.

func (*DcrWallet) RescanWallet added in v0.3.8

func (b *DcrWallet) RescanWallet(startHeight int32, progress func(height int32) error) error

func (*DcrWallet) ScriptForOutput added in v0.6.0

func (b *DcrWallet) ScriptForOutput(*wire.TxOut) (
	btcwalletcompat.ManagedPubKeyAddress, []byte, []byte, error)

func (*DcrWallet) SendOutputs

func (b *DcrWallet) SendOutputs(outputs []*wire.TxOut,
	feeRate chainfee.AtomPerKByte, minConfs int32, label, fromAccount string) (*wire.MsgTx, error)

SendOutputs funds, signs, and broadcasts a Decred transaction paying out to the specified outputs. In the case the wallet has insufficient funds, or the outputs are non-standard, a non-nil error will be returned.

This is a part of the WalletController interface.

func (*DcrWallet) SignMessage

func (b *DcrWallet) SignMessage(keyDesc keychain.KeyLocator,
	msg []byte, double bool) (*ecdsa.Signature, error)

SignMessage attempts to sign a target message with the private key that corresponds to the passed public key. If the target private key is unable to be found, then an error will be returned. The actual digest signed is the chainhash (blake256r14) of the passed message.

NOTE: This is a part of the Messageinput.Signer interface.

func (*DcrWallet) SignOutputRaw

func (b *DcrWallet) SignOutputRaw(tx *wire.MsgTx,
	signDesc *input.SignDescriptor) (input.Signature, error)

SignOutputRaw generates a signature for the passed transaction according to the data within the passed input.SignDescriptor.

This is a part of the WalletController interface.

func (*DcrWallet) SignPsbt added in v0.6.0

func (b *DcrWallet) SignPsbt(*psbt.Packet) error

SignPsbt does nothing.

func (*DcrWallet) Start

func (b *DcrWallet) Start() error

Start initializes the underlying rpc connection, the wallet itself, and begins syncing to the current available blockchain state.

This is a part of the WalletController interface.

func (*DcrWallet) Stop

func (b *DcrWallet) Stop() error

Stop signals the wallet for shutdown. Shutdown may entail closing any active sockets, database handles, stopping goroutines, etc.

This is a part of the WalletController interface.

func (*DcrWallet) SubscribeTransactions

func (b *DcrWallet) SubscribeTransactions() (lnwallet.TransactionSubscription, error)

SubscribeTransactions returns a TransactionSubscription client which is capable of receiving async notifications as new transactions related to the wallet are seen within the network, or found in blocks.

This is a part of the WalletController interface.

func (*DcrWallet) UnlockOutpoint

func (b *DcrWallet) UnlockOutpoint(o wire.OutPoint)

UnlockOutpoint unlocks a previously locked output, marking it eligible for coin selection.

This is a part of the WalletController interface.

type RPCChainIO added in v0.2.0

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

RPCChainIO implements the required methods for performing chain io services.

func NewRPCChainIO added in v0.2.0

func NewRPCChainIO(rpcConfig rpcclient.ConnConfig, net *chaincfg.Params,
	blockCache *blockcache.BlockCache) (*RPCChainIO, error)

NewRPCChainIO initializes a new blockchain IO implementation backed by a full dcrd node. It requires the config for reaching the dcrd instance and the corresponding network this instance should be in.

func (*RPCChainIO) GetBestBlock added in v0.2.0

func (s *RPCChainIO) GetBestBlock() (*chainhash.Hash, int32, error)

GetBestBlock returns the current height and hash of the best known block within the main chain.

This method is a part of the lnwallet.BlockChainIO interface.

func (*RPCChainIO) GetBlock added in v0.2.0

func (s *RPCChainIO) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error)

GetBlock returns a raw block from the server given its hash.

This method is a part of the lnwallet.BlockChainIO interface.

func (*RPCChainIO) GetBlockHash added in v0.2.0

func (s *RPCChainIO) GetBlockHash(blockHeight int64) (*chainhash.Hash, error)

GetBlockHash returns the hash of the block in the best blockchain at the given height.

This method is a part of the lnwallet.BlockChainIO interface.

func (*RPCChainIO) GetUtxo added in v0.2.0

func (s *RPCChainIO) GetUtxo(op *wire.OutPoint, pkScript []byte,
	heightHint uint32, cancel <-chan struct{}) (*wire.TxOut, error)

GetUtxo returns the original output referenced by the passed outpoint that create the target pkScript.

This method is a part of the lnwallet.BlockChainIO interface.

type RPCSyncer

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

RPCSyncer implements the required methods for synchronizing a DcrWallet instance using a full node dcrd backend.

func NewRPCSyncer

func NewRPCSyncer(rpcConfig rpcclient.ConnConfig, net *chaincfg.Params) (*RPCSyncer, error)

NewRPCSyncer initializes a new syncer backed by a full dcrd node. It requires the config for reaching the dcrd instance and the corresponding network this instance should be in.

type SPVSyncer added in v0.3.4

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

SPVSyncer implements the required methods for synchronizing a DcrWallet instance using the SPV method.

func NewSPVSyncer added in v0.3.4

func NewSPVSyncer(cfg *SPVSyncerConfig) (*SPVSyncer, error)

NewSPVSyncer initializes a new syncer backed by the dcrd network in SPV mode.

type SPVSyncerConfig added in v0.3.4

type SPVSyncerConfig struct {
	Peers      []string
	Net        *chaincfg.Params
	AppDataDir string
	DialFunc   p2p.DialFunc
}

type WalletSyncer

type WalletSyncer interface {
	// contains filtered or unexported methods
}

WalletSyncer is an exported interface for the available wallet sync backends (RPC, SPV, etc). While this interface is exported to ease construction of a Config structure, only implementations provided by this package are supported, since currently the implementation is tightly coupled to the DcrWallet struct.

The current backend implementations also implement the BlockChainIO interface.

Directories

Path Synopsis
Package loader provides a concurrent safe implementation of a wallet loader.
Package loader provides a concurrent safe implementation of a wallet loader.

Jump to

Keyboard shortcuts

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