2019-07-12 10:17:16 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-08-02 14:09:54 +00:00
|
|
|
"strconv"
|
2019-07-16 16:07:08 +00:00
|
|
|
|
2019-08-02 14:09:54 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
"golang.org/x/xerrors"
|
2019-07-12 10:17:16 +00:00
|
|
|
"gopkg.in/urfave/cli.v2"
|
2019-08-02 14:09:54 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/go-lotus/chain/address"
|
2019-07-12 10:17:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var clientCmd = &cli.Command{
|
|
|
|
Name: "client",
|
|
|
|
Usage: "Make deals, store data, retrieve data",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
clientImportCmd,
|
2019-07-12 10:44:01 +00:00
|
|
|
clientLocalCmd,
|
2019-08-02 14:09:54 +00:00
|
|
|
clientDealCmd,
|
2019-07-12 10:17:16 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var clientImportCmd = &cli.Command{
|
2019-07-12 10:44:01 +00:00
|
|
|
Name: "import",
|
|
|
|
Usage: "Import data",
|
2019-07-12 10:17:16 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2019-07-18 23:16:23 +00:00
|
|
|
api, err := GetAPI(cctx)
|
2019-07-12 10:17:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-07-18 23:16:23 +00:00
|
|
|
ctx := ReqContext(cctx)
|
2019-07-12 10:17:16 +00:00
|
|
|
|
|
|
|
c, err := api.ClientImport(ctx, cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println(c.String())
|
|
|
|
return nil
|
|
|
|
},
|
2019-07-12 10:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var clientLocalCmd = &cli.Command{
|
|
|
|
Name: "local",
|
|
|
|
Usage: "List locally imported data",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2019-07-18 23:16:23 +00:00
|
|
|
api, err := GetAPI(cctx)
|
2019-07-12 10:44:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-07-18 23:16:23 +00:00
|
|
|
ctx := ReqContext(cctx)
|
2019-07-12 10:44:01 +00:00
|
|
|
|
|
|
|
list, err := api.ClientListImports(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, v := range list {
|
|
|
|
fmt.Printf("%s %s %d %s\n", v.Key, v.FilePath, v.Size, v.Status)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2019-08-02 14:09:54 +00:00
|
|
|
|
|
|
|
var clientDealCmd = &cli.Command{
|
|
|
|
Name: "deal",
|
|
|
|
Usage: "Initialize storage deal with a miner",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, err := GetAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
|
|
|
if cctx.NArg() != 3 {
|
|
|
|
return xerrors.New("expected 3 args: dataCid, miner, duration")
|
|
|
|
}
|
|
|
|
|
|
|
|
// [data, miner, dur]
|
|
|
|
|
|
|
|
data, err := cid.Parse(cctx.Args().Get(0))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
miner, err := address.NewFromString(cctx.Args().Get(1))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
dur, err := strconv.ParseInt(cctx.Args().Get(2), 10, 32)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return api.ClientStartDeal(ctx, data, miner, uint64(dur))
|
|
|
|
},
|
|
|
|
}
|