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

lightningnetwork / lnd / 13035292482

29 Jan 2025 03:59PM UTC coverage: 49.3% (-9.5%) from 58.777%
13035292482

Pull #9456

github

mohamedawnallah
docs: update release-notes-0.19.0.md

In this commit, we warn users about the removal
of RPCs `SendToRoute`, `SendToRouteSync`, `SendPayment`,
and `SendPaymentSync` in the next release 0.20.
Pull Request #9456: lnrpc+docs: deprecate warning `SendToRoute`, `SendToRouteSync`, `SendPayment`, and `SendPaymentSync` in Release 0.19

100634 of 204126 relevant lines covered (49.3%)

1.54 hits per line

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

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

3
import (
4
        "sync"
5

6
        "github.com/btcsuite/btcd/wire"
7
        "github.com/lightningnetwork/lnd/chainntnfs"
8
)
9

10
// SpendNotifier extends the mock.ChainNotifier so that spend
11
// notifications can be triggered and delivered to subscribers.
12
type SpendNotifier struct {
13
        *ChainNotifier
14
        spendMap map[wire.OutPoint][]chan *chainntnfs.SpendDetail
15
        spends   map[wire.OutPoint]*chainntnfs.SpendDetail
16
        mtx      sync.Mutex
17
}
18

19
// MakeMockSpendNotifier creates a SpendNotifier.
20
func MakeMockSpendNotifier() *SpendNotifier {
×
21
        return &SpendNotifier{
×
22
                ChainNotifier: &ChainNotifier{
×
23
                        SpendChan: make(chan *chainntnfs.SpendDetail),
×
24
                        EpochChan: make(chan *chainntnfs.BlockEpoch),
×
25
                        ConfChan:  make(chan *chainntnfs.TxConfirmation),
×
26
                },
×
27
                spendMap: make(map[wire.OutPoint][]chan *chainntnfs.SpendDetail),
×
28
                spends:   make(map[wire.OutPoint]*chainntnfs.SpendDetail),
×
29
        }
×
30
}
×
31

32
// RegisterSpendNtfn registers a spend notification for a specified outpoint.
33
func (s *SpendNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
34
        _ []byte, heightHint uint32) (*chainntnfs.SpendEvent, error) {
×
35

×
36
        s.mtx.Lock()
×
37
        defer s.mtx.Unlock()
×
38

×
39
        spendChan := make(chan *chainntnfs.SpendDetail, 1)
×
40
        if detail, ok := s.spends[*outpoint]; ok {
×
41
                // Deliver spend immediately if details are already known.
×
42
                spendChan <- &chainntnfs.SpendDetail{
×
43
                        SpentOutPoint:     detail.SpentOutPoint,
×
44
                        SpendingHeight:    detail.SpendingHeight,
×
45
                        SpendingTx:        detail.SpendingTx,
×
46
                        SpenderTxHash:     detail.SpenderTxHash,
×
47
                        SpenderInputIndex: detail.SpenderInputIndex,
×
48
                }
×
49
        } else {
×
50
                // Otherwise, queue the notification for delivery if the spend
×
51
                // is ever received.
×
52
                s.spendMap[*outpoint] = append(s.spendMap[*outpoint], spendChan)
×
53
        }
×
54

55
        return &chainntnfs.SpendEvent{
×
56
                Spend:  spendChan,
×
57
                Cancel: func() {},
×
58
        }, nil
59
}
60

61
// Spend dispatches SpendDetails to all subscribers of the outpoint. The details
62
// will includethe transaction and height provided by the caller.
63
func (s *SpendNotifier) Spend(outpoint *wire.OutPoint, height int32,
64
        txn *wire.MsgTx) {
×
65

×
66
        s.mtx.Lock()
×
67
        defer s.mtx.Unlock()
×
68

×
69
        var inputIndex uint32
×
70
        for i, in := range txn.TxIn {
×
71
                if in.PreviousOutPoint == *outpoint {
×
72
                        inputIndex = uint32(i)
×
73
                }
×
74
        }
75

76
        txnHash := txn.TxHash()
×
77
        details := &chainntnfs.SpendDetail{
×
78
                SpentOutPoint:     outpoint,
×
79
                SpendingHeight:    height,
×
80
                SpendingTx:        txn,
×
81
                SpenderTxHash:     &txnHash,
×
82
                SpenderInputIndex: inputIndex,
×
83
        }
×
84

×
85
        // Cache details in case of late registration.
×
86
        if _, ok := s.spends[*outpoint]; !ok {
×
87
                s.spends[*outpoint] = details
×
88
        }
×
89

90
        // Deliver any backlogged spend notifications.
91
        if spendChans, ok := s.spendMap[*outpoint]; ok {
×
92
                delete(s.spendMap, *outpoint)
×
93
                for _, spendChan := range spendChans {
×
94
                        spendChan <- &chainntnfs.SpendDetail{
×
95
                                SpentOutPoint:     details.SpentOutPoint,
×
96
                                SpendingHeight:    details.SpendingHeight,
×
97
                                SpendingTx:        details.SpendingTx,
×
98
                                SpenderTxHash:     details.SpenderTxHash,
×
99
                                SpenderInputIndex: details.SpenderInputIndex,
×
100
                        }
×
101
                }
×
102
        }
103
}
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