2020-02-08 00:18:14 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-03-04 02:49:00 +00:00
|
|
|
"encoding/json"
|
2020-02-08 00:18:14 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
2020-03-04 02:49:00 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2020-02-08 00:18:14 +00:00
|
|
|
"gopkg.in/urfave/cli.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var setPriceCmd = &cli.Command{
|
|
|
|
Name: "set-price",
|
2020-03-09 06:22:11 +00:00
|
|
|
Usage: "Set price that miner will accept storage deals at (FIL / GiB / Epoch)",
|
2020-02-08 00:18:14 +00:00
|
|
|
Flags: []cli.Flag{},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := lcli.DaemonContext(cctx)
|
|
|
|
|
|
|
|
if !cctx.Args().Present() {
|
|
|
|
return fmt.Errorf("must specify price to set")
|
|
|
|
}
|
|
|
|
|
|
|
|
fp, err := types.ParseFIL(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-24 18:00:08 +00:00
|
|
|
return api.MarketSetPrice(ctx, types.BigInt(fp))
|
2020-02-08 00:18:14 +00:00
|
|
|
},
|
|
|
|
}
|
2020-03-04 02:49:00 +00:00
|
|
|
|
|
|
|
var dealsCmd = &cli.Command{
|
|
|
|
Name: "deals",
|
|
|
|
Usage: "interact with your deals",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
dealsImportDataCmd,
|
|
|
|
dealsListCmd,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var dealsImportDataCmd = &cli.Command{
|
2020-03-18 05:08:14 +00:00
|
|
|
Name: "import-data",
|
|
|
|
Usage: "Manually import data for a deal",
|
|
|
|
ArgsUsage: "<proposal CID> <file>",
|
2020-03-04 02:49:00 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := lcli.DaemonContext(cctx)
|
|
|
|
|
2020-03-31 18:18:13 +00:00
|
|
|
if cctx.Args().Len() < 2 {
|
2020-03-04 02:49:00 +00:00
|
|
|
return fmt.Errorf("must specify proposal CID and file path")
|
|
|
|
}
|
|
|
|
|
|
|
|
propCid, err := cid.Decode(cctx.Args().Get(0))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fpath := cctx.Args().Get(1)
|
|
|
|
|
|
|
|
return api.DealsImportData(ctx, propCid, fpath)
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var dealsListCmd = &cli.Command{
|
|
|
|
Name: "list",
|
|
|
|
Usage: "List all deals for this miner",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := lcli.DaemonContext(cctx)
|
|
|
|
|
2020-03-31 18:54:37 +00:00
|
|
|
deals, err := api.MarketListIncompleteDeals(ctx)
|
2020-03-04 02:49:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.MarshalIndent(deals, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(string(data))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|