Skip to content

Commit 12d2ea2

Browse files
committed
cmd/rofl: Output trust-root as JSON
The `trust-root` command previously printed a Rust struct literal. Emit standard indented JSON instead so the output is easier to consume programmatically.
1 parent 753e4f8 commit 12d2ea2

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

cmd/rofl/trust_root.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package rofl
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67

78
"github.com/spf13/cobra"
@@ -12,6 +13,14 @@ import (
1213
cliConfig "github.com/oasisprotocol/cli/config"
1314
)
1415

16+
// trustRoot is the consensus trust root for a ROFL application.
17+
type trustRoot struct {
18+
Height uint64 `json:"height"`
19+
Hash string `json:"hash"`
20+
RuntimeID string `json:"runtime_id"`
21+
ChainContext string `json:"chain_context"`
22+
}
23+
1524
var trustRootCmd = &cobra.Command{
1625
Use: "trust-root",
1726
Short: "Show a recent trust root for a ROFL application",
@@ -36,13 +45,16 @@ var trustRootCmd = &cobra.Command{
3645
blk, err := conn.Consensus().Core().GetBlock(ctx, height)
3746
cobra.CheckErr(err)
3847

39-
// TODO: Support different output formats.
40-
fmt.Printf("TrustRoot {\n")
41-
fmt.Printf(" height: %d,\n", height)
42-
fmt.Printf(" hash: \"%s\".into(),\n", blk.Hash)
43-
fmt.Printf(" runtime_id: \"%s\".into(),\n", npa.ParaTime.ID)
44-
fmt.Printf(" chain_context: \"%s\".to_string(),\n", npa.Network.ChainContext)
45-
fmt.Printf("}\n")
48+
tr := trustRoot{
49+
Height: uint64(height),
50+
Hash: blk.Hash.Hex(),
51+
RuntimeID: npa.ParaTime.ID,
52+
ChainContext: npa.Network.ChainContext,
53+
}
54+
55+
out, err := json.MarshalIndent(tr, "", " ")
56+
cobra.CheckErr(err)
57+
fmt.Println(string(out))
4658
},
4759
}
4860

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
TrustRoot {
2-
height: 1022,
3-
hash: "bb3e63d729dd568ce07b37eea33eddf8082ed4cacbd64097aad32168a4a4fc9a".into(),
4-
runtime_id: "8000000000000000000000000000000000000000000000000000000000000000".into(),
5-
chain_context: "074f5ba071c4385a7ad24aea0a3a7b137901395e8f3b35479c1cce87d3170f4e".to_string(),
1+
{
2+
"height": 1022,
3+
"hash": "bb3e63d729dd568ce07b37eea33eddf8082ed4cacbd64097aad32168a4a4fc9a",
4+
"runtime_id": "8000000000000000000000000000000000000000000000000000000000000000",
5+
"chain_context": "074f5ba071c4385a7ad24aea0a3a7b137901395e8f3b35479c1cce87d3170f4e"
66
}

0 commit comments

Comments
 (0)