-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(x/genutil)!: bulk add genesis accounts #21372
Changes from 7 commits
d7fccac
670282d
e15b4ae
aab13de
217e1b6
bd9cfa6
a4a0fe5
25d9719
3cc0ec3
0c4aaa6
fb37cad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ package cli | |
|
||
import ( | ||
"bufio" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
|
@@ -71,7 +73,33 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa | |
vestingAmtStr, _ := cmd.Flags().GetString(flagVestingAmt) | ||
moduleNameStr, _ := cmd.Flags().GetString(flagModuleName) | ||
|
||
return genutil.AddGenesisAccount(clientCtx.Codec, clientCtx.AddressCodec, addr, appendflag, config.GenesisFile(), args[1], vestingAmtStr, vestingStart, vestingEnd, moduleNameStr) | ||
addrStr, err := addressCodec.BytesToString(addr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
coins, err := sdk.ParseCoinsNormalized(args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
vestingAmt, err := sdk.ParseCoinsNormalized(vestingAmtStr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
accounts := []genutil.GenesisAccount{ | ||
{ | ||
Address: addrStr, | ||
Coins: coins, | ||
VestingAmt: vestingAmt, | ||
VestingStart: vestingStart, | ||
VestingEnd: vestingEnd, | ||
ModuleName: moduleNameStr, | ||
}, | ||
} | ||
Comment on lines
+91
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure proper validation for GenesisAccount fields. The Implement validation methods within the |
||
|
||
return genutil.AddGenesisAccounts(clientCtx.Codec, clientCtx.AddressCodec, accounts, appendflag, config.GenesisFile()) | ||
}, | ||
} | ||
|
||
|
@@ -85,3 +113,41 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa | |
|
||
return cmd | ||
} | ||
|
||
// AddBulkGenesisAccountCmd returns bulk-add-genesis-account cobra Command. | ||
// This command is provided as a default, applications are expected to provide their own command if custom genesis accounts are needed. | ||
func AddBulkGenesisAccountCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "bulk-add-genesis-account [/file/path.json]", | ||
Short: "Bulk add genesis accounts to genesis.json", | ||
Long: `Add genesis accounts in bulk to genesis.json. The provided account must specify | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add the Example field from cobra and show how the file should look like? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
the account address and a list of initial coins. The list of initial tokens must | ||
contain valid denominations. Accounts may optionally be supplied with vesting parameters. | ||
`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx := client.GetClientContextFromCmd(cmd) | ||
config := client.GetConfigFromCmd(cmd) | ||
|
||
f, err := os.Open(args[0]) | ||
if err != nil { | ||
return fmt.Errorf("failed to open file: %w", err) | ||
} | ||
defer f.Close() | ||
|
||
var accounts []genutil.GenesisAccount | ||
if err := json.NewDecoder(f).Decode(&accounts); err != nil { | ||
return fmt.Errorf("failed to decode JSON: %w", err) | ||
} | ||
|
||
appendflag, _ := cmd.Flags().GetBool(flagAppendMode) | ||
|
||
return genutil.AddGenesisAccounts(clientCtx.Codec, clientCtx.AddressCodec, accounts, appendflag, config.GenesisFile()) | ||
}, | ||
} | ||
|
||
cmd.Flags().Bool(flagAppendMode, false, "append the coins to an account already in the genesis.json file") | ||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, can you put this under unreleased?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops ty - 25d9719