Skip to content

Commit ac4a066

Browse files
mergify[bot]reecepbcupsjulienrbrt
authored
feat: add more coins after add-genesis-account is made (backport #13233) (#13261)
* feat: add more coins after add-genesis-account is made (#13233) (cherry picked from commit c32493a) # Conflicts: # CHANGELOG.md * updates Co-authored-by: Reece Williams <31943163+Reecepbcups@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
1 parent 78336ef commit ac4a066

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
3939

4040
### API Breaking Changes
4141

42-
- (cli) [#13089](https://github.com/cosmos/cosmos-sdk/pull/13089) Fix rollback command don't actually delete multistore versions, added method `RollbackToVersion` to interface `CommitMultiStore` and added method `CommitMultiStore` to `Application` interface.
42+
* (cli) [#13089](https://github.com/cosmos/cosmos-sdk/pull/13089) Fix rollback command don't actually delete multistore versions, added method `RollbackToVersion` to interface `CommitMultiStore` and added method `CommitMultiStore` to `Application` interface.
4343

4444
### Features
4545

@@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4848

4949
### Improvements
5050

51+
* [#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.
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.

simapp/simd/cmd/genaccounts.go

Lines changed: 34 additions & 19 deletions
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)