From 7b214208310172eeb7828b6b8aade9d7605d6657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 30 Jun 2023 14:24:07 +0200 Subject: [PATCH 1/2] feat: shed: command for decoding block headers --- cmd/lotus-shed/block.go | 40 ++++++++++++++++++++++++++++++++++++++++ cmd/lotus-shed/main.go | 1 + 2 files changed, 41 insertions(+) create mode 100644 cmd/lotus-shed/block.go diff --git a/cmd/lotus-shed/block.go b/cmd/lotus-shed/block.go new file mode 100644 index 000000000..353d0daaf --- /dev/null +++ b/cmd/lotus-shed/block.go @@ -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 + }, +} diff --git a/cmd/lotus-shed/main.go b/cmd/lotus-shed/main.go index 13ab6af0d..7355dad25 100644 --- a/cmd/lotus-shed/main.go +++ b/cmd/lotus-shed/main.go @@ -89,6 +89,7 @@ func main() { indexesCmd, FevmAnalyticsCmd, mismatchesCmd, + blockCmd, } app := &cli.App{ From e30f8af2d1aeab2257c9614511dcd0799dc0415d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 6 Jul 2023 09:35:10 +0200 Subject: [PATCH 2/2] make gen --- cmd/lotus-shed/block.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/lotus-shed/block.go b/cmd/lotus-shed/block.go index 353d0daaf..814eef3fd 100644 --- a/cmd/lotus-shed/block.go +++ b/cmd/lotus-shed/block.go @@ -5,9 +5,11 @@ import ( "encoding/hex" "encoding/json" "fmt" + + "github.com/urfave/cli/v2" + "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" - "github.com/urfave/cli/v2" ) var blockCmd = &cli.Command{