2020-06-23 22:54:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
ma "github.com/multiformats/go-multiaddr"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var actorCmd = &cli.Command{
|
2020-06-23 23:00:32 +00:00
|
|
|
Name: "actor",
|
2020-06-23 22:54:28 +00:00
|
|
|
Usage: "manipulate the miner actor",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
actorSetAddrsCmd,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var actorSetAddrsCmd = &cli.Command{
|
|
|
|
Name: "set-addrs",
|
2020-07-29 20:34:01 +00:00
|
|
|
Usage: "set addresses that your miner can be publicly dialed on",
|
2020-06-23 22:54:28 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.Int64Flag{
|
|
|
|
Name: "gas-limit",
|
|
|
|
Usage: "set gas limit",
|
2020-07-29 08:03:29 +00:00
|
|
|
Value: 0,
|
2020-06-23 22:54:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2020-06-23 23:00:32 +00:00
|
|
|
nodeAPI, closer, err := lcli.GetStorageMinerAPI(cctx)
|
2020-06-23 22:54:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
api, acloser, err := lcli.GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer acloser()
|
|
|
|
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
|
|
|
var addrs []abi.Multiaddrs
|
|
|
|
for _, a := range cctx.Args().Slice() {
|
|
|
|
maddr, err := ma.NewMultiaddr(a)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to parse %q as a multiaddr: %w", a, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
addrs = append(addrs, maddr.Bytes())
|
|
|
|
}
|
|
|
|
|
2020-06-23 23:00:32 +00:00
|
|
|
maddr, err := nodeAPI.ActorAddress(ctx)
|
2020-06-23 22:54:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
minfo, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-23 23:00:32 +00:00
|
|
|
params, err := actors.SerializeParams(&miner.ChangeMultiaddrsParams{NewMultiaddrs: addrs})
|
2020-06-23 22:54:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
gasLimit := cctx.Int64("gas-limit")
|
|
|
|
|
|
|
|
smsg, err := api.MpoolPushMessage(ctx, &types.Message{
|
|
|
|
To: maddr,
|
|
|
|
From: minfo.Worker,
|
|
|
|
Value: types.NewInt(0),
|
|
|
|
GasLimit: gasLimit,
|
|
|
|
Method: 18,
|
|
|
|
Params: params,
|
|
|
|
})
|
2020-06-23 23:00:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-06-23 22:54:28 +00:00
|
|
|
|
|
|
|
fmt.Printf("Requested multiaddrs change in message %s\n", smsg.Cid())
|
|
|
|
return nil
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|