Skip to content

Commit

Permalink
dont double append prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Jan 9, 2024
1 parent 709b70d commit b83740e
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions osmoutils/store_helper.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package osmoutils

import (
"bytes"
"errors"
"fmt"
"strings"

db "github.com/cometbft/cometbft-db"
"github.com/cosmos/cosmos-sdk/store/prefix"
Expand Down Expand Up @@ -238,12 +238,8 @@ func GetCoinArrayFromPrefix(ctx sdk.Context, storeKey storetypes.StoreKey, store
bz := iterator.Value()
sdkInt := osmomath.Int{}
if err := sdkInt.Unmarshal(bz); err == nil {
// Split the key into prefix and denom
keyParts := strings.Split(string(iterator.Key()), "|")
if len(keyParts) > 1 {
denom := keyParts[1]
coinArray = append(coinArray, sdk.NewCoin(denom, sdkInt))
}
denom := bytes.TrimPrefix(iterator.Key(), storePrefix)
coinArray = append(coinArray, sdk.NewCoin(string(denom), sdkInt))
}
}

Expand All @@ -254,7 +250,7 @@ func GetCoinArrayFromPrefix(ctx sdk.Context, storeKey storetypes.StoreKey, store
// If the denom is not found, a zero coin is returned.
func GetCoinByDenomFromPrefix(ctx sdk.Context, storeKey storetypes.StoreKey, storePrefix []byte, denom string) (sdk.Coin, error) {
store := prefix.NewStore(ctx.KVStore(storeKey), storePrefix)
key := []byte(fmt.Sprintf("%s%s%s", storePrefix, "|", []byte(denom)))
key := []byte(denom)

bz := store.Get(key)
if len(bz) == 0 {
Expand All @@ -272,7 +268,7 @@ func GetCoinByDenomFromPrefix(ctx sdk.Context, storeKey storetypes.StoreKey, sto
// IncreaseCoinByDenomFromPrefix increases the coin from the store that has the given prefix and denom by the specified amount.
func IncreaseCoinByDenomFromPrefix(ctx sdk.Context, storeKey storetypes.StoreKey, storePrefix []byte, denom string, increasedAmt osmomath.Int) error {
store := prefix.NewStore(ctx.KVStore(storeKey), storePrefix)
key := []byte(fmt.Sprintf("%s%s%s", storePrefix, "|", []byte(denom)))
key := []byte(denom)

coin, err := GetCoinByDenomFromPrefix(ctx, storeKey, storePrefix, denom)
if err != nil {
Expand Down

0 comments on commit b83740e

Please sign in to comment.