Documentation ¶
Index ¶
- Constants
- Variables
- func DisableLog()
- func NetworkDir(dataDir string, chainParams *chaincfg.Params) string
- func NewWalletLoader(chainParams *chaincfg.Params, recoveryWindow uint32, opts ...LoaderOption) (*wallet.Loader, error)
- func UseLogger(logger btclog.Logger)
- type BtcWallet
- func (b *BtcWallet) AddressInfo(a btcutil.Address) (waddrmgr.ManagedAddress, error)
- func (b *BtcWallet) BackEnd() string
- func (b *BtcWallet) ComputeInputScript(tx *wire.MsgTx, signDesc *input.SignDescriptor) (*input.Script, error)
- func (b *BtcWallet) ConfirmedBalance(confs int32, accountFilter string) (btcutil.Amount, error)
- func (b *BtcWallet) CreateSimpleTx(outputs []*wire.TxOut, feeRate chainfee.SatPerKWeight, minConfs int32, ...) (*txauthor.AuthoredTx, error)
- func (b *BtcWallet) FetchInputInfo(prevOut *wire.OutPoint) (*lnwallet.Utxo, error)
- func (b *BtcWallet) FetchTx(txHash chainhash.Hash) (*wire.MsgTx, error)
- func (b *BtcWallet) FinalizePsbt(packet *psbt.Packet, accountName string) error
- func (b *BtcWallet) FundPsbt(packet *psbt.Packet, minConfs int32, feeRate chainfee.SatPerKWeight, ...) (int32, error)
- func (b *BtcWallet) GetBestBlock() (*chainhash.Hash, int32, error)
- func (b *BtcWallet) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error)
- func (b *BtcWallet) GetBlockHash(blockHeight int64) (*chainhash.Hash, error)
- func (b *BtcWallet) GetRecoveryInfo() (bool, float64, error)
- func (b *BtcWallet) GetUtxo(op *wire.OutPoint, pkScript []byte, heightHint uint32, cancel <-chan struct{}) (*wire.TxOut, error)
- func (b *BtcWallet) ImportAccount(name string, accountPubKey *hdkeychain.ExtendedKey, ...) (*waddrmgr.AccountProperties, []btcutil.Address, []btcutil.Address, error)
- func (b *BtcWallet) ImportPublicKey(pubKey *btcec.PublicKey, addrType waddrmgr.AddressType) error
- func (b *BtcWallet) InternalWallet() *base.Wallet
- func (b *BtcWallet) IsOurAddress(a btcutil.Address) bool
- func (b *BtcWallet) IsSynced() (bool, int64, error)
- func (b *BtcWallet) LabelTransaction(hash chainhash.Hash, label string, overwrite bool) error
- func (b *BtcWallet) LastUnusedAddress(addrType lnwallet.AddressType, accountName string) (btcutil.Address, error)
- func (b *BtcWallet) LeaseOutput(id wtxmgr.LockID, op wire.OutPoint, duration time.Duration) (time.Time, error)
- func (b *BtcWallet) ListAccounts(name string, keyScope *waddrmgr.KeyScope) ([]*waddrmgr.AccountProperties, error)
- func (b *BtcWallet) ListLeasedOutputs() ([]*wtxmgr.LockedOutput, error)
- func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32, accountFilter string) ([]*lnwallet.TransactionDetail, error)
- func (b *BtcWallet) ListUnspentWitness(minConfs, maxConfs int32, accountFilter string) ([]*lnwallet.Utxo, error)
- func (b *BtcWallet) LockOutpoint(o wire.OutPoint)
- func (b *BtcWallet) NewAddress(t lnwallet.AddressType, change bool, accountName string) (btcutil.Address, error)
- func (b *BtcWallet) PublishTransaction(tx *wire.MsgTx, label string) error
- func (b *BtcWallet) ReleaseOutput(id wtxmgr.LockID, op wire.OutPoint) error
- func (b *BtcWallet) RemoveDescendants(tx *wire.MsgTx) error
- func (b *BtcWallet) ScriptForOutput(output *wire.TxOut) (waddrmgr.ManagedPubKeyAddress, []byte, []byte, error)
- func (b *BtcWallet) SendOutputs(outputs []*wire.TxOut, feeRate chainfee.SatPerKWeight, minConfs int32, ...) (*wire.MsgTx, error)
- func (b *BtcWallet) SignMessage(keyLoc keychain.KeyLocator, msg []byte, doubleHash bool) (*btcec.Signature, error)
- func (b *BtcWallet) SignOutputRaw(tx *wire.MsgTx, signDesc *input.SignDescriptor) (input.Signature, error)
- func (b *BtcWallet) SignPsbt(packet *psbt.Packet) error
- func (b *BtcWallet) Start() error
- func (b *BtcWallet) Stop() error
- func (b *BtcWallet) SubscribeTransactions() (lnwallet.TransactionSubscription, error)
- func (b *BtcWallet) UnlockOutpoint(o wire.OutPoint)
- type Config
- type LoaderOption
Constants ¶
const Subsystem = "BTWL"
Subsystem defines the logging code for this subsystem.
const ( // UnconfirmedHeight is the special case end height that is used to // obtain unconfirmed transactions from ListTransactionDetails. UnconfirmedHeight int32 = -1 )
Variables ¶
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") // ErrOutputNotFound signals that the desired output could not be // located. ErrOutputNotFound = errors.New("target output was not found") )
var ( // PsbtKeyTypeInputSignatureTweakSingle is a custom/proprietary PSBT key // for an input that specifies what single tweak should be applied to // the key before signing the input. The value 51 is leet speak for // "si", short for "single". PsbtKeyTypeInputSignatureTweakSingle = []byte{0x51} // PsbtKeyTypeInputSignatureTweakDouble is a custom/proprietary PSBT key // for an input that specifies what double tweak should be applied to // the key before signing the input. The value d0 is leet speak for // "do", short for "double". PsbtKeyTypeInputSignatureTweakDouble = []byte{0xd0} )
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
func NetworkDir ¶
NetworkDir returns the directory name of a network directory to hold wallet files.
func NewWalletLoader ¶
func NewWalletLoader(chainParams *chaincfg.Params, recoveryWindow uint32, opts ...LoaderOption) (*wallet.Loader, error)
NewWalletLoader constructs a wallet loader.
Types ¶
type BtcWallet ¶
type BtcWallet struct {
// contains filtered or unexported fields
}
BtcWallet is an implementation of the lnwallet.WalletController interface backed by an active instance of btcwallet. At the time of the writing of this documentation, this implementation requires a full btcd node to operate.
func New ¶
func New(cfg Config, blockCache *blockcache.BlockCache) (*BtcWallet, error)
New returns a new fully initialized instance of BtcWallet given a valid configuration struct.
func (*BtcWallet) AddressInfo ¶
AddressInfo returns the information about an address, if it's known to this wallet.
NOTE: This is a part of the WalletController interface.
func (*BtcWallet) BackEnd ¶
BackEnd returns the underlying ChainService's name as a string.
This is a part of the WalletController interface.
func (*BtcWallet) ComputeInputScript ¶
func (b *BtcWallet) 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 SignDescriptor. This method is capable of generating the proper input script for both regular p2wkh output and p2wkh outputs nested within a regular p2sh output.
This is a part of the WalletController interface.
func (*BtcWallet) ConfirmedBalance ¶
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. The account parameter serves as a filter to retrieve the balance for a specific account. When empty, the confirmed balance of all wallet accounts is returned.
This is a part of the WalletController interface.
func (*BtcWallet) CreateSimpleTx ¶
func (b *BtcWallet) CreateSimpleTx(outputs []*wire.TxOut, feeRate chainfee.SatPerKWeight, 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.
NOTE: This method requires the global coin selection lock to be held.
This is a part of the WalletController interface.
func (*BtcWallet) FetchInputInfo ¶
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 (*BtcWallet) FetchTx ¶
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.
func (*BtcWallet) FinalizePsbt ¶
FinalizePsbt expects a partial transaction with all inputs and outputs fully declared and tries to sign all inputs that belong to the specified account. Lnd must be the last signer of the transaction. That means, if there are any unsigned non-witness inputs or inputs without UTXO information attached or inputs without witness data that do not belong to lnd's wallet, this method will fail. If no error is returned, the PSBT is ready to be extracted and the final TX within to be broadcast.
NOTE: This method does NOT publish the transaction after it's been finalized successfully.
This is a part of the WalletController interface.
func (*BtcWallet) FundPsbt ¶
func (b *BtcWallet) FundPsbt(packet *psbt.Packet, minConfs int32, feeRate chainfee.SatPerKWeight, accountName string) (int32, error)
FundPsbt creates a fully populated PSBT packet that contains enough inputs to fund the outputs specified in the passed in packet with the specified fee rate. If there is change left, a change output from the internal wallet is added and the index of the change output is returned. Otherwise no additional output is created and the index -1 is returned.
NOTE: If the packet doesn't contain any inputs, coin selection is performed automatically. The account parameter must be non-empty as it determines which set of coins are eligible for coin selection. If the packet does contain any inputs, it is assumed that full coin selection happened externally and no additional inputs are added. If the specified inputs aren't enough to fund the outputs with the given fee rate, an error is returned. No lock lease is acquired for any of the selected/validated inputs. It is in the caller's responsibility to lock the inputs before handing them out.
This is a part of the WalletController interface.
func (*BtcWallet) GetBestBlock ¶
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 (*BtcWallet) GetBlock ¶
GetBlock returns a raw block from the server given its hash. For the Neutrino implementation of the lnwallet.BlockChainIO interface, the Neutrino GetBlock method is called directly. For other implementations, the block cache is used to wrap the call to GetBlock.
This method is a part of the lnwallet.BlockChainIO interface.
func (*BtcWallet) GetBlockHash ¶
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 (*BtcWallet) GetRecoveryInfo ¶
GetRecoveryInfo returns a boolean indicating whether the wallet is started in recovery mode. It also returns a float64, ranging from 0 to 1, representing the recovery progress made so far.
This is a part of the WalletController interface.
func (*BtcWallet) GetUtxo ¶
func (b *BtcWallet) 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 creates the target pkScript.
This method is a part of the lnwallet.BlockChainIO interface.
func (*BtcWallet) ImportAccount ¶
func (b *BtcWallet) ImportAccount(name string, accountPubKey *hdkeychain.ExtendedKey, masterKeyFingerprint uint32, addrType *waddrmgr.AddressType, dryRun bool) (*waddrmgr.AccountProperties, []btcutil.Address, []btcutil.Address, error)
ImportAccount imports an account backed by an account extended public key. The master key fingerprint denotes the fingerprint of the root key corresponding to the account public key (also known as the key with derivation path m/). This may be required by some hardware wallets for proper identification and signing.
The address type can usually be inferred from the key's version, but may be required for certain keys to map them into the proper scope.
For BIP-0044 keys, an address type must be specified as we intend to not support importing BIP-0044 keys into the wallet using the legacy pay-to-pubkey-hash (P2PKH) scheme. A nested witness address type will force the standard BIP-0049 derivation scheme, while a witness address type will force the standard BIP-0084 derivation scheme.
For BIP-0049 keys, an address type must also be specified to make a distinction between the standard BIP-0049 address schema (nested witness pubkeys everywhere) and our own BIP-0049Plus address schema (nested pubkeys externally, witness pubkeys internally).
This is a part of the WalletController interface.
func (*BtcWallet) ImportPublicKey ¶
ImportPublicKey imports a single derived public key into the wallet. The address type can usually be inferred from the key's version, but in the case of legacy versions (xpub, tpub), an address type must be specified as we intend to not support importing BIP-44 keys into the wallet using the legacy pay-to-pubkey-hash (P2PKH) scheme.
This is a part of the WalletController interface.
func (*BtcWallet) InternalWallet ¶
InternalWallet returns a pointer to the internal base wallet which is the core of btcwallet.
func (*BtcWallet) IsOurAddress ¶
IsOurAddress checks if the passed address belongs to this wallet
This is a part of the WalletController interface.
func (*BtcWallet) IsSynced ¶
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 (*BtcWallet) LabelTransaction ¶
LabelTransaction adds a label to a transaction. If the tx already has a label, this call will fail unless the overwrite parameter is set. Labels must not be empty, and they are limited to 500 chars.
Note: it is part of the WalletController interface.
func (*BtcWallet) LastUnusedAddress ¶
func (b *BtcWallet) LastUnusedAddress(addrType lnwallet.AddressType, accountName string) (btcutil.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. The account parameter must be non-empty as it determines which account the address should be generated from.
func (*BtcWallet) LeaseOutput ¶
func (b *BtcWallet) LeaseOutput(id wtxmgr.LockID, op wire.OutPoint, duration time.Duration) (time.Time, error)
LeaseOutput locks an output to the given ID, preventing it from being available for any future coin selection attempts. The absolute time of the lock's expiration is returned. The expiration of the lock can be extended by successive invocations of this call. Outputs can be unlocked before their expiration through `ReleaseOutput`.
If the output is not known, wtxmgr.ErrUnknownOutput is returned. If the output has already been locked to a different ID, then wtxmgr.ErrOutputAlreadyLocked is returned.
NOTE: This method requires the global coin selection lock to be held.
func (*BtcWallet) ListAccounts ¶
func (b *BtcWallet) ListAccounts(name string, keyScope *waddrmgr.KeyScope) ([]*waddrmgr.AccountProperties, error)
ListAccounts retrieves all accounts belonging to the wallet by default. A name and key scope filter can be provided to filter through all of the wallet accounts and return only those matching.
This is a part of the WalletController interface.
func (*BtcWallet) ListLeasedOutputs ¶
func (b *BtcWallet) ListLeasedOutputs() ([]*wtxmgr.LockedOutput, error)
ListLeasedOutputs returns a list of all currently locked outputs.
func (*BtcWallet) ListTransactionDetails ¶
func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32, accountFilter string) ([]*lnwallet.TransactionDetail, error)
ListTransactionDetails returns a list of all transactions which are relevant to the wallet over [startHeight;endHeight]. If start height is greater than end height, the transactions will be retrieved in reverse order. To include unconfirmed transactions, endHeight should be set to the special value -1. This will return transactions from the tip of the chain until the start height (inclusive) and unconfirmed transactions. The account parameter serves as a filter to retrieve the transactions relevant to a specific account. When empty, transactions of all wallet accounts are returned.
This is a part of the WalletController interface.
func (*BtcWallet) ListUnspentWitness ¶
func (b *BtcWallet) ListUnspentWitness(minConfs, maxConfs int32, accountFilter string) ([]*lnwallet.Utxo, error)
ListUnspentWitness returns all unspent outputs which are version 0 witness programs. The 'minConfs' and 'maxConfs' parameters indicate the minimum and maximum number of confirmations an output needs in order to be returned by this method. Passing -1 as 'minConfs' indicates that even unconfirmed outputs should be returned. Using MaxInt32 as 'maxConfs' implies returning all outputs with at least 'minConfs'. The account parameter serves as a filter to retrieve the unspent outputs for a specific account. When empty, the unspent outputs of all wallet accounts are returned.
NOTE: This method requires the global coin selection lock to be held.
This is a part of the WalletController interface.
func (*BtcWallet) LockOutpoint ¶
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.
NOTE: This method requires the global coin selection lock to be held.
This is a part of the WalletController interface.
func (*BtcWallet) NewAddress ¶
func (b *BtcWallet) NewAddress(t lnwallet.AddressType, change bool, accountName string) (btcutil.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. The account parameter must be non-empty as it determines which account the address should be generated from.
This is a part of the WalletController interface.
func (*BtcWallet) PublishTransaction ¶
PublishTransaction performs cursory validation (dust checks, etc), then finally broadcasts the passed transaction to the Bitcoin 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 (*BtcWallet) ReleaseOutput ¶
ReleaseOutput unlocks an output, allowing it to be available for coin selection if it remains unspent. The ID should match the one used to originally lock the output.
NOTE: This method requires the global coin selection lock to be held.
func (*BtcWallet) RemoveDescendants ¶
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.
func (*BtcWallet) ScriptForOutput ¶
func (b *BtcWallet) ScriptForOutput(output *wire.TxOut) ( waddrmgr.ManagedPubKeyAddress, []byte, []byte, error)
ScriptForOutput returns the address, witness program and redeem script for a given UTXO. An error is returned if the UTXO does not belong to our wallet or it is not a managed pubKey address.
func (*BtcWallet) SendOutputs ¶
func (b *BtcWallet) SendOutputs(outputs []*wire.TxOut, feeRate chainfee.SatPerKWeight, minConfs int32, label string) (*wire.MsgTx, error)
SendOutputs funds, signs, and broadcasts a Bitcoin 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.
NOTE: This method requires the global coin selection lock to be held.
This is a part of the WalletController interface.
func (*BtcWallet) SignMessage ¶
func (b *BtcWallet) SignMessage(keyLoc keychain.KeyLocator, msg []byte, doubleHash bool) (*btcec.Signature, error)
SignMessage attempts to sign a target message with the private key that corresponds to the passed key locator. If the target private key is unable to be found, then an error will be returned. The actual digest signed is the double SHA-256 of the passed message.
NOTE: This is a part of the MessageSigner interface.
func (*BtcWallet) SignOutputRaw ¶
func (b *BtcWallet) 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 SignDescriptor.
This is a part of the WalletController interface.
func (*BtcWallet) SignPsbt ¶
SignPsbt expects a partial transaction with all inputs and outputs fully declared and tries to sign all unsigned inputs that have all required fields (UTXO information, BIP32 derivation information, witness or sig scripts) set. If no error is returned, the PSBT is ready to be given to the next signer or to be finalized if lnd was the last signer.
NOTE: This method only signs inputs (and only those it can sign), it does not perform any other tasks (such as coin selection, UTXO locking or input/output/fee value validation, PSBT finalization). Any input that is incomplete will be skipped.
func (*BtcWallet) Start ¶
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 (*BtcWallet) Stop ¶
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 (*BtcWallet) SubscribeTransactions ¶
func (b *BtcWallet) 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 (*BtcWallet) UnlockOutpoint ¶
UnlockOutpoint unlocks a previously locked output, marking it eligible for coin selection.
NOTE: This method requires the global coin selection lock to be held.
This is a part of the WalletController interface.
type Config ¶
type Config struct { // 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 btcwallet // instance. Without this, the wallet cannot be decrypted and operated. PrivatePass []byte // PublicPass is the optional public password to btcwallet. 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 // 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 // ChainSource is the primary chain interface. This is used to operate // the wallet and do things such as rescanning, sending transactions, // notifications for received funds, etc. ChainSource chain.Interface // NetParams is the net parameters for the target chain. NetParams *chaincfg.Params // CoinType specifies the BIP 44 coin type to be used for derivation. CoinType uint32 // 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 BtcWallet. Wallet *wallet.Wallet // LoaderOptions holds functional wallet db loader options. LoaderOptions []LoaderOption // CoinSelectionStrategy is the strategy that is used for selecting // coins when funding a transaction. CoinSelectionStrategy wallet.CoinSelectionStrategy // WatchOnly indicates that the wallet was initialized with public key // material only and does not contain any private keys. WatchOnly bool // MigrateWatchOnly indicates that if a wallet with private key material // already exists, it should be attempted to be converted into a // watch-only wallet on first startup. This flag has no effect if no // wallet exists and a watch-only one is created directly, or, if the // wallet was previously converted to a watch-only already. MigrateWatchOnly bool }
Config is a struct which houses configuration parameters which modify the instance of BtcWallet generated by the New() function.
type LoaderOption ¶
type LoaderOption func(*loaderCfg)
LoaderOption is a functional option to update the optional loader config.
func LoaderWithExternalWalletDB ¶
func LoaderWithExternalWalletDB(db kvdb.Backend) LoaderOption
LoaderWithExternalWalletDB configures the wallet loadr to use an external db.
func LoaderWithLocalWalletDB ¶
func LoaderWithLocalWalletDB(dbDirPath string, noFreelistSync bool, dbTimeout time.Duration) LoaderOption
LoaderWithLocalWalletDB configures the wallet loader to use the local db.