retrieval: Optional address in cli
This commit is contained in:
parent
f8a2ecaf52
commit
3f32b75b74
@ -2,6 +2,7 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/filecoin-project/go-lotus/api"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
@ -165,28 +166,39 @@ var clientFindCmd = &cli.Command{
|
|||||||
var clientRetrieveCmd = &cli.Command{
|
var clientRetrieveCmd = &cli.Command{
|
||||||
Name: "retrieve",
|
Name: "retrieve",
|
||||||
Usage: "retrieve data from network",
|
Usage: "retrieve data from network",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "address",
|
||||||
|
Usage: "address to use for transactions",
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
if cctx.NArg() != 3 {
|
if cctx.NArg() != 2 {
|
||||||
fmt.Println("Usage: retrieve [client address] [CID] [outfile]")
|
fmt.Println("Usage: retrieve [CID] [outfile]")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
payer, err := address.NewFromString(cctx.Args().Get(0))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
file, err := cid.Parse(cctx.Args().Get(1))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
api, err := GetFullNodeAPI(cctx)
|
api, err := GetFullNodeAPI(cctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ctx := ReqContext(cctx)
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
|
var payer address.Address
|
||||||
|
if cctx.String("address") != "" {
|
||||||
|
payer, err = address.NewFromString(cctx.String("address"))
|
||||||
|
} else {
|
||||||
|
payer, err = api.WalletDefaultAddress(ctx)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := cid.Parse(cctx.Args().Get(0))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Check if we already have this data locally
|
// Check if we already have this data locally
|
||||||
|
|
||||||
/*has, err := api.ClientHasLocal(ctx, file)
|
/*has, err := api.ClientHasLocal(ctx, file)
|
||||||
@ -209,7 +221,7 @@ var clientRetrieveCmd = &cli.Command{
|
|||||||
order := offers[0].Order()
|
order := offers[0].Order()
|
||||||
order.Client = payer
|
order.Client = payer
|
||||||
|
|
||||||
err = api.ClientRetrieve(ctx, order, cctx.Args().Get(2))
|
err = api.ClientRetrieve(ctx, order, cctx.Args().Get(1))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fmt.Println("Success")
|
fmt.Println("Success")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user