Skip to content

Commit

Permalink
fix: ibc quota iterator (#1761)
Browse files Browse the repository at this point in the history
## Description

1. uses new prefix store abstraction to deal with keys
2. fixes denom extranction

---

### Author Checklist

_All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues._

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] added appropriate labels to the PR
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/umee-network/umee/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

_All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items._

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
robert-zaremba authored Jan 31, 2023
1 parent 4bc2f8b commit 549ca9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
6 changes: 0 additions & 6 deletions x/uibc/keys.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package uibc

import (
"encoding/hex"

"github.com/umee-network/umee/v4/util"
)

Expand Down Expand Up @@ -30,7 +28,3 @@ func KeyTotalOutflows(ibcDenom string) []byte {
// KeyPrefixDenomQuota| denom
return util.ConcatBytes(0, KeyPrefixDenomQuota, []byte(ibcDenom))
}

func DenomFromKeyTotalOutflows(key []byte) string {
return hex.EncodeToString(key[2:])
}
11 changes: 6 additions & 5 deletions x/uibc/quota/keeper/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

sdkmath "cosmossdk.io/math"
prefixsore "github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
transfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types"
Expand Down Expand Up @@ -115,14 +116,14 @@ func (k Keeper) ResetQuota(ctx sdk.Context) error {
return err
}
k.SetTotalOutflowSum(ctx, zero)

store := ctx.KVStore(k.storeKey)
iter := sdk.KVStorePrefixIterator(store, uibc.KeyPrefixDenomQuota)
store = prefixsore.NewStore(store, uibc.KeyPrefixDenomQuota)
iter := sdk.KVStorePrefixIterator(store, nil)
defer iter.Close()
for ; iter.Valid(); iter.Next() {
ibcDenom := uibc.DenomFromKeyTotalOutflows(iter.Key())
q := uibc.Quota{IbcDenom: ibcDenom, OutflowSum: zero}
store.Set(uibc.KeyTotalOutflows(ibcDenom), k.cdc.MustMarshal(&q))
ibcDenom := iter.Key()
q := uibc.Quota{IbcDenom: string(ibcDenom), OutflowSum: zero}
store.Set(ibcDenom, k.cdc.MustMarshal(&q))
}
return nil
}
Expand Down

0 comments on commit 549ca9f

Please sign in to comment.