2020-08-26 15:06:46 -04:00
|
|
|
package mock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"sync/atomic"
|
|
|
|
"time"
|
|
|
|
|
2022-02-23 14:48:00 +01:00
|
|
|
"github.com/btcsuite/btcd/btcec/v2"
|
|
|
|
"github.com/btcsuite/btcd/btcutil"
|
|
|
|
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
|
|
|
"github.com/btcsuite/btcd/btcutil/psbt"
|
2020-08-26 15:06:46 -04:00
|
|
|
"github.com/btcsuite/btcd/chaincfg"
|
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
|
|
|
"github.com/btcsuite/btcd/wire"
|
2021-02-19 17:42:02 -08:00
|
|
|
"github.com/btcsuite/btcwallet/waddrmgr"
|
2022-05-12 10:24:40 +02:00
|
|
|
base "github.com/btcsuite/btcwallet/wallet"
|
2020-08-26 15:06:46 -04:00
|
|
|
"github.com/btcsuite/btcwallet/wallet/txauthor"
|
|
|
|
"github.com/btcsuite/btcwallet/wtxmgr"
|
2024-03-01 20:25:20 +01:00
|
|
|
"github.com/lightningnetwork/lnd/fn"
|
2020-08-26 15:06:46 -04:00
|
|
|
"github.com/lightningnetwork/lnd/lnwallet"
|
|
|
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
CoinPkScript, _ = hex.DecodeString("001431df1bde03c074d0cf21ea2529427e1499b8f1de")
|
|
|
|
)
|
|
|
|
|
|
|
|
// WalletController is a mock implementation of the WalletController
|
|
|
|
// interface. It let's us mock the interaction with the bitcoin network.
|
|
|
|
type WalletController struct {
|
|
|
|
RootKey *btcec.PrivateKey
|
|
|
|
PublishedTransactions chan *wire.MsgTx
|
|
|
|
index uint32
|
|
|
|
Utxos []*lnwallet.Utxo
|
|
|
|
}
|
|
|
|
|
2024-03-01 20:25:20 +01:00
|
|
|
// A compile time check to ensure this mocked WalletController implements the
|
|
|
|
// WalletController.
|
|
|
|
var _ lnwallet.WalletController = (*WalletController)(nil)
|
|
|
|
|
2020-08-26 15:06:46 -04:00
|
|
|
// BackEnd returns "mock" to signify a mock wallet controller.
|
|
|
|
func (w *WalletController) BackEnd() string {
|
|
|
|
return "mock"
|
|
|
|
}
|
|
|
|
|
|
|
|
// FetchInputInfo will be called to get info about the inputs to the funding
|
|
|
|
// transaction.
|
|
|
|
func (w *WalletController) FetchInputInfo(
|
|
|
|
prevOut *wire.OutPoint) (*lnwallet.Utxo, error) {
|
|
|
|
|
|
|
|
utxo := &lnwallet.Utxo{
|
|
|
|
AddressType: lnwallet.WitnessPubKey,
|
|
|
|
Value: 10 * btcutil.SatoshiPerBitcoin,
|
|
|
|
PkScript: []byte("dummy"),
|
|
|
|
Confirmations: 1,
|
|
|
|
OutPoint: *prevOut,
|
|
|
|
}
|
|
|
|
return utxo, nil
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
func (w *WalletController) ScriptForOutput(*wire.TxOut) (
|
|
|
|
waddrmgr.ManagedPubKeyAddress, []byte, []byte, error) {
|
|
|
|
|
|
|
|
return nil, nil, nil, nil
|
|
|
|
}
|
|
|
|
|
2020-08-26 15:06:46 -04:00
|
|
|
// ConfirmedBalance currently returns dummy values.
|
2022-01-05 11:04:14 +01:00
|
|
|
func (w *WalletController) ConfirmedBalance(int32, string) (btcutil.Amount,
|
|
|
|
error) {
|
|
|
|
|
2020-08-26 15:06:46 -04:00
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewAddress is called to get new addresses for delivery, change etc.
|
2022-01-05 11:04:14 +01:00
|
|
|
func (w *WalletController) NewAddress(lnwallet.AddressType, bool,
|
|
|
|
string) (btcutil.Address, error) {
|
2020-08-26 15:06:46 -04:00
|
|
|
|
|
|
|
addr, _ := btcutil.NewAddressPubKey(
|
|
|
|
w.RootKey.PubKey().SerializeCompressed(), &chaincfg.MainNetParams,
|
|
|
|
)
|
|
|
|
return addr, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// LastUnusedAddress currently returns dummy values.
|
2022-01-05 11:04:14 +01:00
|
|
|
func (w *WalletController) LastUnusedAddress(lnwallet.AddressType,
|
|
|
|
string) (btcutil.Address, error) {
|
|
|
|
|
2020-08-26 15:06:46 -04:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsOurAddress currently returns a dummy value.
|
2022-01-05 11:04:14 +01:00
|
|
|
func (w *WalletController) IsOurAddress(btcutil.Address) bool {
|
2020-08-26 15:06:46 -04:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-03-16 15:11:13 +01:00
|
|
|
// AddressInfo currently returns a dummy value.
|
|
|
|
func (w *WalletController) AddressInfo(
|
|
|
|
btcutil.Address) (waddrmgr.ManagedAddress, error) {
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-02-19 17:42:02 -08:00
|
|
|
// ListAccounts currently returns a dummy value.
|
2022-01-05 11:04:14 +01:00
|
|
|
func (w *WalletController) ListAccounts(string,
|
|
|
|
*waddrmgr.KeyScope) ([]*waddrmgr.AccountProperties, error) {
|
|
|
|
|
2021-02-19 17:42:02 -08:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2022-06-17 21:07:17 +05:30
|
|
|
// RequiredReserve currently returns a dummy value.
|
|
|
|
func (w *WalletController) RequiredReserve(uint32) btcutil.Amount {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2022-07-23 11:05:53 +05:30
|
|
|
// ListAddresses currently returns a dummy value.
|
|
|
|
func (w *WalletController) ListAddresses(string,
|
|
|
|
bool) (lnwallet.AccountAddressMap, error) {
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-02-19 17:42:02 -08:00
|
|
|
// ImportAccount currently returns a dummy value.
|
|
|
|
func (w *WalletController) ImportAccount(string, *hdkeychain.ExtendedKey,
|
2021-05-04 15:56:26 -07:00
|
|
|
uint32, *waddrmgr.AddressType, bool) (*waddrmgr.AccountProperties,
|
|
|
|
[]btcutil.Address, []btcutil.Address, error) {
|
2022-01-05 11:04:14 +01:00
|
|
|
|
2021-05-04 15:56:26 -07:00
|
|
|
return nil, nil, nil, nil
|
2021-02-19 17:42:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImportPublicKey currently returns a dummy value.
|
|
|
|
func (w *WalletController) ImportPublicKey(*btcec.PublicKey,
|
|
|
|
waddrmgr.AddressType) error {
|
2022-01-05 11:04:14 +01:00
|
|
|
|
2021-02-19 17:42:02 -08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-07-29 18:20:05 +02:00
|
|
|
// ImportTaprootScript currently returns a dummy value.
|
|
|
|
func (w *WalletController) ImportTaprootScript(waddrmgr.KeyScope,
|
|
|
|
*waddrmgr.Tapscript) (waddrmgr.ManagedAddress, error) {
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2020-08-26 15:06:46 -04:00
|
|
|
// SendOutputs currently returns dummy values.
|
2024-03-01 20:25:20 +01:00
|
|
|
func (w *WalletController) SendOutputs(fn.Set[wire.OutPoint], []*wire.TxOut,
|
|
|
|
chainfee.SatPerKWeight, int32, string, base.CoinSelectionStrategy) (
|
|
|
|
*wire.MsgTx, error) {
|
2020-08-26 15:06:46 -04:00
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateSimpleTx currently returns dummy values.
|
2024-03-01 20:25:20 +01:00
|
|
|
func (w *WalletController) CreateSimpleTx(fn.Set[wire.OutPoint], []*wire.TxOut,
|
2024-03-26 19:08:27 +02:00
|
|
|
chainfee.SatPerKWeight, int32, base.CoinSelectionStrategy,
|
|
|
|
bool) (*txauthor.AuthoredTx, error) {
|
2020-08-26 15:06:46 -04:00
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListUnspentWitness is called by the wallet when doing coin selection. We just
|
|
|
|
// need one unspent for the funding transaction.
|
2022-01-05 11:04:14 +01:00
|
|
|
func (w *WalletController) ListUnspentWitness(int32, int32,
|
|
|
|
string) ([]*lnwallet.Utxo, error) {
|
2020-08-26 15:06:46 -04:00
|
|
|
|
|
|
|
// If the mock already has a list of utxos, return it.
|
|
|
|
if w.Utxos != nil {
|
|
|
|
return w.Utxos, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise create one to return.
|
|
|
|
utxo := &lnwallet.Utxo{
|
|
|
|
AddressType: lnwallet.WitnessPubKey,
|
|
|
|
Value: btcutil.Amount(10 * btcutil.SatoshiPerBitcoin),
|
|
|
|
PkScript: CoinPkScript,
|
|
|
|
OutPoint: wire.OutPoint{
|
|
|
|
Hash: chainhash.Hash{},
|
|
|
|
Index: w.index,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
atomic.AddUint32(&w.index, 1)
|
|
|
|
var ret []*lnwallet.Utxo
|
|
|
|
ret = append(ret, utxo)
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListTransactionDetails currently returns dummy values.
|
2022-01-05 11:04:14 +01:00
|
|
|
func (w *WalletController) ListTransactionDetails(int32, int32,
|
|
|
|
string) ([]*lnwallet.TransactionDetail, error) {
|
2020-08-26 15:06:46 -04:00
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// LeaseOutput returns the current time and a nil error.
|
2021-03-12 08:45:12 +01:00
|
|
|
func (w *WalletController) LeaseOutput(wtxmgr.LockID, wire.OutPoint,
|
2022-05-12 10:24:40 +02:00
|
|
|
time.Duration) (time.Time, []byte, btcutil.Amount, error) {
|
2020-08-26 15:06:46 -04:00
|
|
|
|
2022-05-12 10:24:40 +02:00
|
|
|
return time.Now(), nil, 0, nil
|
2020-08-26 15:06:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReleaseOutput currently does nothing.
|
|
|
|
func (w *WalletController) ReleaseOutput(wtxmgr.LockID, wire.OutPoint) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-12 10:24:40 +02:00
|
|
|
func (w *WalletController) ListLeasedOutputs() ([]*base.ListLeasedOutputResult,
|
|
|
|
error) {
|
|
|
|
|
2021-03-12 09:26:24 +01:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2020-10-01 16:21:44 +02:00
|
|
|
// FundPsbt currently does nothing.
|
2022-01-05 11:04:14 +01:00
|
|
|
func (w *WalletController) FundPsbt(*psbt.Packet, int32, chainfee.SatPerKWeight,
|
2024-03-30 17:03:09 +00:00
|
|
|
string, *waddrmgr.KeyScope, base.CoinSelectionStrategy,
|
|
|
|
func(utxo wtxmgr.Credit) bool) (int32, error) {
|
2020-10-01 16:21:44 +02:00
|
|
|
|
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
|
2022-01-05 11:04:23 +01:00
|
|
|
// SignPsbt currently does nothing.
|
2022-08-16 19:31:06 -04:00
|
|
|
func (w *WalletController) SignPsbt(*psbt.Packet) ([]uint32, error) {
|
|
|
|
return nil, nil
|
2022-01-05 11:04:23 +01:00
|
|
|
}
|
|
|
|
|
2020-10-01 16:21:44 +02:00
|
|
|
// FinalizePsbt currently does nothing.
|
2021-02-19 17:41:45 -08:00
|
|
|
func (w *WalletController) FinalizePsbt(_ *psbt.Packet, _ string) error {
|
2020-10-01 16:21:44 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-02-06 12:25:54 +01:00
|
|
|
// DecorateInputs currently does nothing.
|
|
|
|
func (w *WalletController) DecorateInputs(*psbt.Packet, bool) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-26 15:06:46 -04:00
|
|
|
// PublishTransaction sends a transaction to the PublishedTransactions chan.
|
|
|
|
func (w *WalletController) PublishTransaction(tx *wire.MsgTx, _ string) error {
|
|
|
|
w.PublishedTransactions <- tx
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-01-18 13:29:09 +08:00
|
|
|
// GetTransactionDetails currently does nothing.
|
|
|
|
func (w *WalletController) GetTransactionDetails(
|
|
|
|
txHash *chainhash.Hash) (*lnwallet.TransactionDetail, error) {
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2020-08-26 15:06:46 -04:00
|
|
|
// LabelTransaction currently does nothing.
|
2022-01-05 11:04:14 +01:00
|
|
|
func (w *WalletController) LabelTransaction(chainhash.Hash, string,
|
|
|
|
bool) error {
|
2020-08-26 15:06:46 -04:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SubscribeTransactions currently does nothing.
|
|
|
|
func (w *WalletController) SubscribeTransactions() (lnwallet.TransactionSubscription,
|
|
|
|
error) {
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsSynced currently returns dummy values.
|
|
|
|
func (w *WalletController) IsSynced() (bool, int64, error) {
|
|
|
|
return true, int64(0), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRecoveryInfo currently returns dummy values.
|
|
|
|
func (w *WalletController) GetRecoveryInfo() (bool, float64, error) {
|
|
|
|
return true, float64(1), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start currently does nothing.
|
|
|
|
func (w *WalletController) Start() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop currently does nothing.
|
|
|
|
func (w *WalletController) Stop() error {
|
|
|
|
return nil
|
|
|
|
}
|
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-17 18:25:30 -08:00
|
|
|
|
|
|
|
func (w *WalletController) FetchTx(chainhash.Hash) (*wire.MsgTx, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *WalletController) RemoveDescendants(*wire.MsgTx) error {
|
|
|
|
return nil
|
|
|
|
}
|
2024-02-29 03:07:22 +08:00
|
|
|
|
|
|
|
func (w *WalletController) CheckMempoolAcceptance(tx *wire.MsgTx) error {
|
|
|
|
return nil
|
|
|
|
}
|