Skip to content

Commit

Permalink
move inspectDeal to cli package
Browse files Browse the repository at this point in the history
  • Loading branch information
nonsense committed Apr 1, 2021
1 parent 1626dff commit 686c719
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 82 deletions.
71 changes: 69 additions & 2 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
"github.com/filecoin-project/lotus/chain/types"
dealcli "github.com/filecoin-project/lotus/cli/deal"
"github.com/filecoin-project/lotus/lib/tablewriter"
)

Expand Down Expand Up @@ -1190,7 +1189,7 @@ var clientInspectDealCmd = &cli.Command{
defer closer()

ctx := ReqContext(cctx)
return dealcli.InspectDealCmd(ctx, api, cctx.String("proposal-cid"), cctx.Int("deal-id"))
return inspectDealCmd(ctx, api, cctx.String("proposal-cid"), cctx.Int("deal-id"))
},
}

Expand Down Expand Up @@ -2270,3 +2269,71 @@ func ellipsis(s string, length int) string {
}
return s
}

func inspectDealCmd(ctx context.Context, api lapi.FullNode, proposalCid string, dealId int) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

deals, err := api.ClientListDeals(ctx)
if err != nil {
return err
}

var di *lapi.DealInfo
for i, cdi := range deals {
if proposalCid != "" && cdi.ProposalCid.String() == proposalCid {
di = &deals[i]
break
}

if dealId != 0 && int(cdi.DealID) == dealId {
di = &deals[i]
break
}
}

if di == nil {
if proposalCid != "" {
return fmt.Errorf("cannot find deal with proposal cid: %s", proposalCid)
}
if dealId != 0 {
return fmt.Errorf("cannot find deal with deal id: %v", dealId)
}
return errors.New("you must specify proposal cid or deal id in order to inspect a deal")
}

renderDeal(di)

return nil
}

func renderDeal(di *lapi.DealInfo) {
color.Blue("Deal ID: %d\n", int(di.DealID))
color.Blue("Proposal CID: %s\n\n", di.ProposalCid.String())

if di.DealStages == nil {
color.Yellow("Deal was made with an older version of Lotus and Lotus did not collect detailed information about its stages")
return
}

for _, stg := range di.DealStages.Stages {
msg := fmt.Sprintf("%s %s: %s (%s)", color.BlueString("Stage:"), color.BlueString(strings.TrimPrefix(stg.Name, "StorageDeal")), stg.Description, color.GreenString(stg.ExpectedDuration))
if stg.UpdatedTime.Time().IsZero() {
msg = color.YellowString(msg)
}
fmt.Println(msg)

for _, l := range stg.Logs {
fmt.Printf(" %s %s\n", color.YellowString(l.UpdatedTime.Time().UTC().Round(time.Second).Format(time.Stamp)), l.Log)
}

if stg.Name == "StorageDealStartDataTransfer" {
for _, dtStg := range di.DataTransfer.Stages.Stages {
fmt.Printf(" %s %s %s\n", color.YellowString(dtStg.CreatedTime.Time().UTC().Round(time.Second).Format(time.Stamp)), color.BlueString("Data transfer stage:"), color.BlueString(dtStg.Name))
for _, l := range dtStg.Logs {
fmt.Printf(" %s %s\n", color.YellowString(l.UpdatedTime.Time().UTC().Round(time.Second).Format(time.Stamp)), l.Log)
}
}
}
}
}
80 changes: 0 additions & 80 deletions cli/deal/inspect.go

This file was deleted.

0 comments on commit 686c719

Please sign in to comment.