@@ -87,6 +87,7 @@ import (
87
87
"google.golang.org/grpc"
88
88
"google.golang.org/grpc/codes"
89
89
"google.golang.org/grpc/status"
90
+ "google.golang.org/protobuf/proto"
90
91
"gopkg.in/macaroon-bakery.v2/bakery"
91
92
)
92
93
@@ -579,6 +580,17 @@ func MainRPCServerPermissions() map[string][]bakery.Op {
579
580
}
580
581
}
581
582
583
+ // AuxDataParser is an interface that is used to parse auxiliary custom data
584
+ // within RPC messages. This is used to transform binary blobs to human-readable
585
+ // JSON representations.
586
+ type AuxDataParser interface {
587
+ // InlineParseCustomData replaces any custom data binary blob in the
588
+ // given RPC message with its corresponding JSON formatted data. This
589
+ // transforms the binary (likely TLV encoded) data to a human-readable
590
+ // JSON representation (still as byte slice).
591
+ InlineParseCustomData (msg proto.Message ) error
592
+ }
593
+
582
594
// rpcServer is a gRPC, RPC front end to the lnd daemon.
583
595
// TODO(roasbeef): pagination support for the list-style calls
584
596
type rpcServer struct {
@@ -731,6 +743,20 @@ func (r *rpcServer) addDeps(s *server, macService *macaroons.Service,
731
743
},
732
744
SetChannelAuto : s .chanStatusMgr .RequestAuto ,
733
745
UseStatusInitiated : subServerCgs .RouterRPC .UseStatusInitiated ,
746
+ ParseCustomChannelData : func (msg proto.Message ) error {
747
+ err = fn .MapOptionZ (
748
+ r .server .implCfg .AuxDataParser ,
749
+ func (parser AuxDataParser ) error {
750
+ return parser .InlineParseCustomData (msg )
751
+ },
752
+ )
753
+ if err != nil {
754
+ return fmt .Errorf ("error parsing custom data: " +
755
+ "%w" , err )
756
+ }
757
+
758
+ return nil
759
+ },
734
760
}
735
761
736
762
genInvoiceFeatures := func () * lnwire.FeatureVector {
@@ -3596,7 +3622,7 @@ func (r *rpcServer) ChannelBalance(ctx context.Context,
3596
3622
unsettledRemoteBalance , pendingOpenLocalBalance ,
3597
3623
pendingOpenRemoteBalance )
3598
3624
3599
- return & lnrpc.ChannelBalanceResponse {
3625
+ resp := & lnrpc.ChannelBalanceResponse {
3600
3626
LocalBalance : & lnrpc.Amount {
3601
3627
Sat : uint64 (localBalance .ToSatoshis ()),
3602
3628
Msat : uint64 (localBalance ),
@@ -3626,7 +3652,19 @@ func (r *rpcServer) ChannelBalance(ctx context.Context,
3626
3652
// Deprecated fields.
3627
3653
Balance : int64 (localBalance .ToSatoshis ()),
3628
3654
PendingOpenBalance : int64 (pendingOpenLocalBalance .ToSatoshis ()),
3629
- }, nil
3655
+ }
3656
+
3657
+ err = fn .MapOptionZ (
3658
+ r .server .implCfg .AuxDataParser ,
3659
+ func (parser AuxDataParser ) error {
3660
+ return parser .InlineParseCustomData (resp )
3661
+ },
3662
+ )
3663
+ if err != nil {
3664
+ return nil , fmt .Errorf ("error parsing custom data: %w" , err )
3665
+ }
3666
+
3667
+ return resp , nil
3630
3668
}
3631
3669
3632
3670
type (
@@ -4068,6 +4106,16 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
4068
4106
resp .WaitingCloseChannels = waitingCloseChannels
4069
4107
resp .TotalLimboBalance += limbo
4070
4108
4109
+ err = fn .MapOptionZ (
4110
+ r .server .implCfg .AuxDataParser ,
4111
+ func (parser AuxDataParser ) error {
4112
+ return parser .InlineParseCustomData (resp )
4113
+ },
4114
+ )
4115
+ if err != nil {
4116
+ return nil , fmt .Errorf ("error parsing custom data: %w" , err )
4117
+ }
4118
+
4071
4119
return resp , nil
4072
4120
}
4073
4121
@@ -4382,6 +4430,16 @@ func (r *rpcServer) ListChannels(ctx context.Context,
4382
4430
resp .Channels = append (resp .Channels , channel )
4383
4431
}
4384
4432
4433
+ err = fn .MapOptionZ (
4434
+ r .server .implCfg .AuxDataParser ,
4435
+ func (parser AuxDataParser ) error {
4436
+ return parser .InlineParseCustomData (resp )
4437
+ },
4438
+ )
4439
+ if err != nil {
4440
+ return nil , fmt .Errorf ("error parsing custom data: %w" , err )
4441
+ }
4442
+
4385
4443
return resp , nil
4386
4444
}
4387
4445
0 commit comments