• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 15205630088

23 May 2025 08:14AM UTC coverage: 57.45% (-11.5%) from 68.996%
15205630088

Pull #9784

github

web-flow
Merge f8b9f36a3 into c52a6ddeb
Pull Request #9784: [wip] lnwallet+walletrpc: add SubmitPackage and related RPC call

47 of 96 new or added lines in 5 files covered. (48.96%)

30087 existing lines in 459 files now uncovered.

95586 of 166380 relevant lines covered (57.45%)

0.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lntest/mock/walletcontroller.go
1
package mock
2

3
import (
4
        "encoding/hex"
5
        "sync/atomic"
6
        "time"
7

8
        "github.com/btcsuite/btcd/btcec/v2"
9
        "github.com/btcsuite/btcd/btcjson"
10
        "github.com/btcsuite/btcd/btcutil"
11
        "github.com/btcsuite/btcd/btcutil/hdkeychain"
12
        "github.com/btcsuite/btcd/btcutil/psbt"
13
        "github.com/btcsuite/btcd/chaincfg"
14
        "github.com/btcsuite/btcd/chaincfg/chainhash"
15
        "github.com/btcsuite/btcd/wire"
16
        "github.com/btcsuite/btcwallet/waddrmgr"
17
        base "github.com/btcsuite/btcwallet/wallet"
18
        "github.com/btcsuite/btcwallet/wallet/txauthor"
19
        "github.com/btcsuite/btcwallet/wtxmgr"
20
        "github.com/lightningnetwork/lnd/fn/v2"
21
        "github.com/lightningnetwork/lnd/lnwallet"
22
        "github.com/lightningnetwork/lnd/lnwallet/chainfee"
23
)
24

25
var (
26
        CoinPkScript, _ = hex.DecodeString("001431df1bde03c074d0cf21ea2529427e1499b8f1de")
27
)
28

29
// WalletController is a mock implementation of the WalletController
30
// interface. It let's us mock the interaction with the bitcoin network.
31
type WalletController struct {
32
        RootKey               *btcec.PrivateKey
33
        PublishedTransactions chan *wire.MsgTx
34
        index                 uint32
35
        Utxos                 []*lnwallet.Utxo
36
}
37

38
// A compile time check to ensure this mocked WalletController implements the
39
// WalletController.
40
var _ lnwallet.WalletController = (*WalletController)(nil)
41

42
// BackEnd returns "mock" to signify a mock wallet controller.
43
func (w *WalletController) BackEnd() string {
×
44
        return "mock"
×
45
}
×
46

47
// FetchOutpointInfo will be called to get info about the inputs to the funding
48
// transaction.
49
func (w *WalletController) FetchOutpointInfo(
UNCOV
50
        prevOut *wire.OutPoint) (*lnwallet.Utxo, error) {
×
UNCOV
51

×
UNCOV
52
        utxo := &lnwallet.Utxo{
×
UNCOV
53
                AddressType:   lnwallet.WitnessPubKey,
×
UNCOV
54
                Value:         10 * btcutil.SatoshiPerBitcoin,
×
UNCOV
55
                PkScript:      []byte("dummy"),
×
UNCOV
56
                Confirmations: 1,
×
UNCOV
57
                OutPoint:      *prevOut,
×
UNCOV
58
        }
×
UNCOV
59
        return utxo, nil
×
UNCOV
60
}
×
61

62
// ScriptForOutput returns the address, witness program and redeem script for a
63
// given UTXO. An error is returned if the UTXO does not belong to our wallet or
64
// it is not a managed pubKey address.
65
func (w *WalletController) ScriptForOutput(*wire.TxOut) (
66
        waddrmgr.ManagedPubKeyAddress, []byte, []byte, error) {
×
67

×
68
        return nil, nil, nil, nil
×
69
}
×
70

71
// ConfirmedBalance currently returns dummy values.
72
func (w *WalletController) ConfirmedBalance(int32, string) (btcutil.Amount,
73
        error) {
×
74

×
75
        return 0, nil
×
76
}
×
77

78
// NewAddress is called to get new addresses for delivery, change etc.
79
func (w *WalletController) NewAddress(lnwallet.AddressType, bool,
UNCOV
80
        string) (btcutil.Address, error) {
×
UNCOV
81

×
UNCOV
82
        pkh := btcutil.Hash160(w.RootKey.PubKey().SerializeCompressed())
×
UNCOV
83
        addr, _ := btcutil.NewAddressPubKeyHash(pkh, &chaincfg.MainNetParams)
×
UNCOV
84
        return addr, nil
×
UNCOV
85
}
×
86

87
// LastUnusedAddress currently returns dummy values.
88
func (w *WalletController) LastUnusedAddress(lnwallet.AddressType,
89
        string) (btcutil.Address, error) {
×
90

×
91
        return nil, nil
×
92
}
×
93

94
// IsOurAddress currently returns a dummy value.
UNCOV
95
func (w *WalletController) IsOurAddress(btcutil.Address) bool {
×
UNCOV
96
        return false
×
UNCOV
97
}
×
98

99
// AddressInfo currently returns a dummy value.
100
func (w *WalletController) AddressInfo(
101
        btcutil.Address) (waddrmgr.ManagedAddress, error) {
×
102

×
103
        return nil, nil
×
104
}
×
105

106
// ListAccounts currently returns a dummy value.
107
func (w *WalletController) ListAccounts(string,
108
        *waddrmgr.KeyScope) ([]*waddrmgr.AccountProperties, error) {
×
109

×
110
        return nil, nil
×
111
}
×
112

113
// RequiredReserve currently returns a dummy value.
UNCOV
114
func (w *WalletController) RequiredReserve(uint32) btcutil.Amount {
×
UNCOV
115
        return 0
×
UNCOV
116
}
×
117

118
// ListAddresses currently returns a dummy value.
119
func (w *WalletController) ListAddresses(string,
120
        bool) (lnwallet.AccountAddressMap, error) {
×
121

×
122
        return nil, nil
×
123
}
×
124

125
// ImportAccount currently returns a dummy value.
126
func (w *WalletController) ImportAccount(string, *hdkeychain.ExtendedKey,
127
        uint32, *waddrmgr.AddressType, bool) (*waddrmgr.AccountProperties,
128
        []btcutil.Address, []btcutil.Address, error) {
×
129

×
130
        return nil, nil, nil, nil
×
131
}
×
132

133
// ImportPublicKey currently returns a dummy value.
134
func (w *WalletController) ImportPublicKey(*btcec.PublicKey,
135
        waddrmgr.AddressType) error {
×
136

×
137
        return nil
×
138
}
×
139

140
// ImportTaprootScript currently returns a dummy value.
141
func (w *WalletController) ImportTaprootScript(waddrmgr.KeyScope,
142
        *waddrmgr.Tapscript) (waddrmgr.ManagedAddress, error) {
×
143

×
144
        return nil, nil
×
145
}
×
146

147
// SendOutputs currently returns dummy values.
148
func (w *WalletController) SendOutputs(fn.Set[wire.OutPoint], []*wire.TxOut,
149
        chainfee.SatPerKWeight, int32, string, base.CoinSelectionStrategy) (
150
        *wire.MsgTx, error) {
×
151

×
152
        return nil, nil
×
153
}
×
154

155
// CreateSimpleTx currently returns dummy values.
156
func (w *WalletController) CreateSimpleTx(fn.Set[wire.OutPoint], []*wire.TxOut,
157
        chainfee.SatPerKWeight, int32, base.CoinSelectionStrategy,
158
        bool) (*txauthor.AuthoredTx, error) {
×
159

×
160
        return nil, nil
×
161
}
×
162

163
// ListUnspentWitness is called by the wallet when doing coin selection. We just
164
// need one unspent for the funding transaction.
165
func (w *WalletController) ListUnspentWitness(int32, int32,
UNCOV
166
        string) ([]*lnwallet.Utxo, error) {
×
UNCOV
167

×
UNCOV
168
        // If the mock already has a list of utxos, return it.
×
UNCOV
169
        if w.Utxos != nil {
×
UNCOV
170
                return w.Utxos, nil
×
UNCOV
171
        }
×
172

173
        // Otherwise create one to return.
UNCOV
174
        utxo := &lnwallet.Utxo{
×
UNCOV
175
                AddressType: lnwallet.WitnessPubKey,
×
UNCOV
176
                Value:       btcutil.Amount(10 * btcutil.SatoshiPerBitcoin),
×
UNCOV
177
                PkScript:    CoinPkScript,
×
UNCOV
178
                OutPoint: wire.OutPoint{
×
UNCOV
179
                        Hash:  chainhash.Hash{},
×
UNCOV
180
                        Index: w.index,
×
UNCOV
181
                },
×
UNCOV
182
        }
×
UNCOV
183
        atomic.AddUint32(&w.index, 1)
×
UNCOV
184
        var ret []*lnwallet.Utxo
×
UNCOV
185
        ret = append(ret, utxo)
×
UNCOV
186
        return ret, nil
×
187
}
188

189
// ListTransactionDetails currently returns dummy values.
190
func (w *WalletController) ListTransactionDetails(int32, int32,
191
        string, uint32, uint32) ([]*lnwallet.TransactionDetail,
192
        uint64, uint64, error) {
×
193

×
194
        return nil, 0, 0, nil
×
195
}
×
196

197
// LeaseOutput returns the current time and a nil error.
198
func (w *WalletController) LeaseOutput(wtxmgr.LockID, wire.OutPoint,
UNCOV
199
        time.Duration) (time.Time, error) {
×
UNCOV
200

×
UNCOV
201
        return time.Now(), nil
×
UNCOV
202
}
×
203

204
// ReleaseOutput currently does nothing.
UNCOV
205
func (w *WalletController) ReleaseOutput(wtxmgr.LockID, wire.OutPoint) error {
×
UNCOV
206
        return nil
×
UNCOV
207
}
×
208

209
func (w *WalletController) ListLeasedOutputs() ([]*base.ListLeasedOutputResult,
210
        error) {
×
211

×
212
        return nil, nil
×
213
}
×
214

215
// FundPsbt currently does nothing.
216
func (w *WalletController) FundPsbt(*psbt.Packet, int32, chainfee.SatPerKWeight,
217
        string, *waddrmgr.KeyScope, base.CoinSelectionStrategy,
218
        func(utxo wtxmgr.Credit) bool) (int32, error) {
×
219

×
220
        return 0, nil
×
221
}
×
222

223
// SignPsbt currently does nothing.
224
func (w *WalletController) SignPsbt(*psbt.Packet) ([]uint32, error) {
×
225
        return nil, nil
×
226
}
×
227

228
// FinalizePsbt currently does nothing.
229
func (w *WalletController) FinalizePsbt(_ *psbt.Packet, _ string) error {
×
230
        return nil
×
231
}
×
232

233
// DecorateInputs currently does nothing.
234
func (w *WalletController) DecorateInputs(*psbt.Packet, bool) error {
×
235
        return nil
×
236
}
×
237

238
// PublishTransaction sends a transaction to the PublishedTransactions chan.
UNCOV
239
func (w *WalletController) PublishTransaction(tx *wire.MsgTx, _ string) error {
×
UNCOV
240
        w.PublishedTransactions <- tx
×
UNCOV
241
        return nil
×
UNCOV
242
}
×
243

244
// GetTransactionDetails currently does nothing.
245
func (w *WalletController) GetTransactionDetails(
246
        txHash *chainhash.Hash) (*lnwallet.TransactionDetail, error) {
×
247

×
248
        return nil, nil
×
249
}
×
250

251
// LabelTransaction currently does nothing.
252
func (w *WalletController) LabelTransaction(chainhash.Hash, string,
253
        bool) error {
×
254

×
255
        return nil
×
256
}
×
257

258
// SubscribeTransactions currently does nothing.
259
func (w *WalletController) SubscribeTransactions() (lnwallet.TransactionSubscription,
260
        error) {
×
261

×
262
        return nil, nil
×
263
}
×
264

265
// IsSynced currently returns dummy values.
UNCOV
266
func (w *WalletController) IsSynced() (bool, int64, error) {
×
UNCOV
267
        return true, int64(0), nil
×
UNCOV
268
}
×
269

270
// GetRecoveryInfo currently returns dummy values.
271
func (w *WalletController) GetRecoveryInfo() (bool, float64, error) {
×
272
        return true, float64(1), nil
×
273
}
×
274

275
// Start currently does nothing.
UNCOV
276
func (w *WalletController) Start() error {
×
UNCOV
277
        return nil
×
UNCOV
278
}
×
279

280
// Stop currently does nothing.
281
func (w *WalletController) Stop() error {
×
282
        return nil
×
283
}
×
284

285
func (w *WalletController) FetchTx(chainhash.Hash) (*wire.MsgTx, error) {
×
286
        return nil, nil
×
287
}
×
288

289
func (w *WalletController) RemoveDescendants(*wire.MsgTx) error {
×
290
        return nil
×
291
}
×
292

293
func (w *WalletController) CheckMempoolAcceptance(tx *wire.MsgTx) error {
×
294
        return nil
×
295
}
×
296

297
func (w *WalletController) SubmitPackage([]*wire.MsgTx, *wire.MsgTx,
NEW
298
        chainfee.SatPerKWeight) (*btcjson.SubmitPackageResult, error) {
×
NEW
299

×
NEW
300
        return nil, nil
×
NEW
301
}
×
302

303
// FetchDerivationInfo queries for the wallet's knowledge of the passed
304
// pkScript and constructs the derivation info and returns it.
305
func (w *WalletController) FetchDerivationInfo(
306
        pkScript []byte) (*psbt.Bip32Derivation, error) {
×
307

×
308
        return nil, nil
×
309
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc