add miner side commands and a few other goodies

This commit is contained in:
whyrusleeping 2020-03-03 18:49:00 -08:00
parent 52acfb88ee
commit 9169a073b6
6 changed files with 112 additions and 3 deletions

View File

@ -118,6 +118,9 @@ type StorageMiner interface {
MarketListDeals(ctx context.Context) ([]storagemarket.StorageDeal, error)
MarketListIncompleteDeals(ctx context.Context) ([]storagemarket.MinerDeal, error)
SetPrice(context.Context, types.BigInt) error
DealsImportData(ctx context.Context, dealPropCid cid.Cid, file string) error
DealsList(ctx context.Context) ([]storagemarket.StorageDeal, error)
}
type SectorLog struct {

View File

@ -178,6 +178,9 @@ type StorageMinerStruct struct {
WorkerDone func(ctx context.Context, task uint64, res sectorbuilder.SealRes) error `perm:"admin"`
SetPrice func(context.Context, types.BigInt) error `perm:"admin"`
DealsImportData func(ctx context.Context, dealPropCid cid.Cid, file string) error `perm:"write"`
DealsList func(ctx context.Context) ([]storagemarket.StorageDeal, error) `perm:"read"`
}
}
@ -635,6 +638,14 @@ func (c *StorageMinerStruct) SetPrice(ctx context.Context, p types.BigInt) error
return c.Internal.SetPrice(ctx, p)
}
func (c *StorageMinerStruct) DealsImportData(ctx context.Context, dealPropCid cid.Cid, file string) error {
return c.Internal.DealsImportData(ctx, dealPropCid, file)
}
func (c *StorageMinerStruct) DealsList(ctx context.Context) ([]storagemarket.StorageDeal, error) {
return c.Internal.DealsList(ctx)
}
var _ api.Common = &CommonStruct{}
var _ api.FullNode = &FullNodeStruct{}
var _ api.StorageMiner = &StorageMinerStruct{}

View File

@ -96,6 +96,10 @@ var clientDealCmd = &cli.Command{
Name: "manual-piece-size",
Usage: "if manually specifying piece cid, used to specify size",
},
&cli.StringFlag{
Name: "from",
Usage: "specify address to fund the deal with",
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
@ -131,9 +135,19 @@ var clientDealCmd = &cli.Command{
return err
}
a, err := api.WalletDefaultAddress(ctx)
if err != nil {
return err
var a address.Address
if from := cctx.String("from"); from != "" {
faddr, err := address.NewFromString(from)
if err != nil {
return xerrors.Errorf("failed to parse 'from' address: %w", err)
}
a = faddr
} else {
def, err := api.WalletDefaultAddress(ctx)
if err != nil {
return err
}
a = def
}
ref := &storagemarket.DataRef{

View File

@ -22,6 +22,7 @@ func main() {
lotuslog.SetupLogLevels()
local := []*cli.Command{
dealsCmd,
infoCmd,
initCmd,
pledgeSectorCmd,

View File

@ -1,10 +1,12 @@
package main
import (
"encoding/json"
"fmt"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/ipfs/go-cid"
"gopkg.in/urfave/cli.v2"
)
@ -33,3 +35,67 @@ var setPriceCmd = &cli.Command{
return api.SetPrice(ctx, types.BigInt(fp))
},
}
var dealsCmd = &cli.Command{
Name: "deals",
Usage: "interact with your deals",
Subcommands: []*cli.Command{
dealsImportDataCmd,
dealsListCmd,
},
}
var dealsImportDataCmd = &cli.Command{
Name: "import-data",
Usage: "Manually import data for a deal",
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().Len() == 2 {
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)
deals, err := api.DealsList(ctx)
if err != nil {
return err
}
data, err := json.MarshalIndent(deals, "", " ")
if err != nil {
return err
}
fmt.Println(string(data))
return nil
},
}

View File

@ -287,4 +287,18 @@ func (sm *StorageMinerAPI) SetPrice(ctx context.Context, p types.BigInt) error {
return sm.StorageProvider.AddAsk(abi.TokenAmount(p), 60*60*24*100) // lasts for 100 days?
}
func (sm *StorageMinerAPI) DealsList(ctx context.Context) ([]storagemarket.StorageDeal, error) {
return sm.StorageProvider.ListDeals(ctx)
}
func (sm *StorageMinerAPI) DealsImportData(ctx context.Context, deal cid.Cid, fname string) error {
fi, err := os.Open(fname)
if err != nil {
return xerrors.Errorf("failed to open given file: %w", err)
}
defer fi.Close()
return sm.StorageProvider.ImportDataForDeal(ctx, deal, fi)
}
var _ api.StorageMiner = &StorageMinerAPI{}