2020-03-06 05:32:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2020-06-02 18:12:53 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-03-06 05:32:52 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
2020-04-21 21:45:33 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
2020-03-06 05:32:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var rewardsCmd = &cli.Command{
|
|
|
|
Name: "rewards",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
rewardsRedeemCmd,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var rewardsRedeemCmd = &cli.Command{
|
|
|
|
Name: "redeem",
|
|
|
|
Usage: "Redeem block rewards",
|
2020-04-23 16:44:25 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.Int64Flag{
|
|
|
|
Name: "gas-limit",
|
|
|
|
Usage: "set gas limit",
|
|
|
|
Value: 100000,
|
|
|
|
},
|
|
|
|
},
|
2020-03-06 05:32:52 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
api, acloser, err := lcli.GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer acloser()
|
|
|
|
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
|
|
|
maddr, err := nodeApi.ActorAddress(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-16 17:36:36 +00:00
|
|
|
mi, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
2020-03-06 05:32:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-21 21:45:33 +00:00
|
|
|
mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK)
|
2020-03-06 05:32:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-21 21:45:33 +00:00
|
|
|
params, err := actors.SerializeParams(&miner.WithdrawBalanceParams{
|
|
|
|
mact.Balance, // Default to attempting to withdraw all the extra funds in the miner actor
|
|
|
|
})
|
2020-03-06 05:32:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-23 16:44:25 +00:00
|
|
|
gasLimit := cctx.Int64("gas-limit")
|
|
|
|
|
2020-04-21 21:45:33 +00:00
|
|
|
smsg, err := api.MpoolPushMessage(ctx, &types.Message{
|
|
|
|
To: maddr,
|
|
|
|
From: mi.Owner,
|
2020-03-06 05:32:52 +00:00
|
|
|
Value: types.NewInt(0),
|
|
|
|
GasPrice: types.NewInt(1),
|
2020-04-23 16:44:25 +00:00
|
|
|
GasLimit: gasLimit,
|
2020-04-21 21:45:33 +00:00
|
|
|
Method: builtin.MethodsMiner.WithdrawBalance,
|
2020-03-06 05:32:52 +00:00
|
|
|
Params: params,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-21 21:45:33 +00:00
|
|
|
fmt.Printf("Requested rewards withdrawal in message %s\n", smsg.Cid())
|
2020-03-06 05:32:52 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|