feat: retrieval ask CLI command

This commit is contained in:
Dirk McCormick 2021-12-17 15:50:51 +01:00
parent a4728d3c72
commit b1734f84b3
8 changed files with 92 additions and 7 deletions

View File

@ -900,6 +900,7 @@ type QueryOffer struct {
Size uint64
MinPrice types.BigInt
UnsealPrice types.BigInt
PricePerByte abi.TokenAmount
PaymentInterval uint64
PaymentIntervalIncrease uint64
Miner address.Address

Binary file not shown.

View File

@ -92,6 +92,7 @@ var clientCmd = &cli.Command{
WithCategory("data", clientLocalCmd),
WithCategory("data", clientStat),
WithCategory("retrieval", clientFindCmd),
WithCategory("retrieval", clientQueryRetrievalAskCmd),
WithCategory("retrieval", clientRetrieveCmd),
WithCategory("retrieval", clientRetrieveCatCmd),
WithCategory("retrieval", clientRetrieveLsCmd),
@ -1030,6 +1031,63 @@ var clientFindCmd = &cli.Command{
},
}
var clientQueryRetrievalAskCmd = &cli.Command{
Name: "query-retrieval-ask",
Usage: "Get a miner's retrieval ask",
ArgsUsage: "[minerAddress] [data CID]",
Flags: []cli.Flag{
&cli.Int64Flag{
Name: "size",
Usage: "data size in bytes",
},
},
Action: func(cctx *cli.Context) error {
afmt := NewAppFmt(cctx.App)
if cctx.NArg() != 2 {
afmt.Println("Usage: query-retrieval-ask [minerAddress] [data CID]")
return nil
}
maddr, err := address.NewFromString(cctx.Args().First())
if err != nil {
return err
}
dataCid, err := cid.Parse(cctx.Args().Get(1))
if err != nil {
return fmt.Errorf("parsing data cid: %w", err)
}
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := ReqContext(cctx)
ask, err := api.ClientMinerQueryOffer(ctx, maddr, dataCid, nil)
if err != nil {
return err
}
afmt.Printf("Ask: %s\n", maddr)
afmt.Printf("Unseal price: %s\n", types.FIL(ask.UnsealPrice))
afmt.Printf("Price per byte: %s\n", types.FIL(ask.PricePerByte))
afmt.Printf("Payment interval: %s\n", types.SizeStr(types.NewInt(ask.PaymentInterval)))
afmt.Printf("Payment interval increase: %s\n", types.SizeStr(types.NewInt(ask.PaymentIntervalIncrease)))
size := cctx.Int64("size")
if size == 0 {
return nil
}
transferPrice := types.BigMul(ask.PricePerByte, types.NewInt(uint64(size)))
totalPrice := types.BigAdd(ask.UnsealPrice, transferPrice)
afmt.Printf("Total price for %d bytes: %s\n", size, types.FIL(totalPrice))
return nil
},
}
var clientListRetrievalsCmd = &cli.Command{
Name: "list-retrievals",
Usage: "List retrieval market deals",

View File

@ -1386,6 +1386,7 @@ Response:
"Size": 42,
"MinPrice": "0",
"UnsealPrice": "0",
"PricePerByte": "0",
"PaymentInterval": 42,
"PaymentIntervalIncrease": 42,
"Miner": "f01234",

View File

@ -1425,6 +1425,7 @@ Response:
"Size": 42,
"MinPrice": "0",
"UnsealPrice": "0",
"PricePerByte": "0",
"PaymentInterval": 42,
"PaymentIntervalIncrease": 42,
"Miner": "f01234",

View File

@ -424,12 +424,13 @@ COMMANDS:
local List locally imported data
stat Print information about a locally stored file (piece size, etc)
RETRIEVAL:
find Find data in the network
retrieve Retrieve data from network
cat Show data from network
ls List object links
cancel-retrieval Cancel a retrieval deal by deal ID; this also cancels the associated transfer
list-retrievals List retrieval market deals
find Find data in the network
query-retrieval-ask Get a miner's retrieval ask
retrieve Retrieve data from network
cat Show data from network
ls List object links
cancel-retrieval Cancel a retrieval deal by deal ID; this also cancels the associated transfer
list-retrievals List retrieval market deals
STORAGE:
deal Initialize storage deal with a miner
query-ask Find a miners ask
@ -535,6 +536,23 @@ OPTIONS:
```
### lotus client query-retrieval-ask
```
NAME:
lotus client query-retrieval-ask - Get a miner's retrieval ask
USAGE:
lotus client query-retrieval-ask [command options] [minerAddress] [data CID]
CATEGORY:
RETRIEVAL
OPTIONS:
--size value data size in bytes (default: 0)
--help, -h show help (default: false)
```
### lotus client retrieve
```
NAME:

View File

@ -101,9 +101,14 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode *TestFullNode)
time.Sleep(time.Second)
}
// client query-retrieval-ask --size=1 <miner addr> <data CID>
out = clientCLI.RunCmd("client", "query-retrieval-ask", "--size=1", minerAddr.String(), dataCid.String())
require.Regexp(t, regexp.MustCompile("Ask:"), out)
fmt.Println("retrieval ask:\n", out)
// Retrieve the first file from the Miner
// client retrieve <cid> <file path>
tmpdir, err := ioutil.TempDir(os.TempDir(), "test-cli-Client")
tmpdir, err := ioutil.TempDir(os.TempDir(), "test-cli-client")
require.NoError(t, err)
path := filepath.Join(tmpdir, "outfile.dat")
out = clientCLI.RunCmd("client", "retrieve", dataCid.String(), path)

View File

@ -490,6 +490,7 @@ func (a *API) makeRetrievalQuery(ctx context.Context, rp rm.RetrievalPeer, paylo
Size: queryResponse.Size,
MinPrice: queryResponse.PieceRetrievalPrice(),
UnsealPrice: queryResponse.UnsealPrice,
PricePerByte: queryResponse.MinPricePerByte,
PaymentInterval: queryResponse.MaxPaymentInterval,
PaymentIntervalIncrease: queryResponse.MaxPaymentIntervalIncrease,
Miner: queryResponse.PaymentAddress, // TODO: check