From 236f8a0dc2c513666c1f937d433cf9f3701fa728 Mon Sep 17 00:00:00 2001 From: Anton Shchurov Date: Wed, 11 Dec 2024 19:34:59 +0700 Subject: [PATCH] fix(templates): fixed linter errors for empty scaffolded chain (#4441) --- .../cmd/testnet.go.plush | 53 ++++++++++++------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/testnet.go.plush b/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/testnet.go.plush index 26528a6552..4a7e787023 100644 --- a/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/testnet.go.plush +++ b/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/testnet.go.plush @@ -158,27 +158,37 @@ func initAppForTestnet(app *app.App, args valArgs) *app.App { iterator.Close() // Add our validator to power and last validators store - app.StakingKeeper.SetValidator(ctx, newVal) - err = app.StakingKeeper.SetValidatorByConsAddr(ctx, newVal) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - app.StakingKeeper.SetValidatorByPowerIndex(ctx, newVal) - app.StakingKeeper.SetLastValidatorPower(ctx, validator, 0) - if err := app.StakingKeeper.Hooks().AfterValidatorCreated(ctx, validator); err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - + handleErr(app.StakingKeeper.SetValidator(ctx, newVal)) + handleErr(app.StakingKeeper.SetValidatorByConsAddr(ctx, newVal)) + handleErr(app.StakingKeeper.SetValidatorByPowerIndex(ctx, newVal)) + handleErr(app.StakingKeeper.SetLastValidatorPower(ctx, validator, 0)) + handleErr(app.StakingKeeper.Hooks().AfterValidatorCreated(ctx, validator)) + // DISTRIBUTION // // Initialize records for this validator across all distribution stores - app.DistrKeeper.ValidatorHistoricalRewards.Set(ctx, collections.Join(sdk.ValAddress(validator), uint64(0)), distrtypes.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1)) - app.DistrKeeper.ValidatorCurrentRewards.Set(ctx, validator, distrtypes.NewValidatorCurrentRewards(sdk.DecCoins{}, 1)) - app.DistrKeeper.ValidatorsAccumulatedCommission.Set(ctx, validator, distrtypes.InitialValidatorAccumulatedCommission()) - app.DistrKeeper.ValidatorOutstandingRewards.Set(ctx, validator, distrtypes.ValidatorOutstandingRewards{Rewards: sdk.DecCoins{}}) + handleErr(app.DistrKeeper.ValidatorHistoricalRewards.Set( + ctx, + collections.Join(sdk.ValAddress(validator), uint64(0)), + distrtypes.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1), + )) + + handleErr(app.DistrKeeper.ValidatorCurrentRewards.Set( + ctx, + validator, + distrtypes.NewValidatorCurrentRewards(sdk.DecCoins{}, 1), + )) + + handleErr(app.DistrKeeper.ValidatorsAccumulatedCommission.Set( + ctx, validator, distrtypes.InitialValidatorAccumulatedCommission(), + )) + + handleErr(app.DistrKeeper.ValidatorOutstandingRewards.Set( + ctx, + validator, + distrtypes.ValidatorOutstandingRewards{Rewards: sdk.DecCoins{}}, + )) <%= if (!IsChainMinimal) { %> // SLASHING @@ -204,7 +214,6 @@ func initAppForTestnet(app *app.App, args valArgs) *app.App { defaultCoins := sdk.NewCoins(sdk.NewInt64Coin(bondDenom, 1000000000)) - // Fund local accounts // Fund local accounts for _, accountStr := range args.accountsToFund { err := app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, defaultCoins) @@ -267,3 +276,11 @@ func getCommandArgs(appOpts servertypes.AppOptions) (valArgs, error) { return args, nil } + +// handleErr prints the error and exits the program if the error is not nil +func handleErr(err error) { + if err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(1) + } +} \ No newline at end of file