Skip to content

Command hex format#717

Open
Lagrang3 wants to merge 14 commits into
Blockstream:mainfrom
Lagrang3:command-hex-format
Open

Command hex format#717
Lagrang3 wants to merge 14 commits into
Blockstream:mainfrom
Lagrang3:command-hex-format

Conversation

@Lagrang3
Copy link
Copy Markdown
Collaborator

@Lagrang3 Lagrang3 commented May 15, 2026

Added json outputs to gl-cli commands.

For example:

$ glcli --json node getinfo
{
  "address": [],
  "alias": "...",
  "binding": [],
  "blockheight": 949533,
  "color": "...",
  "fees_collected_msat": 0,
  "id": "...",
  "lightning_dir": "/tmp/bitcoin",
  "network": "bitcoin",
  "num_active_channels": 0,
  "num_inactive_channels": 0,
  "num_peers": 1,
  "num_pending_channels": 0,
  "our_features": {
    "channel": "",
    "init": "0898880a8a59a1",
    "invoice": "02000002024100",
    "node": "8898880a8a59a1"
  },
  "version": "v25.12gl1"
}

I did this by hand, for every possible gRPC response that we use, which are not all of CLN's commands.
I know this is flawed, since we have no guarantee of correctedness by developer error or API changes and
as the number of gRPC commands grow this task becomes tedious.
But right now it is manageable and until we find a trick to make it automatic we can use this.

Lagrang3 added 14 commits May 15, 2026 08:42
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
and implemented the trait for GetinfoResponse
to have nice json outputs from glcli.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Sort out if we use the typical output or we print a json object.
Use a macro to avoid code repetition.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Though this implementation is trivial, notice that this command's
response is always failure when it should be success.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
@cdecker
Copy link
Copy Markdown
Collaborator

cdecker commented May 18, 2026

Very good idea, the JSON output is likely more useful than the native protobuf serialization. However, I know that there are ways to add attributes to the structs that are generated in Rust. The App team had used it a while ago to convert arbitrary messages to JSON for their own logging.

They were using the message_attribute() builder call to have the generated messages automatically be annotated with #[derive(Serialize, Deserialize)] and then did something to convert binary fields to hex, I think with a custom serializer that knew how to identify and handle the binary values. This would solve the manual maintenance you mention above and absolutely ensure that the JSON and binary representation remain in sync.

@cdecker
Copy link
Copy Markdown
Collaborator

cdecker commented May 18, 2026

Let me know if you'd like to merge this as is, so the functionality is available, or whether you want to look into a more complex, but simpler longer term, solution :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants