Skip to content

Commit

Permalink
lowercase tokenContract
Browse files Browse the repository at this point in the history
  • Loading branch information
kstoykov committed Sep 13, 2021
1 parent f97ca84 commit 0b68110
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion module/x/gravity/keeper/cosmos-originated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"fmt"
"strings"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -34,7 +35,7 @@ func (k Keeper) GetCosmosOriginatedERC20(ctx sdk.Context, denom string) (string,

func (k Keeper) setCosmosOriginatedDenomToERC20(ctx sdk.Context, denom string, tokenContract string) {
store := ctx.KVStore(k.storeKey)
store.Set(types.GetDenomToERC20Key(denom), []byte(tokenContract))
store.Set(types.GetDenomToERC20Key(denom), []byte(strings.ToLower(tokenContract)))
store.Set(types.GetERC20ToDenomKey(tokenContract), []byte(denom))
}

Expand Down
4 changes: 3 additions & 1 deletion module/x/gravity/keeper/keeper_batch.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"strings"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -40,7 +42,7 @@ func (k Keeper) SetBatchConfirm(ctx sdk.Context, batch *types.MsgConfirmBatch) [
// TODO: specify which nonce this is
func (k Keeper) IterateBatchConfirmByNonceAndTokenContract(ctx sdk.Context, nonce uint64, tokenContract string, cb func([]byte, types.MsgConfirmBatch) bool) {
prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.BatchConfirmKey)
prefix := append([]byte(tokenContract), types.UInt64Bytes(nonce)...)
prefix := append([]byte(strings.ToLower(tokenContract)), types.UInt64Bytes(nonce)...)
iter := prefixStore.Iterator(prefixRange(prefix))
defer iter.Close()

Expand Down
3 changes: 2 additions & 1 deletion module/x/gravity/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math/big"
"sort"
"strconv"
"strings"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -279,7 +280,7 @@ func (k Keeper) GetPoolTransactions(ctx sdk.Context) []*types.OutgoingTransferTx
// IterateOutgoingPoolByFee iterates over the outgoing pool which is sorted by fee
func (k Keeper) IterateOutgoingPoolByFee(ctx sdk.Context, contract string, cb func(uint64, *types.OutgoingTransferTx) bool) {
prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.SecondIndexOutgoingTXFeeKey)
iter := prefixStore.ReverseIterator(prefixRange([]byte(contract)))
iter := prefixStore.ReverseIterator(prefixRange([]byte(strings.ToLower(contract))))
defer iter.Close()
for ; iter.Valid(); iter.Next() {
var ids types.IDSet
Expand Down
6 changes: 3 additions & 3 deletions module/x/gravity/types/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func GetOutgoingTxPoolKey(id uint64) []byte {
// prefix nonce eth-contract-address
// [0xa][0 0 0 0 0 0 0 1][0xc783df8a850f42e7F7e57013759C285caa701eB6]
func GetOutgoingTxBatchKey(tokenContract string, nonce uint64) []byte {
return append(append(OutgoingTXBatchKey, []byte(tokenContract)...), UInt64Bytes(nonce)...)
return append(append(OutgoingTXBatchKey, []byte(strings.ToLower(tokenContract))...), UInt64Bytes(nonce)...)
}

// GetOutgoingTxBatchBlockKey returns the following key format
Expand All @@ -249,7 +249,7 @@ func GetOutgoingTxBatchBlockKey(block uint64) []byte {
// TODO this should be a sdk.ValAddress
func GetBatchConfirmKey(tokenContract string, batchNonce uint64, validator sdk.AccAddress) []byte {
a := append(UInt64Bytes(batchNonce), validator.Bytes()...)
b := append([]byte(tokenContract), a...)
b := append([]byte(strings.ToLower(tokenContract)), a...)
c := append(BatchConfirmKey, b...)
return c
}
Expand All @@ -265,7 +265,7 @@ func GetFeeSecondIndexKey(fee ERC20Token) []byte {
amount = fee.Amount.BigInt().FillBytes(amount)
// TODO this won't ever work fix it
copy(r[0:], SecondIndexOutgoingTXFeeKey)
copy(r[len(SecondIndexOutgoingTXFeeKey):], []byte(fee.Contract))
copy(r[len(SecondIndexOutgoingTXFeeKey):], []byte(strings.ToLower(fee.Contract)))
copy(r[len(SecondIndexOutgoingTXFeeKey)+len(fee.Contract):], amount)
return r
}
Expand Down

0 comments on commit 0b68110

Please sign in to comment.