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

lightningnetwork / lnd / 10287175337

07 Aug 2024 03:23PM UTC coverage: 58.756% (+1.1%) from 57.666%
10287175337

push

github

web-flow
Merge pull request #8174 from yyforyongyu/fix-inflight-payments

routing: fix stuck inflight payments

389 of 498 new or added lines in 10 files covered. (78.11%)

1575 existing lines in 18 files now uncovered.

125920 of 214309 relevant lines covered (58.76%)

28435.58 hits per line

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

0.0
/cmd/lncli/types.go
1
package main
2

3
import (
4
        "encoding/hex"
5
        "errors"
6
        "fmt"
7
        "strconv"
8
        "strings"
9

10
        "github.com/btcsuite/btcd/chaincfg/chainhash"
11
        "github.com/lightningnetwork/lnd/lnrpc"
12
)
13

14
// OutPoint displays an outpoint string in the form "<txid>:<output-index>".
15
type OutPoint string
16

17
// NewOutPointFromProto formats the lnrpc.OutPoint into an OutPoint for display.
18
func NewOutPointFromProto(op *lnrpc.OutPoint) OutPoint {
×
19
        var hash chainhash.Hash
×
20
        copy(hash[:], op.TxidBytes)
×
21
        return OutPoint(fmt.Sprintf("%v:%d", hash, op.OutputIndex))
×
22
}
×
23

24
// NewProtoOutPoint parses an OutPoint into its corresponding lnrpc.OutPoint
25
// type.
26
func NewProtoOutPoint(op string) (*lnrpc.OutPoint, error) {
×
27
        parts := strings.Split(op, ":")
×
28
        if len(parts) != 2 {
×
29
                return nil, errors.New("outpoint should be of the form txid:index")
×
30
        }
×
31
        txid := parts[0]
×
32
        if hex.DecodedLen(len(txid)) != chainhash.HashSize {
×
33
                return nil, fmt.Errorf("invalid hex-encoded txid %v", txid)
×
34
        }
×
35
        outputIndex, err := strconv.Atoi(parts[1])
×
36
        if err != nil {
×
37
                return nil, fmt.Errorf("invalid output index: %w", err)
×
38
        }
×
39
        return &lnrpc.OutPoint{
×
40
                TxidStr:     txid,
×
41
                OutputIndex: uint32(outputIndex),
×
42
        }, nil
×
43
}
44

45
// Utxo displays information about an unspent output, including its address,
46
// amount, pkscript, and confirmations.
47
type Utxo struct {
48
        Type          lnrpc.AddressType `json:"address_type"`
49
        Address       string            `json:"address"`
50
        AmountSat     int64             `json:"amount_sat"`
51
        PkScript      string            `json:"pk_script"`
52
        OutPoint      OutPoint          `json:"outpoint"`
53
        Confirmations int64             `json:"confirmations"`
54
}
55

56
// NewUtxoFromProto creates a display Utxo from the Utxo proto. This filters out
57
// the raw txid bytes from the provided outpoint, which will otherwise be
58
// printed in base64.
59
func NewUtxoFromProto(utxo *lnrpc.Utxo) *Utxo {
×
60
        return &Utxo{
×
61
                Type:          utxo.AddressType,
×
62
                Address:       utxo.Address,
×
63
                AmountSat:     utxo.AmountSat,
×
64
                PkScript:      utxo.PkScript,
×
65
                OutPoint:      NewOutPointFromProto(utxo.Outpoint),
×
66
                Confirmations: utxo.Confirmations,
×
67
        }
×
68
}
×
69

70
// FailedUpdate displays information about a failed update, including its
71
// address, reason and update error.
72
type FailedUpdate struct {
73
        OutPoint    OutPoint `json:"outpoint"`
74
        Reason      string   `json:"reason"`
75
        UpdateError string   `json:"update_error"`
76
}
77

78
// NewFailedUpdateFromProto creates a display from the FailedUpdate
79
// proto. This filters out the raw txid bytes from the provided outpoint,
80
// which will otherwise be printed in base64.
81
func NewFailedUpdateFromProto(update *lnrpc.FailedUpdate) *FailedUpdate {
×
82
        return &FailedUpdate{
×
83
                OutPoint:    NewOutPointFromProto(update.Outpoint),
×
84
                Reason:      update.Reason.String(),
×
85
                UpdateError: update.UpdateError,
×
86
        }
×
87
}
×
88

89
// UtxosToOutpoints converts a slice of UTXO strings into a slice of OutPoint
90
// protobuf objects. It returns an error if no UTXOs are specified or if any
91
// UTXO string cannot be parsed into an OutPoint.
UNCOV
92
func UtxosToOutpoints(utxos []string) ([]*lnrpc.OutPoint, error) {
×
UNCOV
93
        var outpoints []*lnrpc.OutPoint
×
UNCOV
94
        if len(utxos) == 0 {
×
UNCOV
95
                return nil, fmt.Errorf("no utxos specified")
×
UNCOV
96
        }
×
UNCOV
97
        for _, utxo := range utxos {
×
UNCOV
98
                outpoint, err := NewProtoOutPoint(utxo)
×
UNCOV
99
                if err != nil {
×
UNCOV
100
                        return nil, err
×
UNCOV
101
                }
×
UNCOV
102
                outpoints = append(outpoints, outpoint)
×
103
        }
104

UNCOV
105
        return outpoints, nil
×
106
}
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

© 2026 Coveralls, Inc