move inspectDeal to cli package
This commit is contained in:
parent
1626dffd4c
commit
686c719bb1
@ -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"
|
||||
)
|
||||
|
||||
@ -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"))
|
||||
},
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,80 +0,0 @@
|
||||
package deal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
lapi "github.com/filecoin-project/lotus/api"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user