Merge pull request #939 from filecoin-project/feat/sethead-h
cli: chain sethead --epoch
This commit is contained in:
commit
8c741ef702
34
cli/chain.go
34
cli/chain.go
@ -218,6 +218,10 @@ var chainSetHeadCmd = &cli.Command{
|
|||||||
Name: "genesis",
|
Name: "genesis",
|
||||||
Usage: "reset head to genesis",
|
Usage: "reset head to genesis",
|
||||||
},
|
},
|
||||||
|
&cli.Uint64Flag{
|
||||||
|
Name: "epoch",
|
||||||
|
Usage: "reset head to given epoch",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
api, closer, err := GetFullNodeAPI(cctx)
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
@ -227,25 +231,23 @@ var chainSetHeadCmd = &cli.Command{
|
|||||||
defer closer()
|
defer closer()
|
||||||
ctx := ReqContext(cctx)
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
gen := cctx.Bool("genesis")
|
var ts *types.TipSet
|
||||||
|
|
||||||
if !cctx.Args().Present() && !gen {
|
if cctx.Bool("genesis") {
|
||||||
return fmt.Errorf("must pass cids for tipset to set as head")
|
ts, err = api.ChainGetGenesis(ctx)
|
||||||
|
}
|
||||||
|
if ts == nil && cctx.IsSet("epoch") {
|
||||||
|
ts, err = api.ChainGetTipSetByHeight(ctx, cctx.Uint64("epoch"), nil)
|
||||||
|
}
|
||||||
|
if ts == nil {
|
||||||
|
ts, err = parseTipSet(api, ctx, cctx.Args().Slice())
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var ts *types.TipSet
|
if ts == nil {
|
||||||
if gen {
|
return fmt.Errorf("must pass cids for tipset to set as head")
|
||||||
gents, err := api.ChainGetGenesis(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
ts = gents
|
|
||||||
} else {
|
|
||||||
parsedts, err := parseTipSet(api, ctx, cctx.Args().Slice())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
ts = parsedts
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.ChainSetHead(ctx, ts); err != nil {
|
if err := api.ChainSetHead(ctx, ts); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user