Add default max price, fix error messaging

This commit is contained in:
Ingar Shu 2020-07-10 10:04:41 -07:00
parent 5411ebb806
commit 7929a335c3
No known key found for this signature in database
GPG Key ID: BE3D9CE79F22E769

View File

@ -485,6 +485,8 @@ var clientFindCmd = &cli.Command{
}, },
} }
const DefaultMaxRetrievePrice = 1
var clientRetrieveCmd = &cli.Command{ var clientRetrieveCmd = &cli.Command{
Name: "retrieve", Name: "retrieve",
Usage: "retrieve data from network", Usage: "retrieve data from network",
@ -504,7 +506,7 @@ var clientRetrieveCmd = &cli.Command{
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "maxPrice", Name: "maxPrice",
Usage: "maximum price the client is willing to consider", Usage: fmt.Sprintf("maximum price the client is willing to consider (default: %d FIL)", DefaultMaxRetrievePrice),
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "pieceCid", Name: "pieceCid",
@ -593,15 +595,19 @@ var clientRetrieveCmd = &cli.Command{
return fmt.Errorf("The received offer errored: %s", offer.Err) return fmt.Errorf("The received offer errored: %s", offer.Err)
} }
maxPrice := types.NewInt(DefaultMaxRetrievePrice)
if cctx.String("maxPrice") != "" { if cctx.String("maxPrice") != "" {
maxPrice, err := types.ParseFIL(cctx.String("maxPrice")) maxPriceFil, err := types.ParseFIL(cctx.String("maxPrice"))
if err != nil { if err != nil {
return err return xerrors.Errorf("parsing maxPrice: %w", err)
} }
if offer.MinPrice.GreaterThan(types.BigInt(maxPrice)) { maxPrice = types.BigInt(maxPriceFil)
return xerrors.Errorf("Failed to find offer satisfying maxPrice: %w", maxPrice)
} }
if offer.MinPrice.GreaterThan(maxPrice) {
return xerrors.Errorf("failed to find offer satisfying maxPrice: %s", maxPrice)
} }
ref := &lapi.FileRef{ ref := &lapi.FileRef{