Skip to content

Commit 3af226d

Browse files
authored
Add ptCid command (#733)
Signed-off-by: Jakub Sztandera <[email protected]>
1 parent 46112c2 commit 3af226d

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

cmd/f3/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func main() {
2525
&runCmd,
2626
&manifestCmd,
2727
&observerCmd,
28+
&toolsCmd,
2829
},
2930
}
3031

cmd/f3/tools.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os"
7+
8+
"github.com/filecoin-project/go-f3/certs"
9+
"github.com/filecoin-project/go-f3/gpbft"
10+
"github.com/urfave/cli/v2"
11+
)
12+
13+
var toolsCmd = cli.Command{
14+
Name: "tools",
15+
Usage: "various tools for f3",
16+
Subcommands: []*cli.Command{
17+
&ptCidCmd,
18+
},
19+
}
20+
21+
var ptCidCmd = cli.Command{
22+
Name: "ptCid",
23+
Usage: "compute the CID of a json power table",
24+
Action: func(c *cli.Context) error {
25+
var entries gpbft.PowerEntries
26+
err := json.NewDecoder(os.Stdin).Decode(&entries)
27+
if err != nil {
28+
return fmt.Errorf("error while decoding: %w", err)
29+
}
30+
31+
cid, err := certs.MakePowerTableCID(entries)
32+
if err != nil {
33+
return fmt.Errorf("error while computing CID: %w", err)
34+
}
35+
36+
fmt.Printf("%s\n", cid)
37+
return nil
38+
},
39+
}

0 commit comments

Comments
 (0)