From 7af99332e6625ea1cc640ebabaedaf6fa4ee68e2 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Thu, 28 Mar 2024 22:51:09 +0000 Subject: [PATCH] fixes #1340; remove superfluous []byte() casts for strings in append (#1360) * fixes #1340; remove superfluous []byte() casts for strings in append * remove existing unneccessary cast --------- Co-authored-by: Tuan Tran --- third-party-chains/osmosis-types/gamm/key.go | 2 +- .../osmosis-types/osmomath/decimal.go | 2 +- utils/coins_test.go | 8 ++-- x/airdrop/spec/README.md | 41 +++++++++---------- x/airdrop/types/keys.go | 6 +-- x/airdrop/types/keys_test.go | 6 +-- .../keeper/self_consensus_state.go | 6 +-- x/claimsmanager/spec/README.md | 19 ++++----- x/claimsmanager/types/keys.go | 24 +++++------ x/claimsmanager/types/keys_test.go | 24 +++++------ x/interchainstaking/keeper/callbacks.go | 2 +- x/interchainstaking/keeper/callbacks_test.go | 32 +++++++-------- x/interchainstaking/keeper/delegation.go | 4 +- x/interchainstaking/keeper/intent.go | 4 +- x/interchainstaking/keeper/keeper.go | 2 +- x/interchainstaking/keeper/zones.go | 4 +- x/interchainstaking/types/keys.go | 22 +++++----- .../keeper/callbacks_test.go | 2 +- x/participationrewards/keeper/grpc_query.go | 2 +- .../keeper/msg_server_test.go | 4 +- .../keeper/submodule_umee.go | 2 +- 21 files changed, 108 insertions(+), 110 deletions(-) diff --git a/third-party-chains/osmosis-types/gamm/key.go b/third-party-chains/osmosis-types/gamm/key.go index 40eeaea26..dd0918b65 100644 --- a/third-party-chains/osmosis-types/gamm/key.go +++ b/third-party-chains/osmosis-types/gamm/key.go @@ -46,7 +46,7 @@ func ValidatePoolShareDenom(denom string) error { } func GetDenomPrefix(denom string) []byte { - return append(KeyTotalLiquidity, []byte(denom)...) + return append(KeyTotalLiquidity, denom...) } func GetPoolShareDenom(poolId uint64) string { diff --git a/third-party-chains/osmosis-types/osmomath/decimal.go b/third-party-chains/osmosis-types/osmomath/decimal.go index b6aa442ad..58f4927b1 100644 --- a/third-party-chains/osmosis-types/osmomath/decimal.go +++ b/third-party-chains/osmosis-types/osmomath/decimal.go @@ -655,7 +655,7 @@ func SortableDecBytes(dec BigDec) []byte { } // We move the negative sign to the front of all the left padded 0s, to make negative numbers come before positive numbers if dec.IsNegative() { - return append([]byte("-"), []byte(fmt.Sprintf(fmt.Sprintf("%%0%ds", Precision*2+1), dec.Abs().String()))...) + return append([]byte("-"), fmt.Sprintf(fmt.Sprintf("%%0%ds", Precision*2+1), dec.Abs().String())...) } return []byte(fmt.Sprintf(fmt.Sprintf("%%0%ds", Precision*2+1), dec.String())) } diff --git a/utils/coins_test.go b/utils/coins_test.go index 8b613d6c7..e5db551d4 100644 --- a/utils/coins_test.go +++ b/utils/coins_test.go @@ -25,7 +25,7 @@ func TestDenomFromRequestKey(t *testing.T) { func() (sdk.AccAddress, []byte) { accAddr := addressutils.GenerateAccAddressForTest() key := banktypes.CreateAccountBalancesPrefix(accAddr.Bytes()) - key = append(key, []byte(expectedDenom)...) + key = append(key, expectedDenom...) return accAddr, key }, "", @@ -38,7 +38,7 @@ func TestDenomFromRequestKey(t *testing.T) { checkAddr, err := addressutils.AccAddressFromBech32("cosmos1ent5eg0xn3pskf3fhdw8mky88ry7t4kx628ru3pzp4nqjp6eufusphlldy", "cosmos") require.NoError(t, err) key := banktypes.CreateAccountBalancesPrefix(keyAddr.Bytes()) - key = append(key, []byte(expectedDenom)...) + key = append(key, expectedDenom...) return checkAddr, key }, "account mismatch; expected cosmos135rd8ft0dyq8fv3w3hhmaa55qu3pe668j99qh67mg747ew4ad03qsgq8vh, got cosmos1ent5eg0xn3pskf3fhdw8mky88ry7t4kx628ru3pzp4nqjp6eufusphlldy", @@ -48,7 +48,7 @@ func TestDenomFromRequestKey(t *testing.T) { func() (sdk.AccAddress, []byte) { accAddr := sdk.AccAddress{} key := banktypes.CreateAccountBalancesPrefix(accAddr.Bytes()) - key = append(key, []byte(expectedDenom)...) + key = append(key, expectedDenom...) return accAddr, key }, "invalid key", @@ -58,7 +58,7 @@ func TestDenomFromRequestKey(t *testing.T) { func() (sdk.AccAddress, []byte) { accAddr := addressutils.GenerateAccAddressForTest() key := banktypes.CreateAccountBalancesPrefix(accAddr.Bytes()) - key = append(key, []byte("")...) + key = append(key, ""...) return accAddr, key }, "key contained no denom", diff --git a/x/airdrop/spec/README.md b/x/airdrop/spec/README.md index 05958be9c..9f4999e7f 100644 --- a/x/airdrop/spec/README.md +++ b/x/airdrop/spec/README.md @@ -6,10 +6,10 @@ The purpose of this module is to distribute QCK airdrops to users for engaging i **Objectives:** -* Provide airdrop to qualifying users; -* Couple airdrop to specific actions or tasks; -* Airdrops configured on a per zone basis; -* Must decay to zero over a specified period, starting at a specific time / block height; +- Provide airdrop to qualifying users; +- Couple airdrop to specific actions or tasks; +- Airdrops configured on a per zone basis; +- Must decay to zero over a specified period, starting at a specific time / block height; ## Contents @@ -44,9 +44,9 @@ A `ZoneDrop` is considered `Active` if, and only if, the current `BlockTime` is **Formula:** -* active: `BlockTime` > `StartTime` && `BlockTime` < `StartTime`+`Duration`+`Decay`; -* future: `BlockTime` < `StartTime`; -* expired: `BlockTime` > `StartTime`+`Duration`+`Decay`; +- active: `BlockTime` > `StartTime` && `BlockTime` < `StartTime`+`Duration`+`Decay`; +- future: `BlockTime` < `StartTime`; +- expired: `BlockTime` > `StartTime`+`Duration`+`Decay`; #### Duration & Decay @@ -159,7 +159,7 @@ var ( ) func GetKeyZoneDrop(chainID string) []byte { - return append(KeyPrefixZoneDrop, []byte(chainID)...) + return append(KeyPrefixZoneDrop, chainID...) } // ZoneDrop represents an airdrop for a specific zone. @@ -182,11 +182,11 @@ var ( ) func GetKeyClaimRecord(chainID string, addr sdk.AccAddress) []byte { - return append(append(KeyPrefixClaimRecord, []byte(chainID)...), addr...) + return append(append(KeyPrefixClaimRecord, chainID...), addr...) } func GetPrefixClaimRecord(chainID string) []byte { - return append(KeyPrefixClaimRecord, []byte(chainID)...) + return append(KeyPrefixClaimRecord, chainID...) } // ClaimRecord represents a users' claim (including completed claims) for a @@ -265,18 +265,18 @@ Events emitted by module for tracking messages and index transactions; ### RegisterZoneDropProposal | Type | Attribute Key | Attribute Value | -|:------------------|:--------------|:----------------| +| :---------------- | :------------ | :-------------- | | message | module | airdrop | | register_zonedrop | chain_id | {chain_id} | ### MsgClaim -| Type | Attribute Key | Attribute Value | -|:------------------|:--------------|:----------------| -| airdrop_claim | sender | {address} | -| airdrop_claim | zone | {chain_id} | -| airdrop_claim | action | {action} | -| airdrop_claim | amount | {amount} | +| Type | Attribute Key | Attribute Value | +| :------------ | :------------ | :-------------- | +| airdrop_claim | sender | {address} | +| airdrop_claim | zone | {chain_id} | +| airdrop_claim | action | {action} | +| airdrop_claim | amount | {amount} | ## Hooks @@ -432,12 +432,12 @@ type QueryClaimRecordResponse struct { Module parameters: -| Key | Type | Example | -|:-- ---|:-- ---|:-- ---| +| Key | Type | Example | +| :-- | :--- | :------ | Description of parameters: -* `param_name` - short description; +- `param_name` - short description; ## Proposals @@ -459,4 +459,3 @@ N/A ## End Block At the end of every block the module iterates through all unconcluded airdrops (expired but not yet concluded) and calls `EndZoneDrop` for each instance, that deletes all associated `ClaimRecord`s. - diff --git a/x/airdrop/types/keys.go b/x/airdrop/types/keys.go index 2480b8712..575d1160a 100644 --- a/x/airdrop/types/keys.go +++ b/x/airdrop/types/keys.go @@ -21,13 +21,13 @@ var ( ) func GetKeyZoneDrop(chainID string) []byte { - return append(KeyPrefixZoneDrop, []byte(chainID)...) + return append(KeyPrefixZoneDrop, chainID...) } func GetKeyClaimRecord(chainID string, addr sdk.AccAddress) []byte { - return append(append(KeyPrefixClaimRecord, []byte(chainID)...), addr...) + return append(append(KeyPrefixClaimRecord, chainID...), addr...) } func GetPrefixClaimRecord(chainID string) []byte { - return append(KeyPrefixClaimRecord, []byte(chainID)...) + return append(KeyPrefixClaimRecord, chainID...) } diff --git a/x/airdrop/types/keys_test.go b/x/airdrop/types/keys_test.go index 04110e9b7..b71025bf0 100644 --- a/x/airdrop/types/keys_test.go +++ b/x/airdrop/types/keys_test.go @@ -27,7 +27,7 @@ func TestGetKeyZoneDrop(t *testing.T) { args{ chainID: testID, }, - append([]byte{0x1}, []byte(testID)...), + append([]byte{0x1}, testID...), }, } for _, tt := range tests { @@ -61,7 +61,7 @@ func TestGetKeyClaimRecord(t *testing.T) { chainID: testID, addr: testAcc, }, - append(append([]byte{0x2}, []byte(testID)...), testAcc...), + append(append([]byte{0x2}, testID...), testAcc...), }, } for _, tt := range tests { @@ -92,7 +92,7 @@ func TestGetPrefixClaimRecord(t *testing.T) { args{ chainID: testID, }, - append([]byte{0x2}, []byte(testID)...), + append([]byte{0x2}, testID...), }, } for _, tt := range tests { diff --git a/x/claimsmanager/keeper/self_consensus_state.go b/x/claimsmanager/keeper/self_consensus_state.go index d8129531d..b694fea91 100644 --- a/x/claimsmanager/keeper/self_consensus_state.go +++ b/x/claimsmanager/keeper/self_consensus_state.go @@ -13,7 +13,7 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, key string) (ibctmtypes.C store := ctx.KVStore(k.storeKey) var selfConsensusState ibctmtypes.ConsensusState - bz := store.Get(append(types.KeySelfConsensusState, []byte(key)...)) + bz := store.Get(append(types.KeySelfConsensusState, key...)) if bz == nil { return selfConsensusState, false } @@ -24,11 +24,11 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, key string) (ibctmtypes.C // SetSelfConsensusState sets the self consensus state. func (k Keeper) SetSelfConsensusState(ctx sdk.Context, key string, consState *ibctmtypes.ConsensusState) { store := ctx.KVStore(k.storeKey) - store.Set(append(types.KeySelfConsensusState, []byte(key)...), k.cdc.MustMarshal(consState)) + store.Set(append(types.KeySelfConsensusState, key...), k.cdc.MustMarshal(consState)) } // DeleteSelfConsensusState deletes the self consensus state. func (k Keeper) DeleteSelfConsensusState(ctx sdk.Context, key string) { store := ctx.KVStore(k.storeKey) - store.Delete(append(types.KeySelfConsensusState, []byte(key)...)) + store.Delete(append(types.KeySelfConsensusState, key...)) } diff --git a/x/claimsmanager/spec/README.md b/x/claimsmanager/spec/README.md index 1234df60a..6bd6d5e0a 100644 --- a/x/claimsmanager/spec/README.md +++ b/x/claimsmanager/spec/README.md @@ -67,11 +67,11 @@ var ( func GetGenericKeyClaim(key []byte, chainID string, address string, module ClaimType, srcChainID string) []byte { typeBytes := make([]byte, 4) binary.BigEndian.PutUint32(typeBytes, uint32(module)) - key = append(key, []byte(chainID)...) + key = append(key, chainID...) key = append(key, byte(0x00)) - key = append(key, []byte(address)...) + key = append(key, address...) key = append(key, typeBytes...) - return append(key, []byte(srcChainID)...) + return append(key, srcChainID...) } func GetKeyClaim(chainID string, address string, module ClaimType, srcChainID string) []byte { @@ -79,14 +79,14 @@ func GetKeyClaim(chainID string, address string, module ClaimType, srcChainID st } func GetPrefixClaim(chainID string) []byte { - return append(KeyPrefixClaim, []byte(chainID)...) + return append(KeyPrefixClaim, chainID...) } func GetPrefixUserClaim(chainID string, address string) []byte { key := KeyPrefixClaim - key = append(key, []byte(chainID)...) + key = append(key, chainID...) key = append(key, byte(0x00)) - key = append(key, []byte(address)...) + key = append(key, address...) return key } @@ -95,14 +95,14 @@ func GetKeyLastEpochClaim(chainID string, address string, module ClaimType, srcC } func GetPrefixLastEpochClaim(chainID string) []byte { - return append(KeyPrefixLastEpochClaim, []byte(chainID)...) + return append(KeyPrefixLastEpochClaim, chainID...) } func GetPrefixLastEpochUserClaim(chainID string, address string) []byte { key := KeyPrefixLastEpochClaim - key = append(key, []byte(chainID)...) + key = append(key, chainID...) key = append(key, byte(0x00)) - key = append(key, []byte(address)...) + key = append(key, address...) return key } @@ -210,4 +210,3 @@ N/A ## End Block N/A - diff --git a/x/claimsmanager/types/keys.go b/x/claimsmanager/types/keys.go index ac839f164..7d14662c4 100644 --- a/x/claimsmanager/types/keys.go +++ b/x/claimsmanager/types/keys.go @@ -23,11 +23,11 @@ var ( func GetGenericKeyClaim(key []byte, chainID, address string, module ClaimType, srcChainID string) []byte { typeBytes := make([]byte, 4) binary.BigEndian.PutUint32(typeBytes, uint32(module)) - key = append(key, []byte(chainID)...) - key = append(key, byte(0x00)) - key = append(key, []byte(address)...) + key = append(key, chainID...) + key = append(key, 0x00) + key = append(key, address...) key = append(key, typeBytes...) - return append(key, []byte(srcChainID)...) + return append(key, srcChainID...) } func GetKeyClaim(chainID, address string, module ClaimType, srcChainID string) []byte { @@ -35,14 +35,14 @@ func GetKeyClaim(chainID, address string, module ClaimType, srcChainID string) [ } func GetPrefixClaim(chainID string) []byte { - return append(KeyPrefixClaim, []byte(chainID)...) + return append(KeyPrefixClaim, chainID...) } func GetPrefixUserClaim(chainID, address string) []byte { key := KeyPrefixClaim - key = append(key, []byte(chainID)...) - key = append(key, byte(0x00)) - key = append(key, []byte(address)...) + key = append(key, chainID...) + key = append(key, 0x00) + key = append(key, address...) return key } @@ -51,13 +51,13 @@ func GetKeyLastEpochClaim(chainID, address string, module ClaimType, srcChainID } func GetPrefixLastEpochClaim(chainID string) []byte { - return append(KeyPrefixLastEpochClaim, []byte(chainID)...) + return append(KeyPrefixLastEpochClaim, chainID...) } func GetPrefixLastEpochUserClaim(chainID, address string) []byte { key := KeyPrefixLastEpochClaim - key = append(key, []byte(chainID)...) - key = append(key, byte(0x00)) - key = append(key, []byte(address)...) + key = append(key, chainID...) + key = append(key, 0x00) + key = append(key, address...) return key } diff --git a/x/claimsmanager/types/keys_test.go b/x/claimsmanager/types/keys_test.go index c3a7e3c73..749c61adc 100644 --- a/x/claimsmanager/types/keys_test.go +++ b/x/claimsmanager/types/keys_test.go @@ -14,19 +14,19 @@ func TestKeys(t *testing.T) { // zone prefixClaim := types.GetPrefixClaim("testzone-1") - require.Equal(t, append(types.KeyPrefixClaim, []byte("testzone-1")...), prefixClaim) + require.Equal(t, append(types.KeyPrefixClaim, "testzone-1"...), prefixClaim) expected := types.KeyPrefixClaim - expected = append(expected, []byte("testzone-1")...) - expected = append(expected, byte(0x00)) - expected = append(expected, []byte(address.String())...) + expected = append(expected, "testzone-1"...) + expected = append(expected, 0x00) + expected = append(expected, address.String()...) // zone + user prefixUserClaim := types.GetPrefixUserClaim("testzone-1", address.String()) require.Equal(t, expected, prefixUserClaim) - expected = append(expected, []byte{0x00, 0x00, 0x00, 0x02}...) - expected = append(expected, []byte("testzone-2")...) + expected = append(expected, 0x00, 0x00, 0x00, 0x02) + expected = append(expected, "testzone-2"...) // zone + user + claimType + srcZone keyClaim := types.GetKeyClaim("testzone-1", address.String(), types.ClaimTypeOsmosisPool, "testzone-2") @@ -38,19 +38,19 @@ func TestLastEpochKeys(t *testing.T) { // zone prefixClaim := types.GetPrefixLastEpochClaim("testzone-1") - require.Equal(t, append(types.KeyPrefixLastEpochClaim, []byte("testzone-1")...), prefixClaim) + require.Equal(t, append(types.KeyPrefixLastEpochClaim, "testzone-1"...), prefixClaim) expected := types.KeyPrefixLastEpochClaim - expected = append(expected, []byte("testzone-1")...) - expected = append(expected, byte(0x00)) - expected = append(expected, []byte(address.String())...) + expected = append(expected, "testzone-1"...) + expected = append(expected, 0x00) + expected = append(expected, address.String()...) // zone + user prefixUserClaim := types.GetPrefixLastEpochUserClaim("testzone-1", address.String()) require.Equal(t, expected, prefixUserClaim) - expected = append(expected, []byte{0x00, 0x00, 0x00, 0x02}...) - expected = append(expected, []byte("testzone-2")...) + expected = append(expected, 0x00, 0x00, 0x00, 0x02) + expected = append(expected, "testzone-2"...) // zone + user + claimType + srcZone keyClaim := types.GetKeyLastEpochClaim("testzone-1", address.String(), types.ClaimTypeOsmosisPool, "testzone-2") diff --git a/x/interchainstaking/keeper/callbacks.go b/x/interchainstaking/keeper/callbacks.go index ddd9e03d7..3b29ade0e 100644 --- a/x/interchainstaking/keeper/callbacks.go +++ b/x/interchainstaking/keeper/callbacks.go @@ -703,7 +703,7 @@ func DelegationAccountBalancesCallback(k *Keeper, ctx sdk.Context, args []byte, zone.ConnectionId, zone.ChainId, types.BankStoreKey, - append(banktypes.CreateAccountBalancesPrefix(addressBytes), []byte(coin.Denom)...), + append(banktypes.CreateAccountBalancesPrefix(addressBytes), coin.Denom...), sdk.NewInt(-1), types.ModuleName, "delegationaccountbalance", diff --git a/x/interchainstaking/keeper/callbacks_test.go b/x/interchainstaking/keeper/callbacks_test.go index 11bcb746e..7d45d8d5e 100644 --- a/x/interchainstaking/keeper/callbacks_test.go +++ b/x/interchainstaking/keeper/callbacks_test.go @@ -1105,7 +1105,7 @@ func (suite *KeeperTestSuite) TestAllBalancesCallback() { if queryInfo.ChainId == zone.ChainId && queryInfo.ConnectionId == zone.ConnectionId && queryInfo.QueryType == icstypes.BankStoreKey && - bytes.Equal(queryInfo.Request, append(data, []byte(response.Balances[0].GetDenom())...)) { + bytes.Equal(queryInfo.Request, append(data, response.Balances[0].GetDenom()...)) { found = true return true } @@ -1155,7 +1155,7 @@ func (suite *KeeperTestSuite) TestAllBalancesCallbackWithExistingWg() { if queryInfo.ChainId == zone.ChainId && queryInfo.ConnectionId == zone.ConnectionId && queryInfo.QueryType == icstypes.BankStoreKey && - bytes.Equal(queryInfo.Request, append(data, []byte(response.Balances[0].GetDenom())...)) { + bytes.Equal(queryInfo.Request, append(data, response.Balances[0].GetDenom()...)) { found = true return true } @@ -1208,7 +1208,7 @@ func (suite *KeeperTestSuite) TestAllBalancesCallbackExistingBalanceNowNil() { if queryInfo.ChainId == zone.ChainId && queryInfo.ConnectionId == zone.ConnectionId && queryInfo.QueryType == icstypes.BankStoreKey && - bytes.Equal(queryInfo.Request, append(data, []byte("uqck")...)) { + bytes.Equal(queryInfo.Request, append(data, "uqck"...)) { found = true return true } @@ -1256,7 +1256,7 @@ func (suite *KeeperTestSuite) TestAllBalancesCallbackExistingBalanceNowNil() { if queryInfo.ChainId == zone.ChainId && queryInfo.ConnectionId == zone.ConnectionId && queryInfo.QueryType == icstypes.BankStoreKey && - bytes.Equal(queryInfo.Request, append(data, []byte("uqck")...)) { + bytes.Equal(queryInfo.Request, append(data, "uqck"...)) { found = true return true } @@ -1305,7 +1305,7 @@ func (suite *KeeperTestSuite) TestAllBalancesCallbackMulti() { if queryInfo.ChainId == zone.ChainId && queryInfo.ConnectionId == zone.ConnectionId && queryInfo.QueryType == icstypes.BankStoreKey && - bytes.Equal(queryInfo.Request, append(data, []byte(coin.GetDenom())...)) { + bytes.Equal(queryInfo.Request, append(data, coin.GetDenom()...)) { found = true return true } @@ -1337,7 +1337,7 @@ func (suite *KeeperTestSuite) TestAccountBalanceCallback() { for _, addr := range []string{zone.DepositAddress.Address, zone.WithdrawalAddress.Address} { accAddr, err := sdk.AccAddressFromBech32(addr) suite.NoError(err) - data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte("qck")...) + data := append(banktypes.CreateAccountBalancesPrefix(accAddr), "qck"...) err = keeper.AccountBalanceCallback(quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data}) suite.NoError(err) @@ -1367,7 +1367,7 @@ func (suite *KeeperTestSuite) TestAccountBalance046Callback() { for _, addr := range []string{zone.DepositAddress.Address, zone.WithdrawalAddress.Address} { accAddr, err := sdk.AccAddressFromBech32(addr) suite.NoError(err) - data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte("qck")...) + data := append(banktypes.CreateAccountBalancesPrefix(accAddr), "qck"...) err = keeper.AccountBalanceCallback(quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data}) suite.NoError(err) @@ -1396,7 +1396,7 @@ func (suite *KeeperTestSuite) TestAccountBalanceCallbackMismatch() { for _, addr := range []string{zone.DepositAddress.Address, zone.WithdrawalAddress.Address} { accAddr, err := sdk.AccAddressFromBech32(addr) suite.NoError(err) - data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte("stake")...) + data := append(banktypes.CreateAccountBalancesPrefix(accAddr), "stake"...) err = keeper.AccountBalanceCallback(quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data}) suite.ErrorContains(err, "received coin denom qck does not match requested denom stake") @@ -1425,7 +1425,7 @@ func (suite *KeeperTestSuite) TestAccountBalanceCallbackNil() { for _, addr := range []string{zone.DepositAddress.Address, zone.WithdrawalAddress.Address} { accAddr, err := sdk.AccAddressFromBech32(addr) suite.NoError(err) - data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte("stake")...) + data := append(banktypes.CreateAccountBalancesPrefix(accAddr), "stake"...) err = keeper.AccountBalanceCallback(quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data}) suite.NoError(err) @@ -2593,7 +2593,7 @@ func (suite *KeeperTestSuite) TestDelegationAccountBalancesCallback() { if queryInfo.ChainId == zone.ChainId && queryInfo.ConnectionId == zone.ConnectionId && queryInfo.QueryType == icstypes.BankStoreKey && - bytes.Equal(queryInfo.Request, append(data, []byte(b.GetDenom())...)) { + bytes.Equal(queryInfo.Request, append(data, b.GetDenom()...)) { found = true return true } @@ -2625,7 +2625,7 @@ func (suite *KeeperTestSuite) TestDelegationAccountBalanceCallbackDenomMismatch( accAddr, err := sdk.AccAddressFromBech32(zone.DelegationAddress.Address) suite.Require().NoError(err) - data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte("uqck")...) + data := append(banktypes.CreateAccountBalancesPrefix(accAddr), "uqck"...) err = keeper.DelegationAccountBalanceCallback(app.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data}) suite.Require().Error(err) @@ -2699,7 +2699,7 @@ func (suite *KeeperTestSuite) TestDelegationAccountBalanceCallback() { accAddr, err := sdk.AccAddressFromBech32(zone.DelegationAddress.Address) suite.Require().NoError(err) - data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte("uatom")...) + data := append(banktypes.CreateAccountBalancesPrefix(accAddr), "uatom"...) err = keeper.DelegationAccountBalanceCallback(app.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data}) suite.Require().NoError(err) @@ -2734,7 +2734,7 @@ func (suite *KeeperTestSuite) TestDelegationAccountBalanceCallbackLSM() { accAddr, err := sdk.AccAddressFromBech32(zone.DelegationAddress.Address) suite.Require().NoError(err) - data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte(denom)...) + data := append(banktypes.CreateAccountBalancesPrefix(accAddr), denom...) err = keeper.DelegationAccountBalanceCallback(app.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data}) suite.Require().NoError(err) @@ -2773,7 +2773,7 @@ func (suite *KeeperTestSuite) TestDelegationAccountBalanceCallbackLSMBadZone() { accAddr, err := sdk.AccAddressFromBech32(zone.DelegationAddress.Address) suite.Require().NoError(err) - data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte(denom)...) + data := append(banktypes.CreateAccountBalancesPrefix(accAddr), denom...) err = keeper.DelegationAccountBalanceCallback(app.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data}) suite.Require().NoError(err) @@ -2818,7 +2818,7 @@ func (suite *KeeperTestSuite) TestPerfBalanceCallbackUpdate() { address := zone.PerformanceAddress.Address accAddr, err := sdk.AccAddressFromBech32(address) suite.NoError(err) - data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte("uatom")...) + data := append(banktypes.CreateAccountBalancesPrefix(accAddr), "uatom"...) err = keeper.PerfBalanceCallback(quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data}) suite.NoError(err) @@ -2866,7 +2866,7 @@ func TestRejectNonADR027(t *testing.T) { // bodyBz's length prefix is 5, with `5` as varint encoding. We also try a // longer varint encoding for 5: `133 00`. - longVarintBodyBz := append(append([]byte{bodyBz[0]}, byte(133), byte(0o0)), bodyBz[2:]...) + longVarintBodyBz := append(append([]byte{bodyBz[0]}, 133, 0o0), bodyBz[2:]...) tests := []struct { name string diff --git a/x/interchainstaking/keeper/delegation.go b/x/interchainstaking/keeper/delegation.go index 644d76fc2..dc87d4064 100644 --- a/x/interchainstaking/keeper/delegation.go +++ b/x/interchainstaking/keeper/delegation.go @@ -63,7 +63,7 @@ func (k *Keeper) GetPerformanceDelegation(ctx sdk.Context, chainID string, perfo func (k *Keeper) IterateAllDelegations(ctx sdk.Context, chainID string, cb func(delegation types.Delegation) (stop bool)) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, append(types.KeyPrefixDelegation, []byte(chainID)...)) + iterator := sdk.KVStorePrefixIterator(store, append(types.KeyPrefixDelegation, chainID...)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -88,7 +88,7 @@ func (k *Keeper) GetAllDelegations(ctx sdk.Context, chainID string) (delegations func (k *Keeper) IterateAllPerformanceDelegations(ctx sdk.Context, chainID string, cb func(delegation types.Delegation) (stop bool)) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, append(types.KeyPrefixPerformanceDelegation, []byte(chainID)...)) + iterator := sdk.KVStorePrefixIterator(store, append(types.KeyPrefixPerformanceDelegation, chainID...)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/interchainstaking/keeper/intent.go b/x/interchainstaking/keeper/intent.go index 39b96f8e2..96b6f0379 100644 --- a/x/interchainstaking/keeper/intent.go +++ b/x/interchainstaking/keeper/intent.go @@ -19,9 +19,9 @@ import ( func (*Keeper) getStoreKey(zone *types.Zone, snapshot bool) []byte { if snapshot { - return append(types.KeyPrefixSnapshotIntent, []byte(zone.ChainId)...) + return append(types.KeyPrefixSnapshotIntent, zone.ChainId...) } - return append(types.KeyPrefixIntent, []byte(zone.ChainId)...) + return append(types.KeyPrefixIntent, zone.ChainId...) } // GetDelegatorIntent returns intent info by zone and delegator. diff --git a/x/interchainstaking/keeper/keeper.go b/x/interchainstaking/keeper/keeper.go index 27dcbf682..9262b8994 100644 --- a/x/interchainstaking/keeper/keeper.go +++ b/x/interchainstaking/keeper/keeper.go @@ -562,7 +562,7 @@ func (k *Keeper) EmitPerformanceBalanceQuery(ctx sdk.Context, zone *types.Zone) zone.ConnectionId, zone.ChainId, types.BankStoreKey, - append(data, []byte(zone.BaseDenom)...), + append(data, zone.BaseDenom...), sdk.NewInt(-1), types.ModuleName, "perfbalance", diff --git a/x/interchainstaking/keeper/zones.go b/x/interchainstaking/keeper/zones.go index b17514801..c8e8d3648 100644 --- a/x/interchainstaking/keeper/zones.go +++ b/x/interchainstaking/keeper/zones.go @@ -351,7 +351,7 @@ func (k *Keeper) SetAccountBalance(ctx sdk.Context, zone types.Zone, address str zone.ConnectionId, zone.ChainId, types.BankStoreKey, - append(data, []byte(coin.Denom)...), + append(data, coin.Denom...), sdk.NewInt(-1), types.ModuleName, "accountbalance", @@ -369,7 +369,7 @@ func (k *Keeper) SetAccountBalance(ctx sdk.Context, zone types.Zone, address str zone.ConnectionId, zone.ChainId, types.BankStoreKey, - append(data, []byte(coin.Denom)...), + append(data, coin.Denom...), sdk.NewInt(-1), types.ModuleName, "accountbalance", diff --git a/x/interchainstaking/types/keys.go b/x/interchainstaking/types/keys.go index 29723aee2..ba7287aa7 100644 --- a/x/interchainstaking/types/keys.go +++ b/x/interchainstaking/types/keys.go @@ -94,12 +94,12 @@ func ParseStakingDelegationKey(key []byte) (sdk.AccAddress, sdk.ValAddress, erro // GetRemoteAddressKey gets the prefix for a remote address mapping. func GetRemoteAddressKey(localAddress []byte, chainID string) []byte { - return append(append(KeyPrefixRemoteAddress, localAddress...), []byte(chainID)...) + return append(append(KeyPrefixRemoteAddress, localAddress...), chainID...) } // GetLocalAddressKey gets the prefix for a local address mapping. func GetLocalAddressKey(remoteAddress []byte, chainID string) []byte { - return append(append(KeyPrefixLocalAddress, []byte(chainID)...), remoteAddress...) + return append(append(KeyPrefixLocalAddress, chainID...), remoteAddress...) } // GetDelegationKey gets the key for delegator bond with validator. @@ -110,7 +110,7 @@ func GetDelegationKey(chainID string, delAddr sdk.AccAddress, valAddr sdk.ValAdd // GetDelegationsKey gets the prefix for a delegator for all validators. func GetDelegationsKey(chainID string, delAddr sdk.AccAddress) []byte { - return append(append(KeyPrefixDelegation, []byte(chainID)...), delAddr.Bytes()...) + return append(append(KeyPrefixDelegation, chainID...), delAddr.Bytes()...) } // GetPerformanceDelegationKey gets the key for delegator bond with validator. @@ -121,7 +121,7 @@ func GetPerformanceDelegationKey(chainID string, delAddr sdk.AccAddress, valAddr // GetPerformanceDelegationsKey gets the prefix for a delegator for all validators. func GetPerformanceDelegationsKey(chainID string, delAddr sdk.AccAddress) []byte { - return append(append(KeyPrefixPerformanceDelegation, []byte(chainID)...), delAddr.Bytes()...) + return append(append(KeyPrefixPerformanceDelegation, chainID...), delAddr.Bytes()...) } func GetReceiptKey(chainID, txhash string) string { @@ -133,14 +133,14 @@ func GetReceiptKey(chainID, txhash string) string { func GetRedelegationKey(chainID, source, destination string, epochNumber int64) []byte { epochBytes := make([]byte, 8) binary.BigEndian.PutUint64(epochBytes, uint64(epochNumber)) - return append(KeyPrefixRedelegationRecord, append(append([]byte(chainID), []byte(source+destination)...), epochBytes...)...) + return append(append(KeyPrefixRedelegationRecord, chainID+source+destination...), epochBytes...) } func GetWithdrawalKey(chainID string, status int32) []byte { statusBytes := make([]byte, 8) binary.BigEndian.PutUint64(statusBytes, uint64(status)) key := KeyPrefixWithdrawalRecord - key = append(key, append([]byte(chainID), statusBytes...)...) + key = append(append(key, chainID...), statusBytes...) return key } @@ -149,12 +149,12 @@ func GetWithdrawalKey(chainID string, status int32) []byte { func GetUnbondingKey(chainID, validator string, epochNumber int64) []byte { epochBytes := make([]byte, 8) binary.BigEndian.PutUint64(epochBytes, uint64(epochNumber)) - return append(KeyPrefixUnbondingRecord, append(append([]byte(chainID), []byte(validator)...), epochBytes...)...) + return append(append(KeyPrefixUnbondingRecord, chainID+validator...), epochBytes...) } // GetZoneValidatorsKey gets the validators key prefix for a given chain. func GetZoneValidatorsKey(chainID string) []byte { - return append(KeyPrefixValidatorsInfo, []byte(chainID)...) + return append(KeyPrefixValidatorsInfo, chainID...) } // GetRemoteAddressPrefix gets the prefix for a remote address mapping. @@ -164,15 +164,15 @@ func GetRemoteAddressPrefix(locaAddress []byte) []byte { // GetZoneValidatorAddrsByConsAddrKey gets the validatoraddrs key prefix for a given chain. func GetZoneValidatorAddrsByConsAddrKey(chainID string) []byte { - return append(KeyPrefixValidatorAddrsByConsAddr, []byte(chainID)...) + return append(KeyPrefixValidatorAddrsByConsAddr, chainID...) } // GetDeniedValidatorKey gets the validator deny list key prefix for a given chain. func GetDeniedValidatorKey(chainID string, validatorAddress sdk.ValAddress) []byte { - return append(KeyPrefixDeniedValidator, append([]byte(chainID), validatorAddress.Bytes()...)...) + return append(append(KeyPrefixDeniedValidator, chainID...), validatorAddress.Bytes()...) } // GetZoneValidatorDenyListKey gets the validator deny list key prefix for a given chain. func GetZoneDeniedValidatorKey(chainID string) []byte { - return append(KeyPrefixDeniedValidator, []byte(chainID)...) + return append(KeyPrefixDeniedValidator, chainID...) } diff --git a/x/participationrewards/keeper/callbacks_test.go b/x/participationrewards/keeper/callbacks_test.go index 2887f4f0e..3c0ab9842 100644 --- a/x/participationrewards/keeper/callbacks_test.go +++ b/x/participationrewards/keeper/callbacks_test.go @@ -201,7 +201,7 @@ func (suite *KeeperTestSuite) executeUmeeLeverageModuleBalanceUpdateCallback() { accountPrefix := banktypes.CreateAccountBalancesPrefix(authtypes.NewModuleAddress(leveragetypes.LeverageModuleName)) - qid := icqkeeper.GenerateQueryHash(umeeTestConnection, umeeTestChain, "store/bank/key", append(accountPrefix, []byte(umeeBaseDenom)...), types.ModuleName, keeper.UmeeLeverageModuleBalanceUpdateCallbackID) + qid := icqkeeper.GenerateQueryHash(umeeTestConnection, umeeTestChain, "store/bank/key", append(accountPrefix, umeeBaseDenom...), types.ModuleName, keeper.UmeeLeverageModuleBalanceUpdateCallbackID) query, found := prk.IcqKeeper.GetQuery(ctx, qid) suite.True(found, "qid: %s", qid) diff --git a/x/participationrewards/keeper/grpc_query.go b/x/participationrewards/keeper/grpc_query.go index a999e0aee..6e3bb641f 100644 --- a/x/participationrewards/keeper/grpc_query.go +++ b/x/participationrewards/keeper/grpc_query.go @@ -28,7 +28,7 @@ func (k *Keeper) ProtocolData(c context.Context, q *types.QueryProtocolDataReque return nil, types.ErrUnknownProtocolDataType } - prefix := append(types.GetPrefixProtocolDataKey(types.ProtocolDataType(pdType)), []byte(q.Key)...) + prefix := append(types.GetPrefixProtocolDataKey(types.ProtocolDataType(pdType)), q.Key...) k.IteratePrefixedProtocolDatas(ctx, prefix, func(index int64, _ []byte, data types.ProtocolData) (stop bool) { out = append(out, data.Data) return false diff --git a/x/participationrewards/keeper/msg_server_test.go b/x/participationrewards/keeper/msg_server_test.go index b57d63717..49f224e4d 100644 --- a/x/participationrewards/keeper/msg_server_test.go +++ b/x/participationrewards/keeper/msg_server_test.go @@ -218,7 +218,7 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitClaim() { func() { userAddress := addressutils.GenerateAccAddressForTest() bankkey := banktypes.CreateAccountBalancesPrefix(userAddress) - bankkey = append(bankkey, []byte("gamm/1")...) + bankkey = append(bankkey, "gamm/1"...) cd := math.NewInt(10000000) bz, err := cd.Marshal() @@ -314,7 +314,7 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitClaim() { userAddress, _ := addressutils.EncodeAddressToBech32("umee", address) bankkey := banktypes.CreateAccountBalancesPrefix(address) - bankkey = append(bankkey, []byte("u/uumee")...) + bankkey = append(bankkey, "u/uumee"...) leveragekey := umeetypes.KeyCollateralAmount(address, "u/uumee") diff --git a/x/participationrewards/keeper/submodule_umee.go b/x/participationrewards/keeper/submodule_umee.go index 42d7fad4f..218880c23 100644 --- a/x/participationrewards/keeper/submodule_umee.go +++ b/x/participationrewards/keeper/submodule_umee.go @@ -134,7 +134,7 @@ func (UmeeModule) Hooks(ctx sdk.Context, k *Keeper) { connectionData.ConnectionID, connectionData.ChainID, icstypes.BankStoreKey, - append(accountPrefix, []byte(balance.Denom)...), + append(accountPrefix, balance.Denom...), sdk.NewInt(-1), types.ModuleName, UmeeLeverageModuleBalanceUpdateCallbackID,