diff --git a/cmd/commands/cmd_payments.go b/cmd/commands/cmd_payments.go index 2fdf97cba..8b93f9458 100644 --- a/cmd/commands/cmd_payments.go +++ b/cmd/commands/cmd_payments.go @@ -1254,6 +1254,7 @@ func queryRoutes(ctx *cli.Context) error { } printRespJSON(route) + return nil } diff --git a/cmd/commands/commands.go b/cmd/commands/commands.go index 60579a70a..cfeaeabac 100644 --- a/cmd/commands/commands.go +++ b/cmd/commands/commands.go @@ -212,6 +212,7 @@ func printJSON(resp interface{}) { _, _ = out.WriteTo(os.Stdout) } +// printRespJSON prints the response in a json format. func printRespJSON(resp proto.Message) { jsonBytes, err := lnrpc.ProtoJSONMarshalOpts.Marshal(resp) if err != nil { @@ -219,6 +220,21 @@ func printRespJSON(resp proto.Message) { return } + // Make the custom data human readable. + jsonBytesReplaced := replaceCustomData(jsonBytes) + + fmt.Printf("%s\n", jsonBytesReplaced) +} + +// printModifiedProtoJSON prints the response with some additional formatting +// and replacements. +func printModifiedProtoJSON(resp proto.Message) { + jsonBytes, err := lnrpc.ProtoJSONMarshalOpts.Marshal(resp) + if err != nil { + fmt.Println("unable to decode response: ", err) + return + } + // Replace custom_channel_data in the JSON. jsonBytesReplaced := replaceCustomData(jsonBytes) @@ -1853,7 +1869,7 @@ func ListChannels(ctx *cli.Context) error { return err } - printRespJSON(resp) + printModifiedProtoJSON(resp) return nil } @@ -1915,7 +1931,7 @@ func closedChannels(ctx *cli.Context) error { return err } - printRespJSON(resp) + printModifiedProtoJSON(resp) return nil }