Skip to content

Commit

Permalink
feat: remove deposit in case zero coins
Browse files Browse the repository at this point in the history
  • Loading branch information
ironman0x7b2 committed Feb 13, 2025
1 parent 3838dbe commit 1f56f13
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions x/deposit/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ func (k *Keeper) SetDeposit(ctx sdk.Context, deposit v1.Deposit) {
panic(err)
}

deposit.Coins = sdk.NewCoins(deposit.Coins...)
if deposit.Coins.IsZero() {
k.DeleteDeposit(ctx, addr)
return
}

store := k.Store(ctx)
key := types.DepositKey(addr)
value := k.cdc.MustMarshal(&deposit)
Expand Down Expand Up @@ -53,6 +59,14 @@ func (k *Keeper) GetDeposits(ctx sdk.Context) (items v1.Deposits) {
return items
}

// DeleteDeposit removes a deposit from the module's KVStore based on the address.
func (k *Keeper) DeleteDeposit(ctx sdk.Context, addr sdk.AccAddress) {
store := k.Store(ctx)
key := types.DepositKey(addr)

store.Delete(key)
}

// IterateDeposits iterates over all deposits stored in the module's KVStore and calls the provided function for each deposit.
// The iteration stops when the provided function returns 'true'.
func (k *Keeper) IterateDeposits(ctx sdk.Context, fn func(index int, item v1.Deposit) (stop bool)) {
Expand Down

0 comments on commit 1f56f13

Please sign in to comment.