From f86ce88d3d059dc754aa46a63a6e0c4a4a65d29f Mon Sep 17 00:00:00 2001 From: Jennifer Wang Date: Sun, 21 Aug 2022 22:33:24 -0400 Subject: [PATCH] add cmd for adding signers to vkh to genesis --- cmd/lotus-seed/genesis.go | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/cmd/lotus-seed/genesis.go b/cmd/lotus-seed/genesis.go index 5c3ac5ff1..9f0a8f7dc 100644 --- a/cmd/lotus-seed/genesis.go +++ b/cmd/lotus-seed/genesis.go @@ -42,6 +42,7 @@ var genesisCmd = &cli.Command{ genesisSetRemainderCmd, genesisSetActorVersionCmd, genesisCarCmd, + genesisSetVRKSignersCmd, }, } @@ -581,3 +582,89 @@ var genesisCarCmd = &cli.Command{ return err }, } + +var genesisSetVRKSignersCmd = &cli.Command{ + Name: "set-signers", + Usage: "", + Flags: []cli.Flag{ + &cli.IntFlag{ + Name: "threshold", + Usage: "change the verifreg signer threshold", + }, + &cli.StringSliceFlag{ + Name: "signers", + Usage: "verifreg signers", + }, + }, + Action: func(cctx *cli.Context) error { + if cctx.Args().Len() != 1 { + return fmt.Errorf("must specify template file") + } + + genf, err := homedir.Expand(cctx.Args().First()) + if err != nil { + return err + } + + var template genesis.Template + b, err := ioutil.ReadFile(genf) + if err != nil { + return xerrors.Errorf("read genesis template: %w", err) + } + + if err := json.Unmarshal(b, &template); err != nil { + return xerrors.Errorf("unmarshal genesis template: %w", err) + } + + var signers []address.Address + var rootkeyMultisig genesis.MultisigMeta + if cctx.IsSet("signers") { + for _, s := range cctx.StringSlice("signers") { + signer, err := address.NewFromString(s) + if err != nil { + return err + } + signers = append(signers, signer) + template.Accounts = append(template.Accounts, genesis.Actor{ + Type: genesis.TAccount, + Balance: big.Mul(big.NewInt(50_000), big.NewInt(int64(build.FilecoinPrecision))), + Meta: (&genesis.AccountMeta{Owner: signer}).ActorMeta(), + }) + } + rootkeyMultisig = genesis.MultisigMeta{ + Signers: signers, + Threshold: 1, + VestingDuration: 0, + VestingStart: 0, + } + + } + + if cctx.IsSet("threshold") { + rootkeyMultisig = genesis.MultisigMeta{ + Signers: signers, + Threshold: cctx.Int("threshold"), + VestingDuration: 0, + VestingStart: 0, + } + } + + newVrk := genesis.Actor{ + Type: genesis.TMultisig, + Balance: big.NewInt(0), + Meta: rootkeyMultisig.ActorMeta(), + } + + template.VerifregRootKey = newVrk + + b, err = json.MarshalIndent(&template, "", " ") + if err != nil { + return err + } + + if err := ioutil.WriteFile(genf, b, 0644); err != nil { + return err + } + return nil + }, +}