From fb34d2b9e32ef566f409b9862a2d02b61c7b9772 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 7 Jul 2020 16:39:32 -0700 Subject: [PATCH] WIP: parse msig accounts file and include it into the genesis template --- cmd/lotus-seed/genesis.go | 73 +++++++++++++++++++++++++++++++++++++++ genesis/types.go | 13 ++++++- 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/cmd/lotus-seed/genesis.go b/cmd/lotus-seed/genesis.go index d439e2ed5..96fa25236 100644 --- a/cmd/lotus-seed/genesis.go +++ b/cmd/lotus-seed/genesis.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "fmt" "io/ioutil" "github.com/google/uuid" @@ -10,6 +11,7 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/lotus/build" @@ -23,6 +25,7 @@ var genesisCmd = &cli.Command{ Subcommands: []*cli.Command{ genesisNewCmd, genesisAddMinerCmd, + genesisAddMsigsCmd, }, } @@ -141,3 +144,73 @@ var genesisAddMinerCmd = &cli.Command{ return nil }, } + +type GenAccountEntry struct { + ID string + CustodianID int + M int + N int + Addresses []address.Address + Type string + Sig1 string + Sig2 string +} + +var genesisAddMsigsCmd = &cli.Command{ + Name: "add-msigs", + Action: func(cctx *cli.Context) error { + if cctx.Args().Len() < 2 { + return fmt.Errorf("must specify template file and csv file with accounts") + } + + 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 entries []GenAccountEntry + // TODO: parse that csv + + for i, e := range entries { + if len(e.Addresses) != e.N { + return fmt.Errorf("entry %d had mismatch between 'N' and number of addresses", i) + } + + msig := &genesis.MultisigMeta{ + Signers: e.Addresses, + Threshold: e.M, + VestingDuration: 0, // TODO + VestingStart: 0, // TODO + } + + act := genesis.Actor{ + Type: genesis.TMultisig, + Balance: abi.NewTokenAmount(0), // TODO + Meta: msig.ActorMeta(), + } + + template.Accounts = append(template.Accounts, act) + + } + + b, err = json.MarshalIndent(&template, "", " ") + if err != nil { + return err + } + + if err := ioutil.WriteFile(genf, b, 0644); err != nil { + return err + } + return nil + }, +} diff --git a/genesis/types.go b/genesis/types.go index 41d8a413c..acf69298f 100644 --- a/genesis/types.go +++ b/genesis/types.go @@ -51,7 +51,18 @@ func (am *AccountMeta) ActorMeta() json.RawMessage { } type MultisigMeta struct { - // TODO + Signers []address.Address + Threshold int + VestingDuration int + VestingStart int +} + +func (mm *MultisigMeta) ActorMeta() json.RawMessage { + out, err := json.Marshal(mm) + if err != nil { + panic(err) + } + return out } type Actor struct {