From 8774a7b2dd67157cdf4947c7c414f250fbed59c2 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Fri, 14 Aug 2020 11:22:54 -0700 Subject: [PATCH] add a market balance command, and a verbose mode for storage-deals list --- cli/state.go | 44 +++++++++++++++++++++++++++++++ cmd/lotus-storage-miner/market.go | 25 +++++++++++++++--- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/cli/state.go b/cli/state.go index 0354131f9..926eca71f 100644 --- a/cli/state.go +++ b/cli/state.go @@ -67,6 +67,7 @@ var stateCmd = &cli.Command{ stateWaitMsgCmd, stateSearchMsgCmd, stateMinerInfo, + stateMarketCmd, }, } @@ -1524,3 +1525,46 @@ var stateCircSupplyCmd = &cli.Command{ return nil }, } + +var stateMarketCmd = &cli.Command{ + Name: "market", + Usage: "Inspect the storage market actor", + Subcommands: []*cli.Command{ + stateMarketBalanceCmd, + }, +} + +var stateMarketBalanceCmd = &cli.Command{ + Name: "balance", + Usage: "Get the market balance (locked and escrowed) for a given account", + Action: func(cctx *cli.Context) error { + if !cctx.Args().Present() { + return ShowHelp(cctx, fmt.Errorf("must specify address to print market balance for")) + } + + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + + ctx := ReqContext(cctx) + + ts, err := LoadTipSet(ctx, cctx, api) + if err != nil { + return err + } + + addr, err := address.NewFromString(cctx.Args().First()) + if err != nil { + return err + } + + balance, err := api.StateMarketBalance(ctx, addr, ts.Key()) + + fmt.Printf("Escrow: %s\n", types.FIL(balance.Escrow)) + fmt.Printf("Locked: %s\n", types.FIL(balance.Locked)) + + return nil + }, +} diff --git a/cmd/lotus-storage-miner/market.go b/cmd/lotus-storage-miner/market.go index f2b3fde89..364db2693 100644 --- a/cmd/lotus-storage-miner/market.go +++ b/cmd/lotus-storage-miner/market.go @@ -338,6 +338,12 @@ var dealsImportDataCmd = &cli.Command{ var dealsListCmd = &cli.Command{ Name: "list", Usage: "List all deals for this miner", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "verbose", + Aliases: []string{"v"}, + }, + }, Action: func(cctx *cli.Context) error { api, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { @@ -354,15 +360,28 @@ var dealsListCmd = &cli.Command{ w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) - _, _ = fmt.Fprintf(w, "ProposalCid\tDealId\tState\tClient\tSize\tPrice\tDuration\n") + verbose := cctx.Bool("verbose") + + if verbose { + _, _ = fmt.Fprintf(w, "ProposalCid\tDealId\tState\tClient\tSize\tPrice\tDuration\tMessage\n") + } else { + _, _ = fmt.Fprintf(w, "ProposalCid\tDealId\tState\tClient\tSize\tPrice\tDuration\n") + } for _, deal := range deals { propcid := deal.ProposalCid.String() - propcid = "..." + propcid[len(propcid)-8:] + if !verbose { + propcid = "..." + propcid[len(propcid)-8:] + } fil := types.FIL(types.BigMul(deal.Proposal.StoragePricePerEpoch, types.NewInt(uint64(deal.Proposal.Duration())))) - _, _ = fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\t%s\t%s\n", propcid, deal.DealID, storagemarket.DealStates[deal.State], deal.Proposal.Client, units.BytesSize(float64(deal.Proposal.PieceSize)), fil, deal.Proposal.Duration()) + _, _ = fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\t%s\t%s", propcid, deal.DealID, storagemarket.DealStates[deal.State], deal.Proposal.Client, units.BytesSize(float64(deal.Proposal.PieceSize)), fil, deal.Proposal.Duration()) + if verbose { + _, _ = fmt.Fprintf(w, "\t%s", deal.Message) + } + + _, _ = fmt.Fprintln(w) } return w.Flush()