storageminer: Flags to allow specyfying keys to use
This commit is contained in:
parent
78e1ea14ad
commit
ad1265cad0
@ -28,11 +28,22 @@ var initCmd = &cli.Command{
|
|||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "genesis-miner",
|
Name: "genesis-miner",
|
||||||
Usage: "enable genesis mining (DON'T USE ON BOOTSTRAPPED NETWORK)",
|
Usage: "enable genesis mining (DON'T USE ON BOOTSTRAPPED NETWORK)",
|
||||||
|
Hidden: true,
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "create-worker-key",
|
Name: "create-worker-key",
|
||||||
Usage: "create separate worker key",
|
Usage: "create separate worker key",
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "worker",
|
||||||
|
Aliases: []string{"w"},
|
||||||
|
Usage: "worker key to use (overrides --create-worker-key)",
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "owner",
|
||||||
|
Aliases: []string{"o"},
|
||||||
|
Usage: "owner key to use",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
log.Info("Initializing lotus storage miner")
|
log.Info("Initializing lotus storage miner")
|
||||||
@ -107,7 +118,7 @@ var initCmd = &cli.Command{
|
|||||||
|
|
||||||
addr = a
|
addr = a
|
||||||
} else {
|
} else {
|
||||||
a, err := createStorageMiner(ctx, api, peerid, cctx.Bool("create-worker-key"))
|
a, err := createStorageMiner(ctx, api, peerid, cctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -198,29 +209,35 @@ func configureStorageMiner(ctx context.Context, api api.FullNode, addr address.A
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createStorageMiner(ctx context.Context, api api.FullNode, peerid peer.ID, createWorker bool) (address.Address, error) {
|
func createStorageMiner(ctx context.Context, api api.FullNode, peerid peer.ID, cctx *cli.Context) (addr address.Address, err error) {
|
||||||
log.Info("Creating StorageMarket.CreateStorageMiner message")
|
log.Info("Creating StorageMarket.CreateStorageMiner message")
|
||||||
|
|
||||||
defOwner, err := api.WalletDefaultAddress(ctx)
|
var owner address.Address
|
||||||
|
if cctx.String("owner") != "" {
|
||||||
|
owner, err = address.NewFromString(cctx.String("owner"))
|
||||||
|
} else {
|
||||||
|
owner, err = api.WalletDefaultAddress(ctx)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return address.Undef, err
|
return address.Undef, err
|
||||||
}
|
}
|
||||||
|
|
||||||
k := defOwner
|
worker := owner
|
||||||
if createWorker { // TODO: Do we need to force this if defOwner is Secpk?
|
if cctx.String("worker") != "" {
|
||||||
k, err = api.WalletNew(ctx, types.KTBLS)
|
worker, err = address.NewFromString(cctx.String("worker"))
|
||||||
if err != nil {
|
} else if cctx.Bool("create-worker-key") { // TODO: Do we need to force this if owner is Secpk?
|
||||||
return address.Undef, err
|
worker, err = api.WalletNew(ctx, types.KTBLS)
|
||||||
}
|
}
|
||||||
|
// TODO: Transfer some initial funds to worker
|
||||||
// TODO: Transfer some initial funds
|
if err != nil {
|
||||||
|
return address.Undef, err
|
||||||
}
|
}
|
||||||
|
|
||||||
collateral := types.NewInt(1000) // TODO: Get this from params
|
collateral := types.NewInt(1000) // TODO: Get this from params
|
||||||
|
|
||||||
params, err := actors.SerializeParams(&actors.CreateStorageMinerParams{
|
params, err := actors.SerializeParams(&actors.CreateStorageMinerParams{
|
||||||
Owner: defOwner,
|
Owner: owner,
|
||||||
Worker: k,
|
Worker: worker,
|
||||||
SectorSize: types.NewInt(build.SectorSize),
|
SectorSize: types.NewInt(build.SectorSize),
|
||||||
PeerID: peerid,
|
PeerID: peerid,
|
||||||
})
|
})
|
||||||
@ -230,7 +247,7 @@ func createStorageMiner(ctx context.Context, api api.FullNode, peerid peer.ID, c
|
|||||||
|
|
||||||
createStorageMinerMsg := &types.Message{
|
createStorageMinerMsg := &types.Message{
|
||||||
To: actors.StorageMarketAddress,
|
To: actors.StorageMarketAddress,
|
||||||
From: defOwner,
|
From: owner,
|
||||||
Value: collateral,
|
Value: collateral,
|
||||||
|
|
||||||
Method: actors.SMAMethods.CreateStorageMiner,
|
Method: actors.SMAMethods.CreateStorageMiner,
|
||||||
@ -253,7 +270,7 @@ func createStorageMiner(ctx context.Context, api api.FullNode, peerid peer.ID, c
|
|||||||
return address.Undef, err
|
return address.Undef, err
|
||||||
}
|
}
|
||||||
|
|
||||||
addr, err := address.NewFromBytes(mw.Receipt.Return)
|
addr, err = address.NewFromBytes(mw.Receipt.Return)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return address.Undef, err
|
return address.Undef, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user