Skip to content

Commit

Permalink
Merge pull request #9493 from ziggie1984/lncli-no-replacement
Browse files Browse the repository at this point in the history
For some lncli cmds we should not replace the content with other data
  • Loading branch information
guggero authored Feb 13, 2025
2 parents 2ec9720 + 3562767 commit 319a0ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/commands/cmd_payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,7 @@ func queryRoutes(ctx *cli.Context) error {
}

printRespJSON(route)

return nil
}

Expand Down
20 changes: 18 additions & 2 deletions cmd/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,29 @@ 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 {
fmt.Println("unable to decode response: ", err)
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)

Expand Down Expand Up @@ -1853,7 +1869,7 @@ func ListChannels(ctx *cli.Context) error {
return err
}

printRespJSON(resp)
printModifiedProtoJSON(resp)

return nil
}
Expand Down Expand Up @@ -1915,7 +1931,7 @@ func closedChannels(ctx *cli.Context) error {
return err
}

printRespJSON(resp)
printModifiedProtoJSON(resp)

return nil
}
Expand Down

0 comments on commit 319a0ee

Please sign in to comment.