Skip to content

Commit

Permalink
Merge pull request #5555 from filecoin-project/chore/change-control
Browse files Browse the repository at this point in the history
chore: set control address: add dump bytes option
  • Loading branch information
diwufeiwen authored Dec 12, 2022
2 parents 35df6cd + 1ff2e99 commit 1800fbd
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions cmd/miner_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"bytes"
"encoding/hex"
"fmt"
"strings"

Expand Down Expand Up @@ -573,6 +574,7 @@ var actorControlSet = &cmds.Command{
Options: []cmds.Option{
cmds.BoolOption("really-do-it", "Actually send transaction performing the action").WithDefault(false),
cmds.StringsOption("addrs", "Control addresses"),
cmds.BoolOption("dump-bytes", "Dumps the bytes of the message that would propose this change").WithDefault(false),
},
Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error {
maddr, err := address.NewFromString(req.Arguments[0])
Expand Down Expand Up @@ -635,10 +637,6 @@ var actorControlSet = &cmds.Command{
}
}

if !req.Options["really-do-it"].(bool) {
return re.Emit("Pass --really-do-it to actually execute this action")
}

cwp := &miner2.ChangeWorkerAddressParams{
NewWorker: mi.Worker,
NewControlAddrs: toSet,
Expand All @@ -649,14 +647,35 @@ var actorControlSet = &cmds.Command{
return fmt.Errorf("serializing params: %w", err)
}

smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.Message{
msg := &types.Message{
From: mi.Owner,
To: maddr,
Method: builtintypes.MethodsMiner.ChangeWorkerAddress,

Value: big.Zero(),
Params: sp,
}, nil)
}

if ok, _ := req.Options["dump-bytes"].(bool); ok {
msg, err = env.(*node.Env).MessagePoolAPI.GasEstimateMessageGas(ctx, msg, nil, types.EmptyTSK)
if err != nil {
return err
}

msgBytes, err := msg.Serialize()
if err != nil {
return err
}

writer.Println("dump message bytes: ", hex.EncodeToString(msgBytes))
return nil
}

if !req.Options["really-do-it"].(bool) {
return re.Emit("Pass --really-do-it to actually execute this action")
}

smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, msg, nil)
if err != nil {
return fmt.Errorf("mpool push: %w", err)
}
Expand Down

0 comments on commit 1800fbd

Please sign in to comment.