github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/cmd/burrow/commands/spec.go (about) 1 package commands 2 3 import ( 4 "fmt" 5 6 "github.com/hyperledger/burrow/config/source" 7 "github.com/hyperledger/burrow/genesis/spec" 8 cli "github.com/jawher/mow.cli" 9 ) 10 11 // Spec generates a list of genesis accounts with certain permissions 12 func Spec(output Output) func(cmd *cli.Cmd) { 13 return func(cmd *cli.Cmd) { 14 tomlOpt := cmd.BoolOpt("t toml", false, "Emit GenesisSpec as TOML rather than the "+ 15 "default JSON") 16 17 baseSpecsArg := cmd.StringsArg("BASE", nil, "Provide a base GenesisSpecs on top of which any "+ 18 "additional GenesisSpec presets specified by other flags will be merged. GenesisSpecs appearing "+ 19 "later take precedent over those appearing early if multiple --base flags are provided") 20 21 accountNamePrefixOpt := cmd.StringOpt("x name-prefix", "", "Prefix added to the names of accounts in GenesisSpec") 22 fullOpt := cmd.IntOpt("f full-accounts", 0, "Number of preset Full type accounts") 23 validatorOpt := cmd.IntOpt("v validator-accounts", 0, "Number of preset Validator type accounts") 24 rootOpt := cmd.IntOpt("r root-accounts", 0, "Number of preset Root type accounts") 25 developerOpt := cmd.IntOpt("d developer-accounts", 0, "Number of preset Developer type accounts") 26 participantsOpt := cmd.IntOpt("p participant-accounts", 0, "Number of preset Participant type accounts") 27 chainNameOpt := cmd.StringOpt("n chain-name", "", "Default chain name") 28 proposalThresholdOpt := cmd.IntOpt("param-proposalthreshold", 3, "Number of votes required for a proposal to pass") 29 30 cmd.Spec = "[--name-prefix=<prefix for account names>][--full-accounts] [--validator-accounts] [--root-accounts] " + 31 "[--developer-accounts] [--participant-accounts] [--chain-name] [--toml] [BASE...]" 32 33 cmd.Action = func() { 34 specs := make([]spec.GenesisSpec, 0, *participantsOpt+*fullOpt) 35 for _, baseSpec := range *baseSpecsArg { 36 genesisSpec := new(spec.GenesisSpec) 37 err := source.FromFile(baseSpec, genesisSpec) 38 if err != nil { 39 output.Fatalf("could not read GenesisSpec: %v", err) 40 } 41 specs = append(specs, *genesisSpec) 42 } 43 for i := 0; i < *fullOpt; i++ { 44 specs = append(specs, spec.FullAccount(fmt.Sprintf("%sFull_%v", *accountNamePrefixOpt, i))) 45 } 46 for i := 0; i < *validatorOpt; i++ { 47 specs = append(specs, spec.ValidatorAccount(fmt.Sprintf("%sValidator_%v", *accountNamePrefixOpt, i))) 48 } 49 for i := 0; i < *rootOpt; i++ { 50 specs = append(specs, spec.RootAccount(fmt.Sprintf("%sRoot_%v", *accountNamePrefixOpt, i))) 51 } 52 for i := 0; i < *developerOpt; i++ { 53 specs = append(specs, spec.DeveloperAccount(fmt.Sprintf("%sDeveloper_%v", *accountNamePrefixOpt, i))) 54 } 55 for i := 0; i < *participantsOpt; i++ { 56 specs = append(specs, spec.ParticipantAccount(fmt.Sprintf("%sParticipant_%v", *accountNamePrefixOpt, i))) 57 } 58 genesisSpec := spec.MergeGenesisSpecs(specs...) 59 if *chainNameOpt != "" { 60 genesisSpec.ChainName = *chainNameOpt 61 } 62 genesisSpec.Params.ProposalThreshold = uint64(*proposalThresholdOpt) 63 if *tomlOpt { 64 output.Printf(source.TOMLString(genesisSpec)) 65 } else { 66 output.Printf(source.JSONString(genesisSpec)) 67 } 68 } 69 } 70 }