Skip to content

Commit

Permalink
Add ptCid command (#733)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Kubuxu authored Nov 6, 2024
1 parent 46112c2 commit 3af226d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/f3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func main() {
&runCmd,
&manifestCmd,
&observerCmd,
&toolsCmd,
},
}

Expand Down
39 changes: 39 additions & 0 deletions cmd/f3/tools.go
Original file line number Diff line number Diff line change
@@ -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
},
}

0 comments on commit 3af226d

Please sign in to comment.