2020-08-26 22:06:46 +03:00
|
|
|
package mock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"sync/atomic"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/btcsuite/btcd/btcec"
|
|
|
|
"github.com/btcsuite/btcd/chaincfg"
|
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
|
|
|
"github.com/btcsuite/btcd/wire"
|
|
|
|
"github.com/btcsuite/btcutil"
|
2021-02-20 04:42:02 +03:00
|
|
|
"github.com/btcsuite/btcutil/hdkeychain"
|
2020-10-01 17:21:44 +03:00
|
|
|
"github.com/btcsuite/btcutil/psbt"
|
2021-02-20 04:42:02 +03:00
|
|
|
"github.com/btcsuite/btcwallet/waddrmgr"
|
2020-08-26 22:06:46 +03:00
|
|
|
"github.com/btcsuite/btcwallet/wallet/txauthor"
|
|
|
|
"github.com/btcsuite/btcwallet/wtxmgr"
|
|
|
|
|
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConfirmedBalance currently returns dummy values.
|
2021-02-20 04:41:50 +03:00
|
|
|
func (w *WalletController) ConfirmedBalance(confs int32,
|
|
|
|
_ string) (btcutil.Amount, error) {
|
2020-08-26 22:06:46 +03:00
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewAddress is called to get new addresses for delivery, change etc.
|
|
|
|
func (w *WalletController) NewAddress(addrType lnwallet.AddressType,
|
2021-02-20 04:41:45 +03:00
|
|
|
change bool, _ string) (btcutil.Address, error) {
|
2020-08-26 22:06:46 +03:00
|
|
|
|
|
|
|
addr, _ := btcutil.NewAddressPubKey(
|
|
|
|
w.RootKey.PubKey().SerializeCompressed(), &chaincfg.MainNetParams,
|
|
|
|
)
|
|
|
|
return addr, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// LastUnusedAddress currently returns dummy values.
|
2021-02-20 04:41:45 +03:00
|
|
|
func (w *WalletController) LastUnusedAddress(addrType lnwallet.AddressType,
|
|
|
|
_ string) (btcutil.Address, error) {
|
2020-08-26 22:06:46 +03:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsOurAddress currently returns a dummy value.
|
|
|
|
func (w *WalletController) IsOurAddress(a btcutil.Address) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-02-20 04:42:02 +03:00
|
|
|
// ListAccounts currently returns a dummy value.
|
|
|
|
func (w *WalletController) ListAccounts(_ string,
|
|
|
|
_ *waddrmgr.KeyScope) ([]*waddrmgr.AccountProperties, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ImportAccount currently returns a dummy value.
|
|
|
|
func (w *WalletController) ImportAccount(string, *hdkeychain.ExtendedKey,
|
|
|
|
uint32, *waddrmgr.AddressType) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ImportPublicKey currently returns a dummy value.
|
|
|
|
func (w *WalletController) ImportPublicKey(*btcec.PublicKey,
|
|
|
|
waddrmgr.AddressType) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-26 22:06:46 +03:00
|
|
|
// SendOutputs currently returns dummy values.
|
|
|
|
func (w *WalletController) SendOutputs(outputs []*wire.TxOut,
|
2020-09-27 18:48:15 +03:00
|
|
|
_ chainfee.SatPerKWeight, _ int32, _ string) (*wire.MsgTx, error) {
|
2020-08-26 22:06:46 +03:00
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateSimpleTx currently returns dummy values.
|
|
|
|
func (w *WalletController) CreateSimpleTx(outputs []*wire.TxOut,
|
|
|
|
_ chainfee.SatPerKWeight, _ bool) (*txauthor.AuthoredTx, error) {
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListUnspentWitness is called by the wallet when doing coin selection. We just
|
|
|
|
// need one unspent for the funding transaction.
|
|
|
|
func (w *WalletController) ListUnspentWitness(minconfirms,
|
2021-02-20 04:41:50 +03:00
|
|
|
maxconfirms int32, _ string) ([]*lnwallet.Utxo, error) {
|
2020-08-26 22:06:46 +03: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.
|
|
|
|
func (w *WalletController) ListTransactionDetails(_,
|
2021-02-20 04:41:50 +03:00
|
|
|
_ int32, _ string) ([]*lnwallet.TransactionDetail, error) {
|
2020-08-26 22:06:46 +03:00
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// LockOutpoint currently does nothing.
|
|
|
|
func (w *WalletController) LockOutpoint(o wire.OutPoint) {}
|
|
|
|
|
|
|
|
// UnlockOutpoint currently does nothing.
|
|
|
|
func (w *WalletController) UnlockOutpoint(o wire.OutPoint) {}
|
|
|
|
|
|
|
|
// LeaseOutput returns the current time and a nil error.
|
2021-03-12 10:45:12 +03:00
|
|
|
func (w *WalletController) LeaseOutput(wtxmgr.LockID, wire.OutPoint,
|
|
|
|
time.Duration) (time.Time, error) {
|
2020-08-26 22:06:46 +03:00
|
|
|
|
|
|
|
return time.Now(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReleaseOutput currently does nothing.
|
|
|
|
func (w *WalletController) ReleaseOutput(wtxmgr.LockID, wire.OutPoint) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-12 11:26:24 +03:00
|
|
|
func (w *WalletController) ListLeasedOutputs() ([]*wtxmgr.LockedOutput, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2020-10-01 17:21:44 +03:00
|
|
|
// FundPsbt currently does nothing.
|
|
|
|
func (w *WalletController) FundPsbt(_ *psbt.Packet,
|
2021-02-20 04:41:45 +03:00
|
|
|
_ chainfee.SatPerKWeight, _ string) (int32, error) {
|
2020-10-01 17:21:44 +03:00
|
|
|
|
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FinalizePsbt currently does nothing.
|
2021-02-20 04:41:45 +03:00
|
|
|
func (w *WalletController) FinalizePsbt(_ *psbt.Packet, _ string) error {
|
2020-10-01 17:21:44 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-26 22:06:46 +03:00
|
|
|
// PublishTransaction sends a transaction to the PublishedTransactions chan.
|
|
|
|
func (w *WalletController) PublishTransaction(tx *wire.MsgTx, _ string) error {
|
|
|
|
w.PublishedTransactions <- tx
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// LabelTransaction currently does nothing.
|
|
|
|
func (w *WalletController) LabelTransaction(_ chainhash.Hash, _ string,
|
|
|
|
_ bool) error {
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|