diff --git a/cmd/lotus-shed/import-car.go b/cmd/lotus-shed/import-car.go index 01343c4a36..9cbff953b1 100644 --- a/cmd/lotus-shed/import-car.go +++ b/cmd/lotus-shed/import-car.go @@ -1,10 +1,13 @@ package main import ( + "encoding/hex" "fmt" "io" "os" + block "github.com/ipfs/go-block-format" + "github.com/ipfs/go-cid" "github.com/ipld/go-car" "github.com/urfave/cli/v2" "golang.org/x/xerrors" @@ -81,3 +84,57 @@ var importCarCmd = &cli.Command{ } }, } + +var importObjectCmd = &cli.Command{ + Name: "import-obj", + Usage: "import a raw ipld object into your datastore", + Action: func(cctx *cli.Context) error { + r, err := repo.NewFS(cctx.String("repo")) + if err != nil { + return xerrors.Errorf("opening fs repo: %w", err) + } + + exists, err := r.Exists() + if err != nil { + return err + } + if !exists { + return xerrors.Errorf("lotus repo doesn't exist") + } + + lr, err := r.Lock(repo.FullNode) + if err != nil { + return err + } + defer lr.Close() //nolint:errcheck + + ds, err := lr.Datastore("/chain") + if err != nil { + return err + } + + bs := blockstore.NewBlockstore(ds) + + c, err := cid.Decode(cctx.Args().Get(0)) + if err != nil { + return err + } + + data, err := hex.DecodeString(cctx.Args().Get(1)) + if err != nil { + return err + } + + blk, err := block.NewBlockWithCid(data, c) + if err != nil { + return err + } + + if err := bs.Put(blk); err != nil { + return err + } + + return nil + + }, +} diff --git a/cmd/lotus-shed/main.go b/cmd/lotus-shed/main.go index 5438a31ef6..11b98a3ac6 100644 --- a/cmd/lotus-shed/main.go +++ b/cmd/lotus-shed/main.go @@ -24,6 +24,7 @@ func main() { bigIntParseCmd, staterootCmd, importCarCmd, + importObjectCmd, commpToCidCmd, fetchParamCmd, proofsCmd,