diff --git a/api/api_full.go b/api/api_full.go index 4200755af..081fce0d3 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -421,6 +421,7 @@ type DealInfo struct { Message string // more information about deal state, particularly errors Provider address.Address + DataRef *storagemarket.DataRef PieceCID cid.Cid Size uint64 diff --git a/cli/client.go b/cli/client.go index 3a1518b4f..2125f524a 100644 --- a/cli/client.go +++ b/cli/client.go @@ -1,6 +1,7 @@ package cli import ( + "encoding/json" "fmt" "os" "path/filepath" @@ -65,6 +66,7 @@ var clientCmd = &cli.Command{ clientQueryAskCmd, clientListDeals, clientCarGenCmd, + clientGetDealCmd, }, } @@ -483,7 +485,7 @@ var clientFindCmd = &cli.Command{ fmt.Printf("ERR %s@%s: %s\n", offer.Miner, offer.MinerPeerID, offer.Err) continue } - fmt.Printf("RETRIEVAL %s@%s-%sfil-%s\n", offer.Miner, offer.MinerPeerID, types.FIL(offer.MinPrice), types.SizeStr(types.NewInt(offer.Size))) + fmt.Printf("RETRIEVAL %s@%s-%s-%s\n", offer.Miner, offer.MinerPeerID, types.FIL(offer.MinPrice), types.SizeStr(types.NewInt(offer.Size))) } return nil @@ -572,6 +574,16 @@ var clientRetrieveCmd = &cli.Command{ if minerStrAddr == "" { // Local discovery offers, err := fapi.ClientFindData(ctx, file, pieceCid) + var cleaned []api.QueryOffer + // filter out offers that errored + for _, o := range offers { + if o.Err != "" { + cleaned = append(cleaned, o) + } + } + + offers = cleaned + // sort by price low to high sort.Slice(offers, func(i, j int) bool { return offers[i].MinPrice.LessThan(offers[j].MinPrice) @@ -779,3 +791,50 @@ type deal struct { LocalDeal lapi.DealInfo OnChainDealState market.DealState } + +var clientGetDealCmd = &cli.Command{ + Name: "get-deal", + Usage: "Print detailed deal information", + Action: func(cctx *cli.Context) error { + if !cctx.Args().Present() { + return cli.ShowCommandHelp(cctx, cctx.Command.Name) + } + + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := ReqContext(cctx) + + propcid, err := cid.Decode(cctx.Args().First()) + if err != nil { + return err + } + + di, err := api.ClientGetDealInfo(ctx, propcid) + if err != nil { + return err + } + + out := map[string]interface{}{ + "DealInfo: ": di, + } + + if di.DealID != 0 { + onChain, err := api.StateMarketStorageDeal(ctx, di.DealID, types.EmptyTSK) + if err != nil { + return err + } + + out["OnChain"] = onChain + } + + b, err := json.MarshalIndent(out, "", " ") + if err != nil { + return err + } + fmt.Println(b) + return nil + }, +} diff --git a/node/impl/client/client.go b/node/impl/client/client.go index 16024a0da..e3eefd3f9 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -162,6 +162,7 @@ func (a *API) ClientListDeals(ctx context.Context) ([]api.DealInfo, error) { for k, v := range deals { out[k] = api.DealInfo{ ProposalCid: v.ProposalCid, + DataRef: v.DataRef, State: v.State, Message: v.Message, Provider: v.Proposal.Provider,