feat(lotus-sim): add an info command

This commit is contained in:
Steven Allen 2021-06-07 15:05:52 -07:00
parent be9e30e39d
commit b7bfc06ebe
3 changed files with 36 additions and 0 deletions

View File

@ -16,6 +16,7 @@ var root []*cli.Command = []*cli.Command{
deleteSimCommand,
listSimCommand,
runSimCommand,
infoSimCommand,
upgradeCommand,
}

View File

@ -143,6 +143,10 @@ func (sim *Simulation) GetHead() *types.TipSet {
return sim.head
}
func (sim *Simulation) GetNetworkVersion() network.Version {
return sim.sm.GetNtwkVersion(context.TODO(), sim.head.Height())
}
func (sim *Simulation) SetHead(head *types.TipSet) error {
if err := sim.MetadataDS.Put(sim.key("head"), head.Key().Bytes()); err != nil {
return xerrors.Errorf("failed to store simulation head: %w", err)

31
cmd/lotus-sim/stat.go Normal file
View File

@ -0,0 +1,31 @@
package main
import (
"fmt"
"text/tabwriter"
"github.com/urfave/cli/v2"
)
var infoSimCommand = &cli.Command{
Name: "info",
Description: "Output information about the simulation.",
Action: func(cctx *cli.Context) error {
node, err := open(cctx)
if err != nil {
return err
}
defer node.Close()
sim, err := node.LoadSim(cctx.Context, cctx.String("simulation"))
if err != nil {
return err
}
tw := tabwriter.NewWriter(cctx.App.Writer, 8, 8, 0, ' ', 0)
fmt.Fprintln(tw, "Name:\t", sim.Name())
fmt.Fprintln(tw, "Height:\t", sim.GetHead().Height())
fmt.Fprintln(tw, "TipSet:\t", sim.GetHead())
fmt.Fprintln(tw, "Network Version:\t", sim.GetNetworkVersion())
return tw.Flush()
},
}