initGenFiles initializes genesis files for testnet.
( clientCtx client.Context, mbm module.BasicManager, genesisParams GenesisParams, chainID string, genAccounts []authtypes.GenesisAccount, genBalances []banktypes.Balance, genFiles []string, numValidators int, )
| 275 | |
| 276 | // initGenFiles initializes genesis files for testnet. |
| 277 | func initGenFiles( |
| 278 | clientCtx client.Context, mbm module.BasicManager, genesisParams GenesisParams, chainID string, |
| 279 | genAccounts []authtypes.GenesisAccount, genBalances []banktypes.Balance, |
| 280 | genFiles []string, numValidators int, |
| 281 | ) error { |
| 282 | appGenState := mbm.DefaultGenesis(clientCtx.Codec) |
| 283 | |
| 284 | // set the accounts in the genesis state |
| 285 | var authGenState authtypes.GenesisState |
| 286 | clientCtx.Codec.MustUnmarshalJSON(appGenState[authtypes.ModuleName], &authGenState) |
| 287 | |
| 288 | accounts, err := authtypes.PackAccounts(genAccounts) |
| 289 | if err != nil { |
| 290 | return err |
| 291 | } |
| 292 | |
| 293 | authGenState.Accounts = accounts |
| 294 | appGenState[authtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&authGenState) |
| 295 | |
| 296 | // set the balances in the genesis state |
| 297 | var bankGenState banktypes.GenesisState |
| 298 | clientCtx.Codec.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState) |
| 299 | |
| 300 | bankGenState.Balances = genBalances |
| 301 | appGenState[banktypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&bankGenState) |
| 302 | |
| 303 | appGenState, _, err = PrepareGenesis(clientCtx, appGenState, &genutiltypes.AppGenesis{}, genesisParams, chainID) |
| 304 | if err != nil { |
| 305 | return err |
| 306 | } |
| 307 | |
| 308 | appGenStateJSON, err := json.MarshalIndent(appGenState, "", " ") |
| 309 | if err != nil { |
| 310 | return fmt.Errorf("failed to marshal application genesis state: %w", err) |
| 311 | } |
| 312 | |
| 313 | genDoc := types.GenesisDoc{ |
| 314 | ChainID: chainID, |
| 315 | AppState: appGenStateJSON, |
| 316 | Validators: nil, |
| 317 | } |
| 318 | |
| 319 | // generate empty genesis files for each validator and save |
| 320 | for i := 0; i < numValidators; i++ { |
| 321 | if err := genDoc.SaveAs(genFiles[i]); err != nil { |
| 322 | return err |
| 323 | } |
| 324 | } |
| 325 | return nil |
| 326 | } |
| 327 | |
| 328 | func collectGenFiles( |
| 329 | clientCtx client.Context, nodeConfig *tmconfig.Config, chainID string, |
no test coverage detected