-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
chain.go
49 lines (40 loc) · 843 Bytes
/
chain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/urfave/cli/v2"
)
var chainCmd = &cli.Command{
Name: "chain",
Usage: "chain-related utilities",
Subcommands: []*cli.Command{
chainNullTsCmd,
},
}
var chainNullTsCmd = &cli.Command{
Name: "latest-null",
Usage: "finds the most recent null tipset",
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := lcli.ReqContext(cctx)
ts, err := lcli.LoadTipSet(ctx, cctx, api)
if err != nil {
return err
}
for {
pts, err := api.ChainGetTipSet(ctx, ts.Parents())
if err != nil {
return err
}
if ts.Height() != pts.Height()+1 {
fmt.Println("null tipset at height ", ts.Height()-1)
return nil
}
ts = pts
}
},
}