From 6a0add975a8bce9ef48430caf0f2e77ff4f7d067 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 6 Nov 2024 11:23:50 +0700 Subject: [PATCH] Add ptCid command Signed-off-by: Jakub Sztandera --- cmd/f3/main.go | 1 + cmd/f3/tools.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 cmd/f3/tools.go diff --git a/cmd/f3/main.go b/cmd/f3/main.go index cdd5ce39..932b4e8f 100644 --- a/cmd/f3/main.go +++ b/cmd/f3/main.go @@ -25,6 +25,7 @@ func main() { &runCmd, &manifestCmd, &observerCmd, + &toolsCmd, }, } diff --git a/cmd/f3/tools.go b/cmd/f3/tools.go new file mode 100644 index 00000000..81d014ec --- /dev/null +++ b/cmd/f3/tools.go @@ -0,0 +1,39 @@ +package main + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/filecoin-project/go-f3/certs" + "github.com/filecoin-project/go-f3/gpbft" + "github.com/urfave/cli/v2" +) + +var toolsCmd = cli.Command{ + Name: "tools", + Usage: "various tools for f3", + Subcommands: []*cli.Command{ + &ptCidCmd, + }, +} + +var ptCidCmd = cli.Command{ + Name: "ptCid", + Usage: "compute the CID of a json power table", + Action: func(c *cli.Context) error { + var entries gpbft.PowerEntries + err := json.NewDecoder(os.Stdin).Decode(&entries) + if err != nil { + return fmt.Errorf("error while decoding: %w", err) + } + + cid, err := certs.MakePowerTableCID(entries) + if err != nil { + return fmt.Errorf("error while computing CID: %w", err) + } + + fmt.Printf("%s\n", cid) + return nil + }, +}