mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-12-06 19:03:35 +01:00
lncli: only add additional info to specific cmds.
We only append the chan_id and the human readable scid for the commands `listchannels` and `closedchannels`. This ensures that other commands like `buildroute` are not affected by this change so their output can be piped into other cmds. For some cmds it is not very practical to replace the json output because we might pipe it into other commands. For example when creating the route we want to pipe the result of buildroute into sendtoRoute.
This commit is contained in:
@@ -1254,6 +1254,7 @@ func queryRoutes(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
printRespJSON(route)
|
printRespJSON(route)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -212,6 +212,7 @@ func printJSON(resp interface{}) {
|
|||||||
_, _ = out.WriteTo(os.Stdout)
|
_, _ = out.WriteTo(os.Stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// printRespJSON prints the response in a json format.
|
||||||
func printRespJSON(resp proto.Message) {
|
func printRespJSON(resp proto.Message) {
|
||||||
jsonBytes, err := lnrpc.ProtoJSONMarshalOpts.Marshal(resp)
|
jsonBytes, err := lnrpc.ProtoJSONMarshalOpts.Marshal(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -219,6 +220,21 @@ func printRespJSON(resp proto.Message) {
|
|||||||
return
|
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.
|
// Replace custom_channel_data in the JSON.
|
||||||
jsonBytesReplaced := replaceCustomData(jsonBytes)
|
jsonBytesReplaced := replaceCustomData(jsonBytes)
|
||||||
|
|
||||||
@@ -1853,7 +1869,7 @@ func ListChannels(ctx *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
printRespJSON(resp)
|
printModifiedProtoJSON(resp)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1915,7 +1931,7 @@ func closedChannels(ctx *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
printRespJSON(resp)
|
printModifiedProtoJSON(resp)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user