Skip to content

Commit

Permalink
add check if duplicate host zone
Browse files Browse the repository at this point in the history
  • Loading branch information
GNaD13 committed Oct 31, 2023
1 parent 8beefb9 commit 83e6408
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions x/feeabs/keeper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ func (k Keeper) GetHostZoneConfig(ctx sdk.Context, ibcDenom string) (types.HostC
return chainConfig, true
}

func (k Keeper) HasHostZoneConfigByOsmosisTokenDenom(ctx sdk.Context, osmosisIbcDenom string) bool {
store := ctx.KVStore(k.storeKey)
key := types.GetKeyHostZoneConfigByOsmosisIBCDenom(osmosisIbcDenom)
return store.Has(key)
}

func (k Keeper) GetHostZoneConfigByOsmosisTokenDenom(ctx sdk.Context, osmosisIbcDenom string) (types.HostChainFeeAbsConfig, bool) {
store := ctx.KVStore(k.storeKey)
key := types.GetKeyHostZoneConfigByOsmosisIBCDenom(osmosisIbcDenom)
Expand Down
11 changes: 8 additions & 3 deletions x/feeabs/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/types"

errorsmod "cosmossdk.io/errors"
)

func (k Keeper) AddHostZoneProposal(ctx sdk.Context, p *types.AddHostZoneProposal) error {
_, found := k.GetHostZoneConfig(ctx, p.HostChainConfig.IbcDenom)
if found {
return types.ErrDuplicateHostZoneConfig
// Check if duplicate host zone
if k.HasHostZoneConfig(ctx, p.HostChainConfig.IbcDenom) {
return errorsmod.Wrapf(types.ErrDuplicateHostZoneConfig, "duplicate IBC denom")
}
if k.HasHostZoneConfigByOsmosisTokenDenom(ctx, p.HostChainConfig.OsmosisPoolTokenDenomIn) {
return errorsmod.Wrapf(types.ErrDuplicateHostZoneConfig, "duplicate Osmosis's IBC denom")
}

err := k.SetHostZoneConfig(ctx, *p.HostChainConfig)
Expand Down

0 comments on commit 83e6408

Please sign in to comment.