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"
|
2020-06-17 00:18:54 +00:00
|
|
|
"os"
|
|
|
|
"text/tabwriter"
|
2020-02-08 00:18:14 +00:00
|
|
|
|
2020-06-16 22:38:48 +00:00
|
|
|
"github.com/docker/go-units"
|
2020-03-04 02:49:00 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2020-06-02 18:12:53 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-06-16 22:38:48 +00:00
|
|
|
|
2020-06-17 00:18:54 +00:00
|
|
|
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
|
|
|
|
2020-06-16 22:38:48 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
2020-02-08 00:18:14 +00:00
|
|
|
)
|
|
|
|
|
2020-06-11 19:20:11 +00:00
|
|
|
var enableCmd = &cli.Command{
|
|
|
|
Name: "enable",
|
|
|
|
Usage: "Configure the miner to consider storage deal proposals",
|
|
|
|
Flags: []cli.Flag{},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2020-06-11 19:59:50 +00:00
|
|
|
api, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
2020-06-11 20:18:18 +00:00
|
|
|
return api.DealsSetAcceptingStorageDeals(lcli.DaemonContext(cctx), true)
|
2020-06-11 19:20:11 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var disableCmd = &cli.Command{
|
|
|
|
Name: "disable",
|
|
|
|
Usage: "Configure the miner to reject all storage deal proposals",
|
|
|
|
Flags: []cli.Flag{},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2020-06-11 19:59:50 +00:00
|
|
|
api, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
2020-06-11 20:18:18 +00:00
|
|
|
return api.DealsSetAcceptingStorageDeals(lcli.DaemonContext(cctx), false)
|
2020-06-11 19:20:11 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-06-16 22:38:48 +00:00
|
|
|
var setAskCmd = &cli.Command{
|
|
|
|
Name: "set-ask",
|
|
|
|
Usage: "Configure the miner's ask",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.Uint64Flag{
|
|
|
|
Name: "price",
|
|
|
|
Usage: "Set the price of the ask (specified as FIL / GiB / Epoch) to `PRICE`",
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
&cli.Uint64Flag{
|
|
|
|
Name: "duration",
|
|
|
|
Usage: "Set the duration (specified as epochs) of the ask to `DURATION`",
|
2020-06-17 00:18:54 +00:00
|
|
|
DefaultText: "100000",
|
|
|
|
Value: 100000,
|
2020-06-16 22:38:48 +00:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "min-piece-size",
|
|
|
|
Usage: "Set minimum piece size (without bit-padding, in bytes) in ask to `SIZE`",
|
|
|
|
DefaultText: "254B",
|
|
|
|
Value: "254B",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "max-piece-size",
|
|
|
|
Usage: "Set maximum piece size (without bit-padding, in bytes) in ask to `SIZE`",
|
|
|
|
DefaultText: "miner sector size, without bit-padding",
|
|
|
|
},
|
|
|
|
},
|
2020-02-08 00:18:14 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2020-06-16 22:38:48 +00:00
|
|
|
ctx := lcli.DaemonContext(cctx)
|
|
|
|
|
2020-02-08 00:18:14 +00:00
|
|
|
api, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
2020-06-16 22:38:48 +00:00
|
|
|
pri := types.NewInt(cctx.Uint64("price"))
|
|
|
|
dur := abi.ChainEpoch(cctx.Uint64("duration"))
|
2020-02-08 00:18:14 +00:00
|
|
|
|
2020-06-16 22:38:48 +00:00
|
|
|
min, err := units.RAMInBytes(cctx.String("min-piece-size"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-02-08 00:18:14 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 22:38:48 +00:00
|
|
|
max, err := units.RAMInBytes(cctx.String("max-piece-size"))
|
2020-02-08 00:18:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-16 22:38:48 +00:00
|
|
|
if max == 0 {
|
|
|
|
maddr, err := api.ActorAddress(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize, err := api.ActorSectorSize(ctx, maddr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
max = int64(abi.PaddedPieceSize(ssize).Unpadded())
|
|
|
|
}
|
|
|
|
|
|
|
|
return api.MarketSetAsk(ctx, pri, dur, abi.UnpaddedPieceSize(min).Padded(), abi.UnpaddedPieceSize(max).Padded())
|
2020-02-08 00:18:14 +00:00
|
|
|
},
|
|
|
|
}
|
2020-03-04 02:49:00 +00:00
|
|
|
|
2020-06-17 00:18:54 +00:00
|
|
|
var getAskCmd = &cli.Command{
|
|
|
|
Name: "get-ask",
|
|
|
|
Usage: "Print the miner's ask",
|
|
|
|
Flags: []cli.Flag{},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
ctx := lcli.DaemonContext(cctx)
|
|
|
|
|
|
|
|
api, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
sask, err := api.MarketGetAsk(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var ask *storagemarket.StorageAsk
|
|
|
|
if sask != nil && sask.Ask != nil {
|
|
|
|
ask = sask.Ask
|
|
|
|
}
|
|
|
|
|
|
|
|
w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
|
2020-06-17 00:32:45 +00:00
|
|
|
fmt.Fprintf(w, "Price per GiB / Epoch\tMin. Piece Size (unpadded)\tMax. Piece Size (unpadded)\tExpiry\tSeq. No.\n")
|
2020-06-17 00:18:54 +00:00
|
|
|
if ask == nil {
|
|
|
|
fmt.Fprintf(w, "<miner does not have an ask>\n")
|
|
|
|
} else {
|
2020-06-17 00:32:45 +00:00
|
|
|
fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%d\n", ask.Price, types.SizeStr(types.NewInt(uint64(ask.MinPieceSize.Unpadded()))), types.SizeStr(types.NewInt(uint64(ask.MaxPieceSize.Unpadded()))), ask.Expiry, ask.SeqNo)
|
2020-06-17 00:18:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return w.Flush()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-03-04 02:49:00 +00:00
|
|
|
var dealsCmd = &cli.Command{
|
|
|
|
Name: "deals",
|
|
|
|
Usage: "interact with your deals",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
dealsImportDataCmd,
|
|
|
|
dealsListCmd,
|
2020-06-11 19:59:50 +00:00
|
|
|
enableCmd,
|
|
|
|
disableCmd,
|
2020-06-16 22:38:48 +00:00
|
|
|
setAskCmd,
|
2020-06-17 00:18:54 +00:00
|
|
|
getAskCmd,
|
2020-03-04 02:49:00 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
},
|
|
|
|
}
|