Merge pull request #352 from filecoin-project/feat/chain-list-flags
Add height and count flags to chain list
This commit is contained in:
commit
b90274bd0c
31
cli/chain.go
31
cli/chain.go
@ -276,6 +276,10 @@ func parseTipSet(api api.FullNode, ctx context.Context, vals []string) (*types.T
|
|||||||
var chainListCmd = &cli.Command{
|
var chainListCmd = &cli.Command{
|
||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "View a segment of the chain",
|
Usage: "View a segment of the chain",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.Uint64Flag{Name: "height"},
|
||||||
|
&cli.UintFlag{Name: "count", Value: 30},
|
||||||
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
api, closer, err := GetFullNodeAPI(cctx)
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -284,25 +288,36 @@ var chainListCmd = &cli.Command{
|
|||||||
defer closer()
|
defer closer()
|
||||||
ctx := ReqContext(cctx)
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
head, err := api.ChainHead(ctx)
|
var head *types.TipSet
|
||||||
|
|
||||||
|
if cctx.IsSet("height") {
|
||||||
|
head, err = api.ChainGetTipSetByHeight(ctx, cctx.Uint64("height"), nil)
|
||||||
|
} else {
|
||||||
|
head, err = api.ChainHead(ctx)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tss := []*types.TipSet{head}
|
count := cctx.Uint("count")
|
||||||
cur := head
|
if count < 1 {
|
||||||
for i := 1; i < 30; i++ {
|
return nil
|
||||||
if cur.Height() == 0 {
|
}
|
||||||
|
|
||||||
|
tss := make([]*types.TipSet, count)
|
||||||
|
tss[0] = head
|
||||||
|
|
||||||
|
for i := 1; i < len(tss); i++ {
|
||||||
|
if head.Height() == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
next, err := api.ChainGetTipSet(ctx, cur.Parents())
|
head, err = api.ChainGetTipSet(ctx, head.Parents())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tss = append(tss, next)
|
tss[i] = head
|
||||||
cur = next
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := len(tss) - 1; i >= 0; i-- {
|
for i := len(tss) - 1; i >= 0; i-- {
|
||||||
|
Loading…
Reference in New Issue
Block a user