From 5f091411c3a2bcd80da811645477ea20748baf71 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 28 Jul 2020 14:12:55 -0700 Subject: [PATCH] some client improvements --- cli/client.go | 62 ++++++++++++++++++++++++++++++++---------- node/impl/storminer.go | 2 +- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/cli/client.go b/cli/client.go index 90e34036d..1ac2e148a 100644 --- a/cli/client.go +++ b/cli/client.go @@ -529,8 +529,7 @@ var clientRetrieveCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 2 { - fmt.Println("Usage: retrieve [CID] [outfile]") - return nil + return ShowHelp(cctx, fmt.Errorf("incorrect number of arguments")) } fapi, closer, err := GetFullNodeAPI(cctx) @@ -732,6 +731,13 @@ var clientQueryAskCmd = &cli.Command{ var clientListDeals = &cli.Command{ Name: "list-deals", Usage: "List storage market deals", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "verbose", + Aliases: []string{"v"}, + Usage: "print verbose deal details", + }, + }, Action: func(cctx *cli.Context) error { api, closer, err := GetFullNodeAPI(cctx) if err != nil { @@ -775,20 +781,46 @@ var clientListDeals = &cli.Command{ } w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) - fmt.Fprintf(w, "DealCid\tDealId\tProvider\tState\tOn Chain?\tSlashed?\tPieceCID\tSize\tPrice\tDuration\tMessage\n") - for _, d := range deals { - onChain := "N" - if d.OnChainDealState.SectorStartEpoch != -1 { - onChain = fmt.Sprintf("Y (epoch %d)", d.OnChainDealState.SectorStartEpoch) + if cctx.Bool("verbose") { + fmt.Fprintf(w, "DealCid\tDealId\tProvider\tState\tOn Chain?\tSlashed?\tPieceCID\tSize\tPrice\tDuration\tMessage\n") + for _, d := range deals { + onChain := "N" + if d.OnChainDealState.SectorStartEpoch != -1 { + onChain = fmt.Sprintf("Y (epoch %d)", d.OnChainDealState.SectorStartEpoch) + } + + slashed := "N" + if d.OnChainDealState.SlashEpoch != -1 { + slashed = fmt.Sprintf("Y (epoch %d)", d.OnChainDealState.SlashEpoch) + } + + price := types.FIL(types.BigMul(d.LocalDeal.PricePerEpoch, types.NewInt(d.LocalDeal.Duration))) + fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%s\n", d.LocalDeal.ProposalCid, d.LocalDeal.DealID, d.LocalDeal.Provider, storagemarket.DealStates[d.LocalDeal.State], onChain, slashed, d.LocalDeal.PieceCID, types.SizeStr(types.NewInt(d.LocalDeal.Size)), price, d.LocalDeal.Duration, d.LocalDeal.Message) + } + } else { + fmt.Fprintf(w, "DealCid\tDealId\tProvider\tState\tOn Chain?\tSlashed?\tPieceCID\tSize\tPrice\tDuration\n") + + for _, d := range deals { + propcid := d.LocalDeal.ProposalCid.String() + propcid = "..." + propcid[len(propcid)-8:] + + onChain := "N" + if d.OnChainDealState.SectorStartEpoch != -1 { + onChain = fmt.Sprintf("Y (epoch %d)", d.OnChainDealState.SectorStartEpoch) + } + + slashed := "N" + if d.OnChainDealState.SlashEpoch != -1 { + slashed = fmt.Sprintf("Y (epoch %d)", d.OnChainDealState.SlashEpoch) + } + + piece := d.LocalDeal.PieceCID.String() + piece = "..." + piece[len(piece)-8:] + + price := types.FIL(types.BigMul(d.LocalDeal.PricePerEpoch, types.NewInt(d.LocalDeal.Duration))) + fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\n", propcid, d.LocalDeal.DealID, d.LocalDeal.Provider, storagemarket.DealStates[d.LocalDeal.State], onChain, slashed, piece, types.SizeStr(types.NewInt(d.LocalDeal.Size)), price, d.LocalDeal.Duration) } - slashed := "N" - if d.OnChainDealState.SlashEpoch != -1 { - slashed = fmt.Sprintf("Y (epoch %d)", d.OnChainDealState.SlashEpoch) - } - - price := types.FIL(types.BigMul(d.LocalDeal.PricePerEpoch, types.NewInt(d.LocalDeal.Duration))) - fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%s\n", d.LocalDeal.ProposalCid, d.LocalDeal.DealID, d.LocalDeal.Provider, storagemarket.DealStates[d.LocalDeal.State], onChain, slashed, d.LocalDeal.PieceCID, types.SizeStr(types.NewInt(d.LocalDeal.Size)), price, d.LocalDeal.Duration, d.LocalDeal.Message) } return w.Flush() }, @@ -841,7 +873,7 @@ var clientGetDealCmd = &cli.Command{ if err != nil { return err } - fmt.Println(b) + fmt.Println(string(b)) return nil }, } diff --git a/node/impl/storminer.go b/node/impl/storminer.go index d9cb59f6f..381fdcd5e 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -40,7 +40,7 @@ type StorageMinerAPI struct { ProofsConfig *ffiwrapper.Config SectorBlocks *sectorblocks.SectorBlocks - PieceStore piecestore.PieceStore + PieceStore dtypes.ProviderPieceStore StorageProvider storagemarket.StorageProvider Miner *storage.Miner BlockMiner *miner.Miner