cli: chain sethead --epoch

This commit is contained in:
Łukasz Magiera 2019-12-16 20:35:07 +01:00
parent c25f616562
commit e6e25c46ae

View File

@ -218,6 +218,10 @@ var chainSetHeadCmd = &cli.Command{
Name: "genesis",
Usage: "reset head to genesis",
},
&cli.Uint64Flag{
Name: "epoch",
Usage: "reset head to given epoch",
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
@ -227,25 +231,23 @@ var chainSetHeadCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
gen := cctx.Bool("genesis")
var ts *types.TipSet
if !cctx.Args().Present() && !gen {
return fmt.Errorf("must pass cids for tipset to set as head")
if cctx.Bool("genesis") {
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 gen {
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 ts == nil {
return fmt.Errorf("must pass cids for tipset to set as head")
}
if err := api.ChainSetHead(ctx, ts); err != nil {