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

lightningnetwork / lnd / 13412100018

19 Feb 2025 12:05PM UTC coverage: 44.914% (-13.9%) from 58.794%
13412100018

Pull #9521

github

web-flow
Merge 861d6970e into 0e8786348
Pull Request #9521: unit: remove GOACC, use Go 1.20 native coverage functionality

101023 of 224923 relevant lines covered (44.91%)

19479.4 hits per line

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

47.27
/lnrpc/walletrpc/psbt.go
1
//go:build walletrpc
2
// +build walletrpc
3

4
package walletrpc
5

6
import (
7
        "fmt"
8
        "math"
9

10
        "github.com/btcsuite/btcd/wire"
11
        base "github.com/btcsuite/btcwallet/wallet"
12
        "github.com/btcsuite/btcwallet/wtxmgr"
13
        "github.com/lightningnetwork/lnd/lnwallet"
14
        "github.com/lightningnetwork/lnd/lnwallet/chanfunding"
15
)
16

17
const (
18
        defaultMaxConf = math.MaxInt32
19
)
20

21
// verifyInputsUnspent checks that all inputs are contained in the list of
22
// known, non-locked UTXOs given.
23
func verifyInputsUnspent(inputs []*wire.TxIn, utxos []*lnwallet.Utxo) error {
×
24
        // TODO(guggero): Pass in UTXOs as a map to make lookup more efficient.
×
25
        for idx, txIn := range inputs {
×
26
                found := false
×
27
                for _, u := range utxos {
×
28
                        if u.OutPoint == txIn.PreviousOutPoint {
×
29
                                found = true
×
30
                                break
×
31
                        }
32
                }
33

34
                if !found {
×
35
                        return fmt.Errorf("input %d not found in list of non-"+
×
36
                                "locked UTXO", idx)
×
37
                }
×
38
        }
39

40
        return nil
×
41
}
42

43
// lockInputs requests a lock lease for all inputs specified in a PSBT packet
44
// by using the internal, static lock ID of lnd's wallet.
45
func lockInputs(w lnwallet.WalletController,
46
        outpoints []wire.OutPoint) ([]*base.ListLeasedOutputResult, error) {
14✔
47

14✔
48
        locks := make(
14✔
49
                []*base.ListLeasedOutputResult, len(outpoints),
14✔
50
        )
14✔
51
        for idx := range outpoints {
27✔
52
                lock := &base.ListLeasedOutputResult{
13✔
53
                        LockedOutput: &wtxmgr.LockedOutput{
13✔
54
                                LockID:   chanfunding.LndInternalLockID,
13✔
55
                                Outpoint: outpoints[idx],
13✔
56
                        },
13✔
57
                }
13✔
58

13✔
59
                // Get the details about this outpoint.
13✔
60
                utxo, err := w.FetchOutpointInfo(&lock.Outpoint)
13✔
61
                if err != nil {
13✔
62
                        return nil, fmt.Errorf("fetch outpoint info: %w", err)
×
63
                }
×
64

65
                expiration, err := w.LeaseOutput(
13✔
66
                        lock.LockID, lock.Outpoint,
13✔
67
                        chanfunding.DefaultLockDuration,
13✔
68
                )
13✔
69
                if err != nil {
13✔
70
                        // If we run into a problem with locking one output, we
×
71
                        // should try to unlock those that we successfully
×
72
                        // locked so far. If that fails as well, there's not
×
73
                        // much we can do.
×
74
                        for i := 0; i < idx; i++ {
×
75
                                op := locks[i].Outpoint
×
76
                                if err := w.ReleaseOutput(
×
77
                                        chanfunding.LndInternalLockID, op,
×
78
                                ); err != nil {
×
79
                                        log.Errorf("could not release the "+
×
80
                                                "lock on %v: %v", op, err)
×
81
                                }
×
82
                        }
83

84
                        return nil, fmt.Errorf("could not lease a lock on "+
×
85
                                "UTXO: %v", err)
×
86
                }
87

88
                lock.Expiration = expiration
13✔
89
                lock.PkScript = utxo.PkScript
13✔
90
                lock.Value = int64(utxo.Value)
13✔
91
                locks[idx] = lock
13✔
92
        }
93

94
        return locks, nil
14✔
95
}
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