@@ -46,6 +46,7 @@ import (
4646 "github.com/lightningnetwork/lnd/contractcourt"
4747 "github.com/lightningnetwork/lnd/discovery"
4848 "github.com/lightningnetwork/lnd/feature"
49+ "github.com/lightningnetwork/lnd/fn"
4950 "github.com/lightningnetwork/lnd/funding"
5051 "github.com/lightningnetwork/lnd/htlcswitch"
5152 "github.com/lightningnetwork/lnd/htlcswitch/hop"
@@ -82,6 +83,7 @@ import (
8283 "google.golang.org/grpc"
8384 "google.golang.org/grpc/codes"
8485 "google.golang.org/grpc/status"
86+ "google.golang.org/protobuf/proto"
8587 "gopkg.in/macaroon-bakery.v2/bakery"
8688)
8789
@@ -567,6 +569,17 @@ func MainRPCServerPermissions() map[string][]bakery.Op {
567569 }
568570}
569571
572+ // AuxDataParser is an interface that is used to parse auxiliary custom data
573+ // within RPC messages. This is used to transform binary blobs to human-readable
574+ // JSON representations.
575+ type AuxDataParser interface {
576+ // InlineParseCustomData replaces any custom data binary blob in the
577+ // given RPC message with its corresponding JSON formatted data. This
578+ // transforms the binary (likely TLV encoded) data to a human-readable
579+ // JSON representation (still as byte slice).
580+ InlineParseCustomData (msg proto.Message ) error
581+ }
582+
570583// rpcServer is a gRPC, RPC front end to the lnd daemon.
571584// TODO(roasbeef): pagination support for the list-style calls
572585type rpcServer struct {
@@ -3544,7 +3557,7 @@ func (r *rpcServer) ChannelBalance(ctx context.Context,
35443557 unsettledRemoteBalance , pendingOpenLocalBalance ,
35453558 pendingOpenRemoteBalance )
35463559
3547- return & lnrpc.ChannelBalanceResponse {
3560+ resp := & lnrpc.ChannelBalanceResponse {
35483561 LocalBalance : & lnrpc.Amount {
35493562 Sat : uint64 (localBalance .ToSatoshis ()),
35503563 Msat : uint64 (localBalance ),
@@ -3574,7 +3587,19 @@ func (r *rpcServer) ChannelBalance(ctx context.Context,
35743587 // Deprecated fields.
35753588 Balance : int64 (localBalance .ToSatoshis ()),
35763589 PendingOpenBalance : int64 (pendingOpenLocalBalance .ToSatoshis ()),
3577- }, nil
3590+ }
3591+
3592+ err = fn .MapOptionZ (
3593+ r .server .implCfg .AuxDataParser ,
3594+ func (parser AuxDataParser ) error {
3595+ return parser .InlineParseCustomData (resp )
3596+ },
3597+ )
3598+ if err != nil {
3599+ return nil , fmt .Errorf ("error parsing custom data: %w" , err )
3600+ }
3601+
3602+ return resp , nil
35783603}
35793604
35803605type (
@@ -4330,6 +4355,16 @@ func (r *rpcServer) ListChannels(ctx context.Context,
43304355 resp .Channels = append (resp .Channels , channel )
43314356 }
43324357
4358+ err = fn .MapOptionZ (
4359+ r .server .implCfg .AuxDataParser ,
4360+ func (parser AuxDataParser ) error {
4361+ return parser .InlineParseCustomData (resp )
4362+ },
4363+ )
4364+ if err != nil {
4365+ return nil , fmt .Errorf ("error parsing custom data: %w" , err )
4366+ }
4367+
43334368 return resp , nil
43344369}
43354370
0 commit comments