lnrpc+rpcserver: encode custom records as custom channel data

With this commit we encode the custom records as a TLV stream into the
custom channel data field of the invoice HTLC.
This allows the custom data parser to parse those records and replace it
with human-readable JSON on the RPC interface.
This commit is contained in:
Oliver Gugger committed 2024-09-19 09:21:38 +02:00
1 parent bbae7148aa
commit d37df75bc0
9 files changed
+144 -5

No files matched your search

+60 -1
View File
@@ -788,7 +788,8 @@ func (r *rpcServer) addDeps(s *server, macService *macaroons.Service,
s.sweeper, tower, s.towerClientMgr, r.cfg.net.ResolveTCPAddr,
genInvoiceFeatures, genAmpInvoiceFeatures,
s.getNodeAnnouncement, s.updateAndBrodcastSelfNode, parseAddr,
rpcsLog, s.aliasMgr, invoiceHtlcModifier,
rpcsLog, s.aliasMgr, r.implCfg.AuxDataParser,
invoiceHtlcModifier,
)
if err != nil {
return err
@@ -6117,6 +6118,19 @@ func (r *rpcServer) LookupInvoice(ctx context.Context,
return nil, err
}
// Give the aux data parser a chance to format the custom data in the
// invoice HTLCs.
err = fn.MapOptionZ(
r.server.implCfg.AuxDataParser,
func(parser AuxDataParser) error {
return parser.InlineParseCustomData(rpcInvoice)
},
)
if err != nil {
return nil, fmt.Errorf("error parsing custom data: %w",
err)
}
return rpcInvoice, nil
}
@@ -6172,6 +6186,21 @@ func (r *rpcServer) ListInvoices(ctx context.Context,
if err != nil {
return nil, err
}
// Give the aux data parser a chance to format the custom data
// in the invoice HTLCs.
err = fn.MapOptionZ(
r.server.implCfg.AuxDataParser,
func(parser AuxDataParser) error {
return parser.InlineParseCustomData(
resp.Invoices[i],
)
},
)
if err != nil {
return nil, fmt.Errorf("error parsing custom data: %w",
err)
}
}
return resp, nil
@@ -6200,6 +6229,21 @@ func (r *rpcServer) SubscribeInvoices(req *lnrpc.InvoiceSubscription,
return err
}
// Give the aux data parser a chance to format the
// custom data in the invoice HTLCs.
err = fn.MapOptionZ(
r.server.implCfg.AuxDataParser,
func(parser AuxDataParser) error {
return parser.InlineParseCustomData(
rpcInvoice,
)
},
)
if err != nil {
return fmt.Errorf("error parsing custom data: "+
"%w", err)
}
if err := updateStream.Send(rpcInvoice); err != nil {
return err
}
@@ -6212,6 +6256,21 @@ func (r *rpcServer) SubscribeInvoices(req *lnrpc.InvoiceSubscription,
return err
}
// Give the aux data parser a chance to format the
// custom data in the invoice HTLCs.
err = fn.MapOptionZ(
r.server.implCfg.AuxDataParser,
func(parser AuxDataParser) error {
return parser.InlineParseCustomData(
rpcInvoice,
)
},
)
if err != nil {
return fmt.Errorf("error parsing custom data: "+
"%w", err)
}
if err := updateStream.Send(rpcInvoice); err != nil {
return err
}