lotus/cmd/lotus-storage-miner/retrieval-deals.go

157 lines
3.5 KiB
Go
Raw Normal View History

package main
import (
"fmt"
2020-08-04 23:40:29 +00:00
"os"
"text/tabwriter"
2020-08-04 23:40:29 +00:00
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
"github.com/urfave/cli/v2"
2020-08-04 23:40:29 +00:00
lcli "github.com/filecoin-project/lotus/cli"
)
var retrievalDealsCmd = &cli.Command{
Name: "retrieval-deals",
Usage: "Manage retrieval deals and related configuration",
Subcommands: []*cli.Command{
retrievalDealSelectionCmd,
2020-08-04 23:40:29 +00:00
retrievalDealsListCmd,
},
}
var retrievalDealSelectionCmd = &cli.Command{
Name: "selection",
Usage: "Configure acceptance criteria for retrieval deal proposals",
Subcommands: []*cli.Command{
retrievalDealSelectionShowCmd,
retrievalDealSelectionResetCmd,
retrievalDealSelectionRejectCmd,
},
}
var retrievalDealSelectionShowCmd = &cli.Command{
Name: "list",
Usage: "List retrieval deal proposal selection criteria",
Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
onlineOk, err := smapi.DealsConsiderOnlineRetrievalDeals(lcli.DaemonContext(cctx))
if err != nil {
return err
}
offlineOk, err := smapi.DealsConsiderOfflineRetrievalDeals(lcli.DaemonContext(cctx))
if err != nil {
return err
}
fmt.Printf("considering online retrieval deals: %t\n", onlineOk)
fmt.Printf("considering offline retrieval deals: %t\n", offlineOk)
return nil
},
}
var retrievalDealSelectionResetCmd = &cli.Command{
Name: "reset",
Usage: "Reset retrieval deal proposal selection criteria to default values",
Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
err = smapi.DealsSetConsiderOnlineRetrievalDeals(lcli.DaemonContext(cctx), true)
if err != nil {
return err
}
err = smapi.DealsSetConsiderOfflineRetrievalDeals(lcli.DaemonContext(cctx), true)
if err != nil {
return err
}
return nil
},
}
var retrievalDealSelectionRejectCmd = &cli.Command{
Name: "reject",
Usage: "Configure criteria which necessitate automatic rejection",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "online",
},
&cli.BoolFlag{
Name: "offline",
},
},
Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
if cctx.Bool("online") {
err = smapi.DealsSetConsiderOnlineRetrievalDeals(lcli.DaemonContext(cctx), false)
if err != nil {
return err
}
}
if cctx.Bool("offline") {
err = smapi.DealsSetConsiderOfflineRetrievalDeals(lcli.DaemonContext(cctx), false)
if err != nil {
return err
}
}
return nil
},
}
2020-08-04 23:40:29 +00:00
var retrievalDealsListCmd = &cli.Command{
Name: "list",
Usage: "List all active retrieval deals for this miner",
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
deals, err := api.MarketListRetrievalDeals(lcli.DaemonContext(cctx))
if err != nil {
return err
}
w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
2020-08-05 00:09:32 +00:00
_, _ = fmt.Fprintf(w, "Receiver\tDealID\tPayload\tState\tPricePerByte\tBytesSent\tMessage\n")
2020-08-04 23:40:29 +00:00
for _, deal := range deals {
2020-08-05 00:09:32 +00:00
payloadCid := deal.PayloadCID.String()
_, _ = fmt.Fprintf(w,
"%s\t%d\t%s\t%s\t%s\t%d\t%s\n",
deal.Receiver.String(),
deal.ID,
"..."+payloadCid[len(payloadCid)-8:],
retrievalmarket.DealStatuses[deal.Status],
deal.PricePerByte.String(),
deal.TotalSent,
deal.Message,
)
2020-08-04 23:40:29 +00:00
}
return w.Flush()
},
}