2020-09-09 07:42:03 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-09-14 23:36:36 +00:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-09-09 07:42:03 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
2020-09-14 23:36:36 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2020-09-09 07:42:03 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func parseTipSet(ctx context.Context, api api.FullNode, vals []string) (*types.TipSet, error) {
|
|
|
|
var headers []*types.BlockHeader
|
|
|
|
for _, c := range vals {
|
|
|
|
blkc, err := cid.Decode(c)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
bh, err := api.ChainGetBlock(ctx, blkc)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
headers = append(headers, bh)
|
|
|
|
}
|
|
|
|
|
|
|
|
return types.NewTipSet(headers)
|
|
|
|
}
|
2020-09-14 23:36:36 +00:00
|
|
|
|
|
|
|
func EpochTime(curr, e abi.ChainEpoch) string {
|
|
|
|
switch {
|
|
|
|
case curr > e:
|
|
|
|
return fmt.Sprintf("%d (%s ago)", e, time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(curr-e)))
|
|
|
|
case curr == e:
|
|
|
|
return fmt.Sprintf("%d (now)", e)
|
|
|
|
case curr < e:
|
|
|
|
return fmt.Sprintf("%d (in %s)", e, time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(e-curr)))
|
|
|
|
}
|
|
|
|
|
|
|
|
panic("math broke")
|
|
|
|
}
|