Skip to content

Commit e2a7735

Browse files
Reecepbcupsmergify[bot]
authored andcommitted
feat: add more coins after add-genesis-account is made (#13233)
(cherry picked from commit c32493a) # Conflicts: # CHANGELOG.md
1 parent 70943c6 commit e2a7735

File tree

2 files changed

+69
-19
lines changed

2 files changed

+69
-19
lines changed

CHANGELOG.md

+35
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,44 @@ Ref: https://keepachangelog.com/en/1.0.0/
4848

4949
### Improvements
5050

51+
<<<<<<< HEAD
5152
* (x/group) [#13214](https://github.com/cosmos/cosmos-sdk/pull/13214) Add `withdraw-proposal` command to group module's CLI transaction commands.
5253
* (x/auth) [#13048](https://github.com/cosmos/cosmos-sdk/pull/13048) Add handling of AccountNumberStoreKeyPrefix to the simulation decoder.
5354
* (simapp) [#13108](https://github.com/cosmos/cosmos-sdk/pull/13108) Call `SetIAVLCacheSize` with the configured value in simapp.
55+
=======
56+
* [#13214](https://github.com/cosmos/cosmos-sdk/pull/13214) Add `withdraw-proposal` command to group module's CLI transaction commands.
57+
* [#13070](https://github.com/cosmos/cosmos-sdk/pull/13070) Migrate from `gogo/protobuf` to `cosmos/gogoproto`.
58+
* [#12981](https://github.com/cosmos/cosmos-sdk/pull/12981) Return proper error when parsing telemetry configuration.
59+
* [#12995](https://github.com/cosmos/cosmos-sdk/pull/12995) Add `FormatTime` and `ParseTimeString` methods.
60+
* [#12952](https://github.com/cosmos/cosmos-sdk/pull/12952) Replace keyring module to Cosmos fork.
61+
* [#12352](https://github.com/cosmos/cosmos-sdk/pull/12352) Move the `RegisterSwaggerAPI` logic into a separate helper function in the server package.
62+
* [#12876](https://github.com/cosmos/cosmos-sdk/pull/12876) Remove proposer-based rewards.
63+
* [#12892](https://github.com/cosmos/cosmos-sdk/pull/12892) `make format` now runs only gofumpt and golangci-lint run ./... --fix, replacing `goimports` `gofmt` and `misspell`
64+
* [#12846](https://github.com/cosmos/cosmos-sdk/pull/12846) Remove `RandomizedParams` from the `AppModuleSimulation` interface which is no longer needed.
65+
* (events) [#12850](https://github.com/cosmos/cosmos-sdk/pull/12850) Add a new `fee_payer` attribute to the `tx` event that is emitted from the `DeductFeeDecorator` AnteHandler decorator.
66+
* (ci) [#12854](https://github.com/cosmos/cosmos-sdk/pull/12854) Use ghcr.io to host the proto builder image. Update proto builder image to go 1.19
67+
* (x/bank) [#12706](https://github.com/cosmos/cosmos-sdk/pull/12706) Added the `chain-id` flag to the `AddTxFlagsToCmd` API. There is no longer a need to explicitly register this flag on commands whens `AddTxFlagsToCmd` is already called.
68+
* [#12791](https://github.com/cosmos/cosmos-sdk/pull/12791) Bump the math library used in the sdk and replace old usages of sdk.\*
69+
* (x/params) [#12615](https://github.com/cosmos/cosmos-sdk/pull/12615) Add `GetParamSetIfExists` function to params `Subspace` to prevent panics on breaking changes.
70+
* [#12717](https://github.com/cosmos/cosmos-sdk/pull/12717) Use injected encoding params in simapp.
71+
* (x/bank) [#12674](https://github.com/cosmos/cosmos-sdk/pull/12674) Add convenience function `CreatePrefixedAccountStoreKey()` to construct key to access account's balance for a given denom.
72+
* [#12702](https://github.com/cosmos/cosmos-sdk/pull/12702) Linting and tidiness, fixed two minor security warnings.
73+
* [#12634](https://github.com/cosmos/cosmos-sdk/pull/12634) Move `sdk.Dec` to math package.
74+
* [#12596](https://github.com/cosmos/cosmos-sdk/pull/12596) Remove all imports of the non-existent gogo/protobuf v1.3.3 to ease downstream use and go workspaces.
75+
* [#12187](https://github.com/cosmos/cosmos-sdk/pull/12187) Add batch operation for x/nft module.
76+
* [#12693](https://github.com/cosmos/cosmos-sdk/pull/12693) Make sure the order of each node is consistent when emitting proto events.
77+
* [#12455](https://github.com/cosmos/cosmos-sdk/pull/12455) Show attempts count in error for signing.
78+
* [#12886](https://github.com/cosmos/cosmos-sdk/pull/12886) Amortize cost of processing cache KV store
79+
* [#12953](https://github.com/cosmos/cosmos-sdk/pull/12953) Change the default priority mechanism to be based on gas price.
80+
* [#13048](https://github.com/cosmos/cosmos-sdk/pull/13048) Add handling of AccountNumberStoreKeyPrefix to the x/auth simulation decoder.
81+
* [#13101](https://github.com/cosmos/cosmos-sdk/pull/13101) Remove weights from `simapp/params` and `testutil/sims`. They are now in their respective modules.
82+
* (simapp) [#13107](https://github.com/cosmos/cosmos-sdk/pull/13107) Call `SetIAVLCacheSize` with the configured value in simapp.
83+
* [#12398](https://github.com/cosmos/cosmos-sdk/issues/12398) Refactor all `x` modules to unit-test via mocks and decouple `simapp`.
84+
* [#13144](https://github.com/cosmos/cosmos-sdk/pull/13144) Add validator distribution info grpc gateway get endpoint.
85+
* [#13168](https://github.com/cosmos/cosmos-sdk/pull/13168) Migrate tendermintdev/proto-builder to ghcr.io. New image `ghcr.io/cosmos/proto-builder:0.8`
86+
* [#13233](https://github.com/cosmos/cosmos-sdk/pull/13233) Add `--append` to `add-genesis-account` sub-command to append new tokens after an account is already created.
87+
* [#13236](https://github.com/cosmos/cosmos-sdk/pull/13236) Integrate Filter Logging
88+
>>>>>>> c32493a5b (feat: add more coins after add-genesis-account is made (#13233))
5489
5590
### Bug Fixes
5691

simapp/simd/cmd/genaccounts.go

+34-19
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const (
2424
flagVestingStart = "vesting-start-time"
2525
flagVestingEnd = "vesting-end-time"
2626
flagVestingAmt = "vesting-amount"
27+
flagAppendMode = "append"
2728
)
2829

2930
// AddGenesisAccountCmd returns add-genesis-account cobra Command.
@@ -130,38 +131,51 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
130131
return fmt.Errorf("failed to get accounts from any: %w", err)
131132
}
132133

134+
bankGenState := banktypes.GetGenesisStateFromAppState(clientCtx.Codec, appState)
133135
if accs.Contains(addr) {
134-
return fmt.Errorf("cannot add account at existing address %s", addr)
135-
}
136+
appendflag, _ := cmd.Flags().GetBool(flagAppendMode)
137+
if !appendflag {
138+
return fmt.Errorf("cannot add account at existing address %s", addr)
139+
}
136140

137-
// Add the new account to the set of genesis accounts and sanitize the
138-
// accounts afterwards.
139-
accs = append(accs, genAccount)
140-
accs = authtypes.SanitizeGenesisAccounts(accs)
141+
genesisB := banktypes.GetGenesisStateFromAppState(clientCtx.Codec, appState)
142+
for idx, acc := range genesisB.Balances {
143+
if acc.Address != addr.String() {
144+
continue
145+
}
141146

142-
genAccs, err := authtypes.PackAccounts(accs)
143-
if err != nil {
144-
return fmt.Errorf("failed to convert accounts into any's: %w", err)
145-
}
146-
authGenState.Accounts = genAccs
147+
updatedCoins := acc.Coins.Add(coins...)
148+
bankGenState.Balances[idx] = banktypes.Balance{Address: addr.String(), Coins: updatedCoins.Sort()}
149+
break
150+
}
151+
} else {
152+
// Add the new account to the set of genesis accounts and sanitize the accounts afterwards.
153+
accs = append(accs, genAccount)
154+
accs = authtypes.SanitizeGenesisAccounts(accs)
147155

148-
authGenStateBz, err := clientCtx.Codec.MarshalJSON(&authGenState)
149-
if err != nil {
150-
return fmt.Errorf("failed to marshal auth genesis state: %w", err)
151-
}
156+
genAccs, err := authtypes.PackAccounts(accs)
157+
if err != nil {
158+
return fmt.Errorf("failed to convert accounts into any's: %w", err)
159+
}
160+
authGenState.Accounts = genAccs
152161

153-
appState[authtypes.ModuleName] = authGenStateBz
162+
authGenStateBz, err := clientCtx.Codec.MarshalJSON(&authGenState)
163+
if err != nil {
164+
return fmt.Errorf("failed to marshal auth genesis state: %w", err)
165+
}
166+
appState[authtypes.ModuleName] = authGenStateBz
167+
168+
bankGenState.Balances = append(bankGenState.Balances, balances)
169+
}
154170

155-
bankGenState := banktypes.GetGenesisStateFromAppState(clientCtx.Codec, appState)
156-
bankGenState.Balances = append(bankGenState.Balances, balances)
157171
bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances)
172+
158173
bankGenState.Supply = bankGenState.Supply.Add(balances.Coins...)
159174

160175
bankGenStateBz, err := clientCtx.Codec.MarshalJSON(bankGenState)
161176
if err != nil {
162177
return fmt.Errorf("failed to marshal bank genesis state: %w", err)
163178
}
164-
165179
appState[banktypes.ModuleName] = bankGenStateBz
166180

167181
appStateJSON, err := json.Marshal(appState)
@@ -179,6 +193,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
179193
cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts")
180194
cmd.Flags().Int64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts")
181195
cmd.Flags().Int64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts")
196+
cmd.Flags().Bool(flagAppendMode, false, "append the coins to an account already in the genesis.json file")
182197
flags.AddQueryFlagsToCmd(cmd)
183198

184199
return cmd

0 commit comments

Comments
 (0)