2020-09-09 07:42:03 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-02-22 18:37:47 +00:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2021-07-13 10:19:55 +00:00
|
|
|
"os"
|
2020-09-14 23:36:36 +00:00
|
|
|
|
2021-07-13 10:19:55 +00:00
|
|
|
"github.com/fatih/color"
|
2020-09-14 23:36:36 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2021-07-13 10:19:55 +00:00
|
|
|
"github.com/mattn/go-isatty"
|
2020-09-14 23:36:36 +00:00
|
|
|
|
2021-04-03 10:55:29 +00:00
|
|
|
"github.com/filecoin-project/lotus/api/v0api"
|
2020-09-09 07:42:03 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
2021-07-13 10:19:55 +00:00
|
|
|
// Set the global default, to be overridden by individual cli flags in order
|
|
|
|
func init() {
|
|
|
|
color.NoColor = os.Getenv("GOLOG_LOG_FMT") != "color" &&
|
|
|
|
!isatty.IsTerminal(os.Stdout.Fd()) &&
|
|
|
|
!isatty.IsCygwinTerminal(os.Stdout.Fd())
|
|
|
|
}
|
|
|
|
|
2021-04-03 10:55:29 +00:00
|
|
|
func parseTipSet(ctx context.Context, api v0api.FullNode, vals []string) (*types.TipSet, error) {
|
2020-09-09 07:42:03 +00:00
|
|
|
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)
|
|
|
|
}
|
2024-02-22 18:37:47 +00:00
|
|
|
|
|
|
|
func PrintJson(obj interface{}) error {
|
|
|
|
resJson, err := json.MarshalIndent(obj, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("marshalling json: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(string(resJson))
|
|
|
|
return nil
|
|
|
|
}
|