feat: shed: command for decoding block headers

This commit is contained in:
Łukasz Magiera 2023-06-30 14:24:07 +02:00
parent 8577dcb475
commit 7b21420831
2 changed files with 41 additions and 0 deletions

40
cmd/lotus-shed/block.go Normal file
View File

@ -0,0 +1,40 @@
package main
import (
"bytes"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/urfave/cli/v2"
)
var blockCmd = &cli.Command{
Name: "block",
Usage: "Output decoded block header in readeble form",
ArgsUsage: "[block header hex]",
Action: func(cctx *cli.Context) error {
if cctx.NArg() != 1 {
return lcli.IncorrectNumArgs(cctx)
}
b, err := hex.DecodeString(cctx.Args().First())
if err != nil {
return err
}
var blk types.BlockHeader
if err := blk.UnmarshalCBOR(bytes.NewReader(b)); err != nil {
return err
}
jb, err := json.MarshalIndent(blk, "", " ")
if err != nil {
return err
}
fmt.Println(string(jb))
return nil
},
}

View File

@ -89,6 +89,7 @@ func main() {
indexesCmd, indexesCmd,
FevmAnalyticsCmd, FevmAnalyticsCmd,
mismatchesCmd, mismatchesCmd,
blockCmd,
} }
app := &cli.App{ app := &cli.App{