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

lightningnetwork / lnd / 14358372723

09 Apr 2025 01:26PM UTC coverage: 56.696% (-12.3%) from 69.037%
14358372723

Pull #9696

github

web-flow
Merge e2837e400 into 867d27d68
Pull Request #9696: Add `development_guidelines.md` for both human and machine

107055 of 188823 relevant lines covered (56.7%)

22721.56 hits per line

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

0.0
/lnrpc/invoicesrpc/htlc_modifier.go
1
package invoicesrpc
2

3
import (
4
        "fmt"
5

6
        "github.com/btcsuite/btcd/chaincfg"
7
        "github.com/lightningnetwork/lnd/invoices"
8
        "github.com/lightningnetwork/lnd/lnwire"
9
)
10

11
// htlcModifier is a helper struct that handles the lifecycle of an RPC invoice
12
// HTLC modifier server instance.
13
//
14
// This struct handles passing send and receive RPC messages between the client
15
// and the invoice service.
16
type htlcModifier struct {
17
        // chainParams is required to properly marshall an invoice for RPC.
18
        chainParams *chaincfg.Params
19

20
        // serverStream is a bidirectional RPC server stream to send invoices to
21
        // a client and receive accept responses from the client.
22
        serverStream Invoices_HtlcModifierServer
23
}
24

25
// newHtlcModifier creates a new RPC invoice HTLC modifier handler.
26
func newHtlcModifier(params *chaincfg.Params,
27
        serverStream Invoices_HtlcModifierServer) *htlcModifier {
×
28

×
29
        return &htlcModifier{
×
30
                chainParams:  params,
×
31
                serverStream: serverStream,
×
32
        }
×
33
}
×
34

35
// onIntercept is called when an invoice HTLC is intercepted by the invoice HTLC
36
// modifier. This method sends the invoice and the current HTLC to the client.
37
func (r *htlcModifier) onIntercept(
38
        req invoices.HtlcModifyRequest) (*invoices.HtlcModifyResponse, error) {
×
39

×
40
        // Convert the circuit key to an RPC circuit key.
×
41
        rpcCircuitKey := &CircuitKey{
×
42
                ChanId: req.ExitHtlcCircuitKey.ChanID.ToUint64(),
×
43
                HtlcId: req.ExitHtlcCircuitKey.HtlcID,
×
44
        }
×
45

×
46
        // Convert the invoice to an RPC invoice.
×
47
        rpcInvoice, err := CreateRPCInvoice(&req.Invoice, r.chainParams)
×
48
        if err != nil {
×
49
                return nil, err
×
50
        }
×
51

52
        // Send the modification request to the client.
53
        err = r.serverStream.Send(&HtlcModifyRequest{
×
54
                Invoice:                   rpcInvoice,
×
55
                ExitHtlcCircuitKey:        rpcCircuitKey,
×
56
                ExitHtlcAmt:               uint64(req.ExitHtlcAmt),
×
57
                ExitHtlcExpiry:            req.ExitHtlcExpiry,
×
58
                CurrentHeight:             req.CurrentHeight,
×
59
                ExitHtlcWireCustomRecords: req.WireCustomRecords,
×
60
        })
×
61
        if err != nil {
×
62
                return nil, err
×
63
        }
×
64

65
        // Then wait for the client to respond.
66
        resp, err := r.serverStream.Recv()
×
67
        if err != nil {
×
68
                return nil, err
×
69
        }
×
70

71
        if resp.CircuitKey == nil {
×
72
                return nil, fmt.Errorf("missing circuit key")
×
73
        }
×
74

75
        log.Tracef("Resolving invoice HTLC modifier response %v", resp)
×
76

×
77
        // Pass the resolution to the modifier.
×
78
        var amtPaid lnwire.MilliSatoshi
×
79
        if resp.AmtPaid != nil {
×
80
                amtPaid = lnwire.MilliSatoshi(*resp.AmtPaid)
×
81
        }
×
82

83
        return &invoices.HtlcModifyResponse{
×
84
                AmountPaid: amtPaid,
×
85
                CancelSet:  resp.CancelSet,
×
86
        }, nil
×
87
}
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