From c2806fe189a7d3d40004855a89036fd9b93b9595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 21 Apr 2020 17:06:54 +0200 Subject: [PATCH] cli: allow specyfying tipset by @height --- cli/state.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/cli/state.go b/cli/state.go index cabba30f1..5e3414918 100644 --- a/cli/state.go +++ b/cli/state.go @@ -115,12 +115,7 @@ var stateMinerInfo = &cli.Command{ }, } -func parseTipSetString(cctx *cli.Context) ([]cid.Cid, error) { - ts := cctx.String("tipset") - if ts == "" { - return nil, nil - } - +func parseTipSetString(ts string) ([]cid.Cid, error) { strs := strings.Split(ts, ",") var cids []cid.Cid @@ -136,7 +131,21 @@ func parseTipSetString(cctx *cli.Context) ([]cid.Cid, error) { } func LoadTipSet(ctx context.Context, cctx *cli.Context, api api.FullNode) (*types.TipSet, error) { - cids, err := parseTipSetString(cctx) + tss := cctx.String("tipset") + if tss == "" { + return nil, nil + } + + if tss[0] == '@' { + var h uint64 + if _, err := fmt.Sscanf(tss, "@%d", &h); err != nil { + return nil, xerrors.Errorf("parsing height tipset ref: %w", err) + } + + return api.ChainGetTipSetByHeight(ctx, abi.ChainEpoch(h), types.EmptyTSK) + } + + cids, err := parseTipSetString(tss) if err != nil { return nil, err }