Merge pull request #11031 from filecoin-project/feat/shed-block-json
feat: shed: command for decoding block headers
This commit is contained in:
commit
537d31416e
42
cmd/lotus-shed/block.go
Normal file
42
cmd/lotus-shed/block.go
Normal file
@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
lcli "github.com/filecoin-project/lotus/cli"
|
||||
)
|
||||
|
||||
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
|
||||
},
|
||||
}
|
@ -89,6 +89,7 @@ func main() {
|
||||
indexesCmd,
|
||||
FevmAnalyticsCmd,
|
||||
mismatchesCmd,
|
||||
blockCmd,
|
||||
}
|
||||
|
||||
app := &cli.App{
|
||||
|
Loading…
Reference in New Issue
Block a user