Merge pull request #2511 from filecoin-project/feat/retrieval-fixes

a few improvements and fixes for the retrieval CLI
This commit is contained in:
Whyrusleeping 2020-07-21 17:21:54 -07:00 committed by GitHub
commit 8c4d7b431b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 1 deletions

View File

@ -421,6 +421,7 @@ type DealInfo struct {
Message string // more information about deal state, particularly errors Message string // more information about deal state, particularly errors
Provider address.Address Provider address.Address
DataRef *storagemarket.DataRef
PieceCID cid.Cid PieceCID cid.Cid
Size uint64 Size uint64

View File

@ -1,6 +1,7 @@
package cli package cli
import ( import (
"encoding/json"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -65,6 +66,7 @@ var clientCmd = &cli.Command{
clientQueryAskCmd, clientQueryAskCmd,
clientListDeals, clientListDeals,
clientCarGenCmd, clientCarGenCmd,
clientGetDealCmd,
}, },
} }
@ -483,7 +485,7 @@ var clientFindCmd = &cli.Command{
fmt.Printf("ERR %s@%s: %s\n", offer.Miner, offer.MinerPeerID, offer.Err) fmt.Printf("ERR %s@%s: %s\n", offer.Miner, offer.MinerPeerID, offer.Err)
continue 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 return nil
@ -572,6 +574,16 @@ var clientRetrieveCmd = &cli.Command{
if minerStrAddr == "" { // Local discovery if minerStrAddr == "" { // Local discovery
offers, err := fapi.ClientFindData(ctx, file, pieceCid) 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 by price low to high
sort.Slice(offers, func(i, j int) bool { sort.Slice(offers, func(i, j int) bool {
return offers[i].MinPrice.LessThan(offers[j].MinPrice) return offers[i].MinPrice.LessThan(offers[j].MinPrice)
@ -779,3 +791,50 @@ type deal struct {
LocalDeal lapi.DealInfo LocalDeal lapi.DealInfo
OnChainDealState market.DealState 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
},
}

View File

@ -162,6 +162,7 @@ func (a *API) ClientListDeals(ctx context.Context) ([]api.DealInfo, error) {
for k, v := range deals { for k, v := range deals {
out[k] = api.DealInfo{ out[k] = api.DealInfo{
ProposalCid: v.ProposalCid, ProposalCid: v.ProposalCid,
DataRef: v.DataRef,
State: v.State, State: v.State,
Message: v.Message, Message: v.Message,
Provider: v.Proposal.Provider, Provider: v.Proposal.Provider,