2016-03-22 21:00:31 +01:00
|
|
|
package lnwallet
|
|
|
|
|
|
|
|
import (
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"sync"
|
2020-05-21 00:33:56 +02:00
|
|
|
"time"
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
|
2022-02-23 14:48:00 +01:00
|
|
|
"github.com/btcsuite/btcd/btcec/v2"
|
|
|
|
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
|
|
|
"github.com/btcsuite/btcd/btcutil"
|
|
|
|
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
|
|
|
"github.com/btcsuite/btcd/btcutil/psbt"
|
2024-06-04 08:00:38 +02:00
|
|
|
"github.com/btcsuite/btcd/chaincfg"
|
2018-06-05 03:34:16 +02:00
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
2021-07-09 17:49:51 +02:00
|
|
|
"github.com/btcsuite/btcd/txscript"
|
2018-06-05 03:34:16 +02:00
|
|
|
"github.com/btcsuite/btcd/wire"
|
2021-02-20 02:42:02 +01:00
|
|
|
"github.com/btcsuite/btcwallet/waddrmgr"
|
2022-05-12 10:24:40 +02:00
|
|
|
base "github.com/btcsuite/btcwallet/wallet"
|
2019-03-05 14:22:30 +01:00
|
|
|
"github.com/btcsuite/btcwallet/wallet/txauthor"
|
2020-05-21 00:33:56 +02:00
|
|
|
"github.com/btcsuite/btcwallet/wtxmgr"
|
2024-03-01 20:25:20 +01:00
|
|
|
"github.com/lightningnetwork/lnd/fn"
|
2021-09-23 16:54:30 +02:00
|
|
|
"github.com/lightningnetwork/lnd/keychain"
|
2019-10-31 03:43:05 +01:00
|
|
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
2024-09-02 12:10:13 +02:00
|
|
|
"github.com/lightningnetwork/lnd/lnwallet/chanvalidate"
|
2024-09-02 12:05:34 +02:00
|
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
2016-03-22 21:00:31 +01:00
|
|
|
)
|
|
|
|
|
2021-02-20 02:41:45 +01:00
|
|
|
const (
|
|
|
|
// DefaultAccountName is the name for the default account used to manage
|
|
|
|
// on-chain funds within the wallet.
|
|
|
|
DefaultAccountName = "default"
|
|
|
|
)
|
|
|
|
|
2018-04-18 04:02:04 +02:00
|
|
|
// AddressType is an enum-like type which denotes the possible address types
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// WalletController supports.
|
|
|
|
type AddressType uint8
|
|
|
|
|
2022-07-23 07:35:53 +02:00
|
|
|
// AccountAddressMap maps the account properties to an array of
|
|
|
|
// address properties.
|
|
|
|
type AccountAddressMap map[*waddrmgr.AccountProperties][]AddressProperty
|
|
|
|
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
const (
|
2019-06-11 09:16:43 +02:00
|
|
|
// UnknownAddressType represents an output with an unknown or non-standard
|
|
|
|
// script.
|
|
|
|
UnknownAddressType AddressType = iota
|
|
|
|
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// WitnessPubKey represents a p2wkh address.
|
2019-06-11 09:16:43 +02:00
|
|
|
WitnessPubKey
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
|
|
|
|
// NestedWitnessPubKey represents a p2sh output which is itself a
|
|
|
|
// nested p2wkh output.
|
|
|
|
NestedWitnessPubKey
|
2022-03-18 18:37:46 +01:00
|
|
|
|
|
|
|
// TaprootPubkey represents a p2tr key path spending address.
|
|
|
|
TaprootPubkey
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
)
|
|
|
|
|
2018-04-08 23:34:00 +02:00
|
|
|
var (
|
|
|
|
// DefaultPublicPassphrase is the default public passphrase used for the
|
|
|
|
// wallet.
|
|
|
|
DefaultPublicPassphrase = []byte("public")
|
|
|
|
|
|
|
|
// DefaultPrivatePassphrase is the default private passphrase used for
|
|
|
|
// the wallet.
|
|
|
|
DefaultPrivatePassphrase = []byte("hello")
|
|
|
|
|
|
|
|
// ErrDoubleSpend is returned from PublishTransaction in case the
|
|
|
|
// tx being published is spending an output spent by a conflicting
|
|
|
|
// transaction.
|
2020-04-14 19:56:05 +02:00
|
|
|
ErrDoubleSpend = errors.New("transaction rejected: output already spent")
|
2018-04-08 23:34:00 +02:00
|
|
|
|
|
|
|
// ErrNotMine is an error denoting that a WalletController instance is
|
|
|
|
// unable to spend a specified output.
|
|
|
|
ErrNotMine = errors.New("the passed output doesn't belong to the wallet")
|
2023-06-03 13:58:31 +02:00
|
|
|
|
|
|
|
// ErrMempoolFee is returned from PublishTransaction in case the tx
|
|
|
|
// being published is not accepted into mempool because the fee
|
|
|
|
// requirements of the mempool backend are not met.
|
|
|
|
ErrMempoolFee = errors.New("transaction rejected by the mempool " +
|
|
|
|
"because of low fees")
|
2018-04-08 23:34:00 +02:00
|
|
|
)
|
2018-01-15 23:26:35 +01:00
|
|
|
|
2019-03-05 14:22:30 +01:00
|
|
|
// ErrNoOutputs is returned if we try to create a transaction with no outputs
|
|
|
|
// or send coins to a set of outputs that is empty.
|
|
|
|
var ErrNoOutputs = errors.New("no outputs")
|
|
|
|
|
2020-09-27 17:48:15 +02:00
|
|
|
// ErrInvalidMinconf is returned if we try to create a transaction with
|
2021-04-22 19:04:00 +02:00
|
|
|
// invalid minConfs value.
|
2020-09-27 17:48:15 +02:00
|
|
|
var ErrInvalidMinconf = errors.New("minimum number of confirmations must " +
|
|
|
|
"be a non-negative number")
|
|
|
|
|
2022-07-23 07:35:53 +02:00
|
|
|
// AddressProperty contains wallet related information of an address.
|
|
|
|
type AddressProperty struct {
|
|
|
|
// Address is the address of an account.
|
|
|
|
Address string
|
|
|
|
|
|
|
|
// Internal denotes if the address is a change address.
|
|
|
|
Internal bool
|
|
|
|
|
|
|
|
// Balance returns the total balance of an address.
|
|
|
|
Balance btcutil.Amount
|
2024-02-06 12:25:59 +01:00
|
|
|
|
|
|
|
// DerivationPath is the derivation path of the address.
|
|
|
|
DerivationPath string
|
|
|
|
|
|
|
|
// PublicKey is the public key of the address.
|
|
|
|
PublicKey *btcec.PublicKey
|
2022-07-23 07:35:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// AccountIdentifier contains information to uniquely identify an account.
|
|
|
|
type AccountIdentifier struct {
|
|
|
|
// Name is the name of the account.
|
|
|
|
Name string
|
|
|
|
|
|
|
|
// AddressType is the type of addresses supported by the account.
|
|
|
|
AddressType AddressType
|
|
|
|
|
|
|
|
// DerivationPath is the derivation path corresponding to the account
|
|
|
|
// public key.
|
|
|
|
DerivationPath string
|
|
|
|
}
|
|
|
|
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// Utxo is an unspent output denoted by its outpoint, and output value of the
|
|
|
|
// original output.
|
|
|
|
type Utxo struct {
|
2017-10-03 03:52:45 +02:00
|
|
|
AddressType AddressType
|
|
|
|
Value btcutil.Amount
|
2018-09-27 15:49:44 +02:00
|
|
|
Confirmations int64
|
2017-10-03 03:52:45 +02:00
|
|
|
PkScript []byte
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
wire.OutPoint
|
2024-08-08 15:55:10 +02:00
|
|
|
PrevTx *wire.MsgTx
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
}
|
|
|
|
|
2021-07-09 17:49:51 +02:00
|
|
|
// OutputDetail contains additional information on a destination address.
|
|
|
|
type OutputDetail struct {
|
|
|
|
OutputType txscript.ScriptClass
|
|
|
|
Addresses []btcutil.Address
|
|
|
|
PkScript []byte
|
|
|
|
OutputIndex int
|
|
|
|
Value btcutil.Amount
|
|
|
|
IsOurAddress bool
|
|
|
|
}
|
|
|
|
|
2022-06-27 12:15:49 +02:00
|
|
|
// PreviousOutPoint contains information about the previous outpoint.
|
|
|
|
type PreviousOutPoint struct {
|
|
|
|
// OutPoint is the transaction out point in the format txid:n.
|
|
|
|
OutPoint string
|
|
|
|
|
|
|
|
// IsOurOutput denotes if the previous output is controlled by the
|
|
|
|
// internal wallet. The flag will only detect p2wkh, np2wkh and p2tr
|
|
|
|
// inputs as its own.
|
|
|
|
IsOurOutput bool
|
|
|
|
}
|
|
|
|
|
2016-10-15 05:03:34 +02:00
|
|
|
// TransactionDetail describes a transaction with either inputs which belong to
|
|
|
|
// the wallet, or has outputs that pay to the wallet.
|
|
|
|
type TransactionDetail struct {
|
|
|
|
// Hash is the transaction hash of the transaction.
|
2017-01-05 22:56:27 +01:00
|
|
|
Hash chainhash.Hash
|
2016-10-15 05:03:34 +02:00
|
|
|
|
|
|
|
// Value is the net value of this transaction (in satoshis) from the
|
|
|
|
// PoV of the wallet. If this transaction purely spends from the
|
|
|
|
// wallet's funds, then this value will be negative. Similarly, if this
|
|
|
|
// transaction credits the wallet, then this value will be positive.
|
|
|
|
Value btcutil.Amount
|
|
|
|
|
|
|
|
// NumConfirmations is the number of confirmations this transaction
|
|
|
|
// has. If the transaction is unconfirmed, then this value will be
|
|
|
|
// zero.
|
|
|
|
NumConfirmations int32
|
|
|
|
|
|
|
|
// BlockHeight is the hash of the block which includes this
|
|
|
|
// transaction. Unconfirmed transactions will have a nil value for this
|
|
|
|
// field.
|
2017-01-05 22:56:27 +01:00
|
|
|
BlockHash *chainhash.Hash
|
2016-10-15 05:03:34 +02:00
|
|
|
|
|
|
|
// BlockHeight is the height of the block including this transaction.
|
|
|
|
// Unconfirmed transaction will show a height of zero.
|
|
|
|
BlockHeight int32
|
|
|
|
|
|
|
|
// Timestamp is the unix timestamp of the block including this
|
|
|
|
// transaction. If the transaction is unconfirmed, then this will be a
|
|
|
|
// timestamp of txn creation.
|
|
|
|
Timestamp int64
|
|
|
|
|
|
|
|
// TotalFees is the total fee in satoshis paid by this transaction.
|
|
|
|
TotalFees int64
|
2017-12-06 18:19:37 +01:00
|
|
|
|
2021-07-09 17:49:51 +02:00
|
|
|
// OutputDetails contains output data for each destination address, such
|
|
|
|
// as the output script and amount.
|
|
|
|
OutputDetails []OutputDetail
|
|
|
|
|
2019-06-07 16:36:20 +02:00
|
|
|
// RawTx returns the raw serialized transaction.
|
|
|
|
RawTx []byte
|
2020-05-18 14:13:24 +02:00
|
|
|
|
|
|
|
// Label is an optional transaction label.
|
|
|
|
Label string
|
2022-06-27 12:15:49 +02:00
|
|
|
|
|
|
|
// PreviousOutpoints are the inputs for a transaction.
|
|
|
|
PreviousOutpoints []PreviousOutPoint
|
2016-10-15 05:03:34 +02:00
|
|
|
}
|
2016-10-15 23:07:05 +02:00
|
|
|
|
|
|
|
// TransactionSubscription is an interface which describes an object capable of
|
|
|
|
// receiving notifications of new transaction related to the underlying wallet.
|
|
|
|
// TODO(roasbeef): add balance updates?
|
|
|
|
type TransactionSubscription interface {
|
|
|
|
// ConfirmedTransactions returns a channel which will be sent on as new
|
|
|
|
// relevant transactions are confirmed.
|
|
|
|
ConfirmedTransactions() chan *TransactionDetail
|
|
|
|
|
|
|
|
// UnconfirmedTransactions returns a channel which will be sent on as
|
|
|
|
// new relevant transactions are seen within the network.
|
|
|
|
UnconfirmedTransactions() chan *TransactionDetail
|
|
|
|
|
|
|
|
// Cancel finalizes the subscription, cleaning up any resources
|
|
|
|
// allocated.
|
|
|
|
Cancel()
|
|
|
|
}
|
|
|
|
|
2016-03-22 21:00:31 +01:00
|
|
|
// WalletController defines an abstract interface for controlling a local Pure
|
|
|
|
// Go wallet, a local or remote wallet via an RPC mechanism, or possibly even
|
|
|
|
// a daemon assisted hardware wallet. This interface serves the purpose of
|
|
|
|
// allowing LightningWallet to be seamlessly compatible with several wallets
|
|
|
|
// such as: uspv, btcwallet, Bitcoin Core, Electrum, etc. This interface then
|
|
|
|
// serves as a "base wallet", with Lightning Network awareness taking place at
|
|
|
|
// a "higher" level of abstraction. Essentially, an overlay wallet.
|
2016-08-04 07:31:20 +02:00
|
|
|
// Implementors of this interface must closely adhere to the documented
|
|
|
|
// behavior of all interface methods in order to ensure identical behavior
|
|
|
|
// across all concrete implementations.
|
2016-03-22 21:00:31 +01:00
|
|
|
type WalletController interface {
|
2024-08-08 09:01:53 +02:00
|
|
|
// FetchOutpointInfo 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.
|
|
|
|
FetchOutpointInfo(prevOut *wire.OutPoint) (*Utxo, error)
|
|
|
|
|
|
|
|
// FetchDerivationInfo queries for the wallet's knowledge of the passed
|
|
|
|
// pkScript and constructs the derivation info and returns it.
|
|
|
|
FetchDerivationInfo(pkScript []byte) (*psbt.Bip32Derivation, error)
|
|
|
|
|
2022-01-05 11:04:16 +01:00
|
|
|
// 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.
|
|
|
|
ScriptForOutput(output *wire.TxOut) (waddrmgr.ManagedPubKeyAddress,
|
|
|
|
[]byte, []byte, error)
|
|
|
|
|
2016-03-22 21:00:31 +01:00
|
|
|
// 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
|
2021-02-20 02:41:50 +01:00
|
|
|
// 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.
|
2018-02-18 00:36:53 +01:00
|
|
|
//
|
|
|
|
// NOTE: Only witness outputs should be included in the computation of
|
|
|
|
// the total spendable balance of the wallet. We require this as only
|
|
|
|
// witness inputs can be used for funding channels.
|
2022-01-05 11:04:14 +01:00
|
|
|
ConfirmedBalance(confs int32, accountFilter string) (btcutil.Amount,
|
|
|
|
error)
|
2016-04-13 06:36:41 +02:00
|
|
|
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// NewAddress returns the next external or internal address for the
|
2016-12-22 21:34:51 +01:00
|
|
|
// wallet dictated by the value of the `change` parameter. If change is
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// true, then an internal address should be used, otherwise an external
|
|
|
|
// address should be returned. The type of address returned is dictated
|
2018-02-18 00:36:53 +01:00
|
|
|
// by the wallet's capabilities, and may be of type: p2sh, p2wkh,
|
2021-02-20 02:41:45 +01:00
|
|
|
// p2wsh, etc. The account parameter must be non-empty as it determines
|
|
|
|
// which account the address should be generated from.
|
|
|
|
NewAddress(addrType AddressType, change bool,
|
|
|
|
account string) (btcutil.Address, error)
|
2016-03-22 21:00:31 +01:00
|
|
|
|
2019-02-20 04:16:39 +01:00
|
|
|
// 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. By default, this is a non-change address.
|
2021-02-20 02:41:45 +01:00
|
|
|
// The account parameter must be non-empty as it determines which
|
|
|
|
// account the address should be generated from.
|
|
|
|
LastUnusedAddress(addrType AddressType,
|
|
|
|
account string) (btcutil.Address, error)
|
2019-02-20 04:16:39 +01:00
|
|
|
|
2018-09-28 05:58:46 +02:00
|
|
|
// IsOurAddress checks if the passed address belongs to this wallet
|
|
|
|
IsOurAddress(a btcutil.Address) bool
|
2016-03-22 21:00:31 +01:00
|
|
|
|
2022-03-16 15:11:13 +01:00
|
|
|
// AddressInfo returns the information about an address, if it's known
|
|
|
|
// to this wallet.
|
|
|
|
AddressInfo(a btcutil.Address) (waddrmgr.ManagedAddress, error)
|
|
|
|
|
2021-02-20 02:42:02 +01:00
|
|
|
// 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.
|
2022-01-05 11:04:14 +01:00
|
|
|
ListAccounts(string, *waddrmgr.KeyScope) ([]*waddrmgr.AccountProperties,
|
|
|
|
error)
|
2021-02-20 02:42:02 +01:00
|
|
|
|
2022-06-17 17:37:17 +02:00
|
|
|
// RequiredReserve returns the minimum amount of satoshis that should be
|
|
|
|
// kept in the wallet in order to fee bump anchor channels if necessary.
|
|
|
|
// The value scales with the number of public anchor channels but is
|
|
|
|
// capped at a maximum.
|
|
|
|
RequiredReserve(uint32) btcutil.Amount
|
|
|
|
|
2022-07-23 07:35:53 +02:00
|
|
|
// ListAddresses retrieves all the addresses along with their balance. An
|
|
|
|
// account name filter can be provided to filter through all of the
|
|
|
|
// wallet accounts and return the addresses of only those matching.
|
|
|
|
ListAddresses(string, bool) (AccountAddressMap, error)
|
|
|
|
|
2021-02-20 02:42:02 +01:00
|
|
|
// 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).
|
|
|
|
ImportAccount(name string, accountPubKey *hdkeychain.ExtendedKey,
|
2021-05-05 00:56:26 +02:00
|
|
|
masterKeyFingerprint uint32, addrType *waddrmgr.AddressType,
|
|
|
|
dryRun bool) (*waddrmgr.AccountProperties, []btcutil.Address,
|
|
|
|
[]btcutil.Address, error)
|
2021-02-20 02:42:02 +01:00
|
|
|
|
|
|
|
// 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.
|
2022-01-05 11:04:14 +01:00
|
|
|
ImportPublicKey(pubKey *btcec.PublicKey,
|
|
|
|
addrType waddrmgr.AddressType) error
|
2021-02-20 02:42:02 +01:00
|
|
|
|
2022-07-29 18:20:05 +02:00
|
|
|
// ImportTaprootScript imports a user-provided taproot script into the
|
|
|
|
// wallet. The imported script will act as a pay-to-taproot address.
|
|
|
|
//
|
|
|
|
// NOTE: Taproot keys imported through this RPC currently _cannot_ be
|
|
|
|
// used for funding PSBTs. Only tracking the balance and UTXOs is
|
|
|
|
// currently supported.
|
|
|
|
ImportTaprootScript(scope waddrmgr.KeyScope,
|
|
|
|
tapscript *waddrmgr.Tapscript) (waddrmgr.ManagedAddress, error)
|
|
|
|
|
2018-07-28 03:20:58 +02:00
|
|
|
// 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, an error should be returned.
|
|
|
|
// This method also takes the target fee expressed in sat/kw that should
|
|
|
|
// be used when crafting the transaction.
|
2020-06-12 20:22:00 +02:00
|
|
|
//
|
|
|
|
// NOTE: This method requires the global coin selection lock to be held.
|
2024-03-01 20:25:20 +01:00
|
|
|
SendOutputs(inputs fn.Set[wire.OutPoint], outputs []*wire.TxOut,
|
|
|
|
feeRate chainfee.SatPerKWeight, minConfs int32, label string,
|
2024-03-26 18:08:27 +01:00
|
|
|
strategy base.CoinSelectionStrategy) (*wire.MsgTx, error)
|
2016-03-22 21:00:31 +01:00
|
|
|
|
2019-03-05 14:22:30 +01:00
|
|
|
// CreateSimpleTx creates a Bitcoin transaction paying to the specified
|
|
|
|
// outputs. The transaction is not broadcasted to the network. 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.
|
2020-06-12 20:22:00 +02:00
|
|
|
//
|
|
|
|
// NOTE: This method requires the global coin selection lock to be held.
|
2024-03-01 20:25:20 +01:00
|
|
|
CreateSimpleTx(inputs fn.Set[wire.OutPoint], outputs []*wire.TxOut,
|
|
|
|
feeRate chainfee.SatPerKWeight, minConfs int32,
|
|
|
|
strategy base.CoinSelectionStrategy, dryRun bool) (
|
|
|
|
*txauthor.AuthoredTx, error)
|
2019-03-05 14:22:30 +01:00
|
|
|
|
2023-01-18 06:29:09 +01:00
|
|
|
// GetTransactionDetails returns a detailed description of a transaction
|
|
|
|
// given its transaction hash.
|
|
|
|
GetTransactionDetails(txHash *chainhash.Hash) (
|
|
|
|
*TransactionDetail, error)
|
|
|
|
|
2016-04-13 06:36:41 +02:00
|
|
|
// ListUnspentWitness returns all unspent outputs which are version 0
|
2021-04-22 19:04:00 +02:00
|
|
|
// witness programs. The 'minConfs' and 'maxConfs' parameters
|
2018-10-28 15:55:18 +01:00
|
|
|
// indicate the minimum and maximum number of confirmations an output
|
|
|
|
// needs in order to be returned by this method. Passing -1 as
|
2021-04-22 19:04:00 +02:00
|
|
|
// '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
|
2021-02-20 02:41:50 +01:00
|
|
|
// a filter to retrieve the unspent outputs for a specific account.
|
|
|
|
// When empty, the unspent outputs of all wallet accounts are returned.
|
2020-06-12 20:22:00 +02:00
|
|
|
//
|
|
|
|
// NOTE: This method requires the global coin selection lock to be held.
|
2021-04-22 19:04:00 +02:00
|
|
|
ListUnspentWitness(minConfs, maxConfs int32,
|
2021-02-20 02:41:50 +01:00
|
|
|
accountFilter string) ([]*Utxo, error)
|
2016-04-13 06:36:41 +02:00
|
|
|
|
2016-10-15 05:03:34 +02:00
|
|
|
// ListTransactionDetails returns a list of all transactions which are
|
2020-05-05 21:10:06 +02:00
|
|
|
// 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
|
2021-02-20 02:41:50 +01:00
|
|
|
// 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.
|
|
|
|
ListTransactionDetails(startHeight, endHeight int32,
|
|
|
|
accountFilter string) ([]*TransactionDetail, error)
|
2016-10-15 05:03:34 +02:00
|
|
|
|
2020-05-21 00:33:56 +02:00
|
|
|
// 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.
|
2020-06-12 20:22:00 +02:00
|
|
|
//
|
|
|
|
// NOTE: This method requires the global coin selection lock to be held.
|
2021-03-12 08:45:12 +01:00
|
|
|
LeaseOutput(id wtxmgr.LockID, op wire.OutPoint,
|
2024-07-31 21:01:54 +02:00
|
|
|
duration time.Duration) (time.Time, error)
|
2020-05-21 00:33:56 +02:00
|
|
|
|
|
|
|
// 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.
|
2020-06-12 20:22:00 +02:00
|
|
|
//
|
|
|
|
// NOTE: This method requires the global coin selection lock to be held.
|
2020-05-21 00:33:56 +02:00
|
|
|
ReleaseOutput(id wtxmgr.LockID, op wire.OutPoint) error
|
|
|
|
|
2021-03-12 09:26:24 +01:00
|
|
|
// ListLeasedOutputs returns a list of all currently locked outputs.
|
2022-05-12 10:24:40 +02:00
|
|
|
ListLeasedOutputs() ([]*base.ListLeasedOutputResult, error)
|
2021-03-12 09:26:24 +01:00
|
|
|
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// PublishTransaction performs cursory validation (dust checks, etc),
|
|
|
|
// then finally broadcasts the passed transaction to the Bitcoin network.
|
2018-01-15 23:26:35 +01:00
|
|
|
// If the transaction is rejected because it is conflicting with an
|
|
|
|
// already known transaction, ErrDoubleSpend is returned. If the
|
|
|
|
// transaction is already known (published already), no error will be
|
|
|
|
// returned. Other error returned depends on the currently active chain
|
2020-05-18 14:13:23 +02:00
|
|
|
// backend. It takes an optional label which will save a label with the
|
|
|
|
// published transaction.
|
|
|
|
PublishTransaction(tx *wire.MsgTx, label string) error
|
2016-03-22 21:00:31 +01:00
|
|
|
|
2020-05-25 08:38:05 +02:00
|
|
|
// 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.
|
|
|
|
LabelTransaction(hash chainhash.Hash, label string, overwrite bool) error
|
|
|
|
|
sweep: remove all unconfirmed descendant transactions when a sweep conflicts
Before this commit, we we were trying to sweep an anchor output, and
that output was spent by someone else (not the sweeper), then we would
report this back to the original resolver (allowing it to be cleaned
up), and also remove the set of inputs spent by that transaction from
the set we need to sweep.
However, it's possible that if a user is spending unconfirmed outputs,
then the wallet is holding onto an invalid transaction, as the outputs
that were used as inputs have been double spent elsewhere.
In this commit, we fix this issue by recursively removing all descendant
transactions of our past sweeps that have an intersecting input set as
the spending transaction. In cases where a user spent an unconfirmed
output to funding a channel, and that output was a descendant of the now
swept anchor output, the funds will now properly be marked as available.
Fixes #6241
2022-02-18 03:25:30 +01:00
|
|
|
// 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.
|
|
|
|
FetchTx(chainhash.Hash) (*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.
|
|
|
|
RemoveDescendants(*wire.MsgTx) error
|
|
|
|
|
2020-10-01 16:21:44 +02:00
|
|
|
// 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
|
2023-02-02 13:40:02 +01:00
|
|
|
// is returned. If no custom change scope is specified, the BIP0084 will
|
|
|
|
// be used for default accounts and single imported public keys. For
|
|
|
|
// custom account, no key scope should be provided as the coin selection
|
|
|
|
// key scope will always be used to generate the change address.
|
2020-10-01 16:21:44 +02:00
|
|
|
//
|
|
|
|
// NOTE: If the packet doesn't contain any inputs, coin selection is
|
2021-02-20 02:41:45 +01:00
|
|
|
// 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.
|
2021-10-14 15:42:52 +02:00
|
|
|
FundPsbt(packet *psbt.Packet, minConfs int32,
|
2023-02-02 13:40:02 +01:00
|
|
|
feeRate chainfee.SatPerKWeight, account string,
|
2024-03-26 18:08:27 +01:00
|
|
|
changeScope *waddrmgr.KeyScope,
|
2024-03-30 18:03:09 +01:00
|
|
|
strategy base.CoinSelectionStrategy,
|
|
|
|
allowUtxo func(wtxmgr.Credit) bool) (int32, error)
|
2020-10-01 16:21:44 +02:00
|
|
|
|
2022-01-05 11:04:23 +01:00
|
|
|
// 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.
|
2022-08-17 01:31:06 +02:00
|
|
|
SignPsbt(packet *psbt.Packet) ([]uint32, error)
|
2022-01-05 11:04:23 +01:00
|
|
|
|
2020-10-01 16:21:44 +02:00
|
|
|
// FinalizePsbt expects a partial transaction with all inputs and
|
|
|
|
// outputs fully declared and tries to sign all inputs that belong to
|
2021-02-20 02:41:45 +01:00
|
|
|
// 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.
|
2020-10-01 16:21:44 +02:00
|
|
|
//
|
|
|
|
// NOTE: This method does NOT publish the transaction after it's been
|
|
|
|
// finalized successfully.
|
2021-02-20 02:41:45 +01:00
|
|
|
FinalizePsbt(packet *psbt.Packet, account string) error
|
2020-10-01 16:21:44 +02:00
|
|
|
|
2024-02-06 12:25:54 +01:00
|
|
|
// DecorateInputs fetches the UTXO information of all inputs it can
|
|
|
|
// identify and adds the required information to the package's inputs.
|
|
|
|
// The failOnUnknown boolean controls whether the method should return
|
|
|
|
// an error if it cannot identify an input or if it should just skip it.
|
|
|
|
DecorateInputs(packet *psbt.Packet, failOnUnknown bool) error
|
|
|
|
|
2016-10-15 23:07:05 +02:00
|
|
|
// 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.
|
|
|
|
//
|
2016-12-09 03:29:55 +01:00
|
|
|
// NOTE: a non-nil error should be returned if notifications aren't
|
2016-10-15 23:07:05 +02:00
|
|
|
// supported.
|
|
|
|
//
|
|
|
|
// TODO(roasbeef): make distinct interface?
|
|
|
|
SubscribeTransactions() (TransactionSubscription, error)
|
|
|
|
|
2016-12-09 03:29:55 +01:00
|
|
|
// 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.
|
2017-12-10 08:42:46 +01:00
|
|
|
// It also returns an int64 indicating the timestamp of the best block
|
|
|
|
// known to the wallet, expressed in Unix epoch time
|
|
|
|
IsSynced() (bool, int64, error)
|
2016-12-09 03:29:55 +01:00
|
|
|
|
2020-06-09 08:47:17 +02:00
|
|
|
// GetRecoveryInfo returns a boolean indicating whether the wallet is
|
|
|
|
// started in recovery mode. It also returns a float64 indicating the
|
|
|
|
// recovery progress made so far.
|
|
|
|
GetRecoveryInfo() (bool, float64, error)
|
|
|
|
|
2016-12-09 03:29:55 +01:00
|
|
|
// Start initializes the wallet, making any necessary connections,
|
2016-03-22 21:00:31 +01:00
|
|
|
// starting up required goroutines etc.
|
|
|
|
Start() error
|
|
|
|
|
|
|
|
// Stop signals the wallet for shutdown. Shutdown may entail closing
|
|
|
|
// any active sockets, database handles, stopping goroutines, etc.
|
|
|
|
Stop() error
|
2017-11-10 01:30:20 +01:00
|
|
|
|
|
|
|
// BackEnd returns a name for the wallet's backing chain service,
|
|
|
|
// which could be e.g. btcd, bitcoind, neutrino, or another consensus
|
|
|
|
// service.
|
|
|
|
BackEnd() string
|
2024-02-28 20:07:22 +01:00
|
|
|
|
|
|
|
// CheckMempoolAcceptance checks whether a transaction follows mempool
|
|
|
|
// policies and returns an error if it cannot be accepted into the
|
|
|
|
// mempool.
|
|
|
|
CheckMempoolAcceptance(tx *wire.MsgTx) error
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// BlockChainIO is a dedicated source which will be used to obtain queries
|
|
|
|
// related to the current state of the blockchain. The data returned by each of
|
|
|
|
// the defined methods within this interface should always return the most up
|
|
|
|
// to date data possible.
|
|
|
|
//
|
|
|
|
// TODO(roasbeef): move to diff package perhaps?
|
2016-09-12 21:33:22 +02:00
|
|
|
// TODO(roasbeef): move publish txn here?
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
type BlockChainIO interface {
|
2016-12-22 21:34:51 +01:00
|
|
|
// GetBestBlock returns the current height and block hash of the valid
|
|
|
|
// most-work chain the implementation is aware of.
|
2017-01-05 22:56:27 +01:00
|
|
|
GetBestBlock() (*chainhash.Hash, int32, error)
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
|
2017-05-11 01:37:14 +02:00
|
|
|
// GetUtxo attempts to return the passed outpoint if it's still a
|
|
|
|
// member of the utxo set. The passed height hint should be the "birth
|
2018-07-18 04:20:52 +02:00
|
|
|
// height" of the passed outpoint. The script passed should be the
|
2018-07-26 04:33:46 +02:00
|
|
|
// script that the outpoint creates. In the case that the output is in
|
2017-05-11 01:37:14 +02:00
|
|
|
// the UTXO set, then the output corresponding to that output is
|
|
|
|
// returned. Otherwise, a non-nil error will be returned.
|
2018-08-24 15:31:57 +02:00
|
|
|
// As for some backends this call can initiate a rescan, the passed
|
|
|
|
// cancel channel can be closed to abort the call.
|
|
|
|
GetUtxo(op *wire.OutPoint, pkScript []byte, heightHint uint32,
|
|
|
|
cancel <-chan struct{}) (*wire.TxOut, error)
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
|
2017-01-13 06:01:50 +01:00
|
|
|
// GetBlockHash returns the hash of the block in the best blockchain
|
2016-12-22 21:34:51 +01:00
|
|
|
// at the given height.
|
2017-01-05 22:56:27 +01:00
|
|
|
GetBlockHash(blockHeight int64) (*chainhash.Hash, error)
|
2016-12-07 16:49:58 +01:00
|
|
|
|
2016-12-22 21:34:51 +01:00
|
|
|
// GetBlock returns the block in the main chain identified by the given
|
|
|
|
// hash.
|
2017-01-05 22:56:27 +01:00
|
|
|
GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error)
|
2023-10-26 18:09:56 +02:00
|
|
|
|
|
|
|
// GetBlockHeader returns the block header for the given block hash.
|
|
|
|
GetBlockHeader(blockHash *chainhash.Hash) (*wire.BlockHeader, error)
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
}
|
|
|
|
|
2017-04-14 19:59:13 +02:00
|
|
|
// MessageSigner represents an abstract object capable of signing arbitrary
|
|
|
|
// messages. The capabilities of this interface are used to sign announcements
|
|
|
|
// to the network, or just arbitrary messages that leverage the wallet's keys
|
|
|
|
// to attest to some message.
|
|
|
|
type MessageSigner interface {
|
|
|
|
// SignMessage attempts to sign a target message with the private key
|
2021-09-23 16:54:30 +02:00
|
|
|
// described in the key locator. If the target private key is unable to
|
|
|
|
// be found, then an error will be returned. The actual digest signed is
|
2021-10-14 15:42:44 +02:00
|
|
|
// the single or double SHA-256 of the passed message.
|
|
|
|
SignMessage(keyLoc keychain.KeyLocator, msg []byte,
|
2022-02-23 14:48:00 +01:00
|
|
|
doubleHash bool) (*ecdsa.Signature, error)
|
2017-04-14 19:59:13 +02:00
|
|
|
}
|
|
|
|
|
2024-06-04 08:00:38 +02:00
|
|
|
// AddrWithKey wraps a normal addr, but also includes the internal key for the
|
|
|
|
// delivery addr if known.
|
|
|
|
type AddrWithKey struct {
|
|
|
|
lnwire.DeliveryAddress
|
|
|
|
|
|
|
|
InternalKey fn.Option[btcec.PublicKey]
|
|
|
|
|
|
|
|
// TODO(roasbeef): consolidate w/ instance in chan closer
|
|
|
|
}
|
|
|
|
|
|
|
|
// InternalKeyForAddr returns the internal key associated with a taproot
|
|
|
|
// address.
|
|
|
|
func InternalKeyForAddr(wallet WalletController, netParams *chaincfg.Params,
|
|
|
|
deliveryScript []byte) (fn.Option[keychain.KeyDescriptor], error) {
|
|
|
|
|
|
|
|
none := fn.None[keychain.KeyDescriptor]()
|
|
|
|
|
|
|
|
pkScript, err := txscript.ParsePkScript(deliveryScript)
|
|
|
|
if err != nil {
|
|
|
|
return none, err
|
|
|
|
}
|
|
|
|
addr, err := pkScript.Address(netParams)
|
|
|
|
if err != nil {
|
|
|
|
return none, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// If it's not a taproot address, we don't require to know the internal
|
|
|
|
// key in the first place. So we don't return an error here, but also no
|
|
|
|
// internal key.
|
|
|
|
_, isTaproot := addr.(*btcutil.AddressTaproot)
|
|
|
|
if !isTaproot {
|
|
|
|
return none, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
walletAddr, err := wallet.AddressInfo(addr)
|
|
|
|
if err != nil {
|
|
|
|
return none, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// No wallet addr. No error, but we'll return an nil error value here,
|
|
|
|
// as callers can use the .Option() method to get an option value.
|
|
|
|
if walletAddr == nil {
|
|
|
|
return none, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
pubKeyAddr, ok := walletAddr.(waddrmgr.ManagedPubKeyAddress)
|
|
|
|
if !ok {
|
|
|
|
return none, fmt.Errorf("expected pubkey addr, got %T",
|
|
|
|
pubKeyAddr)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, derivationPath, _ := pubKeyAddr.DerivationInfo()
|
|
|
|
|
|
|
|
return fn.Some[keychain.KeyDescriptor](keychain.KeyDescriptor{
|
|
|
|
KeyLocator: keychain.KeyLocator{
|
|
|
|
Family: keychain.KeyFamily(derivationPath.Account),
|
|
|
|
Index: derivationPath.Index,
|
|
|
|
},
|
|
|
|
PubKey: pubKeyAddr.PubKey(),
|
|
|
|
}), nil
|
|
|
|
}
|
|
|
|
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// WalletDriver represents a "driver" for a particular concrete
|
2016-12-22 21:34:51 +01:00
|
|
|
// WalletController implementation. A driver is identified by a globally unique
|
|
|
|
// string identifier along with a 'New()' method which is responsible for
|
|
|
|
// initializing a particular WalletController concrete implementation.
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
type WalletDriver struct {
|
2018-01-17 03:04:07 +01:00
|
|
|
// WalletType is a string which uniquely identifies the
|
|
|
|
// WalletController that this driver, drives.
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
WalletType string
|
|
|
|
|
|
|
|
// New creates a new instance of a concrete WalletController
|
|
|
|
// implementation given a variadic set up arguments. The function takes
|
2017-12-18 03:40:05 +01:00
|
|
|
// a variadic number of interface parameters in order to provide
|
2016-12-22 21:34:51 +01:00
|
|
|
// initialization flexibility, thereby accommodating several potential
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// WalletController implementations.
|
|
|
|
New func(args ...interface{}) (WalletController, error)
|
2017-11-10 01:30:20 +01:00
|
|
|
|
|
|
|
// BackEnds returns a list of available chain service drivers for the
|
|
|
|
// wallet driver. This could be e.g. bitcoind, btcd, neutrino, etc.
|
|
|
|
BackEnds func() []string
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
wallets = make(map[string]*WalletDriver)
|
|
|
|
registerMtx sync.Mutex
|
|
|
|
)
|
|
|
|
|
|
|
|
// RegisteredWallets returns a slice of all currently registered notifiers.
|
|
|
|
//
|
|
|
|
// NOTE: This function is safe for concurrent access.
|
|
|
|
func RegisteredWallets() []*WalletDriver {
|
|
|
|
registerMtx.Lock()
|
|
|
|
defer registerMtx.Unlock()
|
|
|
|
|
|
|
|
registeredWallets := make([]*WalletDriver, 0, len(wallets))
|
|
|
|
for _, wallet := range wallets {
|
|
|
|
registeredWallets = append(registeredWallets, wallet)
|
|
|
|
}
|
|
|
|
|
|
|
|
return registeredWallets
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterWallet registers a WalletDriver which is capable of driving a
|
|
|
|
// concrete WalletController interface. In the case that this driver has
|
|
|
|
// already been registered, an error is returned.
|
|
|
|
//
|
|
|
|
// NOTE: This function is safe for concurrent access.
|
|
|
|
func RegisterWallet(driver *WalletDriver) error {
|
|
|
|
registerMtx.Lock()
|
|
|
|
defer registerMtx.Unlock()
|
|
|
|
|
|
|
|
if _, ok := wallets[driver.WalletType]; ok {
|
|
|
|
return fmt.Errorf("wallet already registered")
|
|
|
|
}
|
|
|
|
|
|
|
|
wallets[driver.WalletType] = driver
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-12-22 21:34:51 +01:00
|
|
|
// SupportedWallets returns a slice of strings that represents the wallet
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// drivers that have been registered and are therefore supported.
|
|
|
|
//
|
|
|
|
// NOTE: This function is safe for concurrent access.
|
|
|
|
func SupportedWallets() []string {
|
|
|
|
registerMtx.Lock()
|
|
|
|
defer registerMtx.Unlock()
|
2016-03-22 21:00:31 +01:00
|
|
|
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
supportedWallets := make([]string, 0, len(wallets))
|
|
|
|
for walletName := range wallets {
|
|
|
|
supportedWallets = append(supportedWallets, walletName)
|
|
|
|
}
|
2016-03-22 21:00:31 +01:00
|
|
|
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
return supportedWallets
|
2016-03-22 21:00:31 +01:00
|
|
|
}
|
2024-09-02 12:05:34 +02:00
|
|
|
|
|
|
|
// FetchFundingTxWrapper is a wrapper around FetchFundingTx, except that it will
|
|
|
|
// exit when the supplied quit channel is closed.
|
|
|
|
func FetchFundingTxWrapper(chain BlockChainIO, chanID *lnwire.ShortChannelID,
|
|
|
|
quit chan struct{}) (*wire.MsgTx, error) {
|
|
|
|
|
|
|
|
txChan := make(chan *wire.MsgTx, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
tx, err := FetchFundingTx(chain, chanID)
|
|
|
|
if err != nil {
|
|
|
|
errChan <- err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
txChan <- tx
|
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case tx := <-txChan:
|
|
|
|
return tx, nil
|
|
|
|
|
|
|
|
case err := <-errChan:
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
case <-quit:
|
|
|
|
return nil, fmt.Errorf("quit channel passed to " +
|
|
|
|
"lnwallet.FetchFundingTxWrapper has been closed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FetchFundingTx uses the given BlockChainIO to fetch and return the funding
|
|
|
|
// transaction identified by the passed short channel ID.
|
|
|
|
//
|
|
|
|
// TODO(roasbeef): replace with call to GetBlockTransaction? (would allow to
|
|
|
|
// later use getblocktxn).
|
|
|
|
func FetchFundingTx(chain BlockChainIO,
|
|
|
|
chanID *lnwire.ShortChannelID) (*wire.MsgTx, error) {
|
|
|
|
|
|
|
|
// First fetch the block hash by the block number encoded, then use
|
|
|
|
// that hash to fetch the block itself.
|
|
|
|
blockNum := int64(chanID.BlockHeight)
|
|
|
|
blockHash, err := chain.GetBlockHash(blockNum)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
fundingBlock, err := chain.GetBlock(blockHash)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// As a sanity check, ensure that the advertised transaction index is
|
|
|
|
// within the bounds of the total number of transactions within a
|
|
|
|
// block.
|
|
|
|
numTxns := uint32(len(fundingBlock.Transactions))
|
|
|
|
if chanID.TxIndex > numTxns-1 {
|
|
|
|
return nil, fmt.Errorf("tx_index=#%v "+
|
|
|
|
"is out of range (max_index=%v), network_chan_id=%v",
|
|
|
|
chanID.TxIndex, numTxns-1, chanID)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fundingBlock.Transactions[chanID.TxIndex].Copy(), nil
|
|
|
|
}
|
2024-09-02 12:10:13 +02:00
|
|
|
|
|
|
|
// FetchPKScriptWithQuit fetches the output script for the given SCID and exits
|
|
|
|
// early with an error if the provided quit channel is closed before
|
|
|
|
// completion.
|
|
|
|
func FetchPKScriptWithQuit(chain BlockChainIO, chanID *lnwire.ShortChannelID,
|
|
|
|
quit chan struct{}) ([]byte, error) {
|
|
|
|
|
|
|
|
tx, err := FetchFundingTxWrapper(chain, chanID, quit)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
outputLocator := chanvalidate.ShortChanIDChanLocator{
|
|
|
|
ID: *chanID,
|
|
|
|
}
|
|
|
|
|
|
|
|
output, _, err := outputLocator.Locate(tx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return output.PkScript, nil
|
|
|
|
}
|