add miner side commands and a few other goodies
This commit is contained in:
parent
52acfb88ee
commit
9169a073b6
@ -118,6 +118,9 @@ type StorageMiner interface {
|
|||||||
MarketListDeals(ctx context.Context) ([]storagemarket.StorageDeal, error)
|
MarketListDeals(ctx context.Context) ([]storagemarket.StorageDeal, error)
|
||||||
MarketListIncompleteDeals(ctx context.Context) ([]storagemarket.MinerDeal, error)
|
MarketListIncompleteDeals(ctx context.Context) ([]storagemarket.MinerDeal, error)
|
||||||
SetPrice(context.Context, types.BigInt) 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 {
|
type SectorLog struct {
|
||||||
|
@ -178,6 +178,9 @@ type StorageMinerStruct struct {
|
|||||||
WorkerDone func(ctx context.Context, task uint64, res sectorbuilder.SealRes) error `perm:"admin"`
|
WorkerDone func(ctx context.Context, task uint64, res sectorbuilder.SealRes) error `perm:"admin"`
|
||||||
|
|
||||||
SetPrice func(context.Context, types.BigInt) 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)
|
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.Common = &CommonStruct{}
|
||||||
var _ api.FullNode = &FullNodeStruct{}
|
var _ api.FullNode = &FullNodeStruct{}
|
||||||
var _ api.StorageMiner = &StorageMinerStruct{}
|
var _ api.StorageMiner = &StorageMinerStruct{}
|
||||||
|
@ -96,6 +96,10 @@ var clientDealCmd = &cli.Command{
|
|||||||
Name: "manual-piece-size",
|
Name: "manual-piece-size",
|
||||||
Usage: "if manually specifying piece cid, used to specify 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 {
|
Action: func(cctx *cli.Context) error {
|
||||||
api, closer, err := GetFullNodeAPI(cctx)
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
@ -131,9 +135,19 @@ var clientDealCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
a, err := api.WalletDefaultAddress(ctx)
|
var a address.Address
|
||||||
if err != nil {
|
if from := cctx.String("from"); from != "" {
|
||||||
return err
|
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{
|
ref := &storagemarket.DataRef{
|
||||||
|
@ -22,6 +22,7 @@ func main() {
|
|||||||
lotuslog.SetupLogLevels()
|
lotuslog.SetupLogLevels()
|
||||||
|
|
||||||
local := []*cli.Command{
|
local := []*cli.Command{
|
||||||
|
dealsCmd,
|
||||||
infoCmd,
|
infoCmd,
|
||||||
initCmd,
|
initCmd,
|
||||||
pledgeSectorCmd,
|
pledgeSectorCmd,
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
lcli "github.com/filecoin-project/lotus/cli"
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
|
"github.com/ipfs/go-cid"
|
||||||
"gopkg.in/urfave/cli.v2"
|
"gopkg.in/urfave/cli.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -33,3 +35,67 @@ var setPriceCmd = &cli.Command{
|
|||||||
return api.SetPrice(ctx, types.BigInt(fp))
|
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
|
||||||
|
},
|
||||||
|
}
|
||||||
|
@ -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?
|
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{}
|
var _ api.StorageMiner = &StorageMinerAPI{}
|
||||||
|
Loading…
Reference in New Issue
Block a user