2019-07-17 03:05:55 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
2019-07-18 18:24:56 +00:00
|
|
|
"golang.org/x/xerrors"
|
2019-07-17 03:05:55 +00:00
|
|
|
"gopkg.in/urfave/cli.v2"
|
|
|
|
|
2019-10-18 04:47:41 +00:00
|
|
|
actors "github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
address "github.com/filecoin-project/lotus/chain/address"
|
|
|
|
types "github.com/filecoin-project/lotus/chain/types"
|
2019-07-17 03:05:55 +00:00
|
|
|
|
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
|
|
)
|
|
|
|
|
|
|
|
var createMinerCmd = &cli.Command{
|
|
|
|
Name: "createminer",
|
|
|
|
Usage: "Create a new storage market actor",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
if cctx.Args().Len() != 4 {
|
|
|
|
return fmt.Errorf("must pass four arguments: worker address, owner address, sector size, peer ID")
|
|
|
|
}
|
|
|
|
|
2019-10-03 18:12:30 +00:00
|
|
|
api, closer, err := GetFullNodeAPI(cctx)
|
2019-07-17 03:05:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-10-03 18:12:30 +00:00
|
|
|
defer closer()
|
2019-07-17 03:05:55 +00:00
|
|
|
|
|
|
|
args := cctx.Args().Slice()
|
|
|
|
|
|
|
|
worker, err := address.NewFromString(args[0])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
owner, err := address.NewFromString(args[1])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize, err := strconv.ParseUint(args[2], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
pid, err := peer.IDB58Decode(args[3])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
createMinerArgs := actors.CreateStorageMinerParams{
|
|
|
|
Worker: worker,
|
|
|
|
Owner: owner,
|
|
|
|
SectorSize: types.NewInt(ssize),
|
|
|
|
PeerID: pid,
|
|
|
|
}
|
|
|
|
|
2019-07-18 23:16:23 +00:00
|
|
|
ctx := ReqContext(cctx)
|
2019-07-17 03:05:55 +00:00
|
|
|
addr, err := api.WalletDefaultAddress(ctx)
|
|
|
|
if err != nil {
|
2019-07-18 18:24:56 +00:00
|
|
|
return xerrors.Errorf("failed to get default address: %w", err)
|
2019-07-17 03:05:55 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 23:03:17 +00:00
|
|
|
params, err := actors.SerializeParams(&createMinerArgs)
|
2019-07-17 03:05:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-10-06 01:34:45 +00:00
|
|
|
msg := &types.Message{
|
2019-07-17 03:05:55 +00:00
|
|
|
To: actors.StorageMarketAddress,
|
|
|
|
From: addr,
|
2019-10-11 22:59:36 +00:00
|
|
|
Method: actors.SPAMethods.CreateStorageMiner,
|
2019-07-17 03:05:55 +00:00
|
|
|
Params: params,
|
2019-07-18 19:12:30 +00:00
|
|
|
Value: types.NewInt(0),
|
2019-10-06 01:34:45 +00:00
|
|
|
GasPrice: types.NewInt(0),
|
|
|
|
GasLimit: types.NewInt(10000),
|
2019-07-17 03:05:55 +00:00
|
|
|
}
|
|
|
|
|
2019-10-06 01:34:45 +00:00
|
|
|
smsg, err := api.MpoolPushMessage(ctx, msg)
|
2019-07-17 03:05:55 +00:00
|
|
|
if err != nil {
|
2019-07-18 18:24:56 +00:00
|
|
|
return xerrors.Errorf("failed to push signed message: %w", err)
|
2019-07-17 03:05:55 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 05:51:34 +00:00
|
|
|
mwait, err := api.StateWaitMsg(ctx, smsg.Cid())
|
2019-07-17 03:05:55 +00:00
|
|
|
if err != nil {
|
2019-07-18 18:24:56 +00:00
|
|
|
return xerrors.Errorf("failed waiting for message inclusion: %w", err)
|
2019-07-17 03:05:55 +00:00
|
|
|
}
|
|
|
|
|
2019-07-17 06:05:11 +00:00
|
|
|
maddr, err := address.NewFromBytes(mwait.Receipt.Return)
|
2019-07-17 03:05:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-07-17 06:15:07 +00:00
|
|
|
fmt.Printf("new miner address: %s\n", maddr)
|
2019-07-17 03:05:55 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|