Skip to content

Commit

Permalink
fixes #1340; remove superfluous []byte() casts for strings in append (#…
Browse files Browse the repository at this point in the history
…1360)

* fixes #1340; remove superfluous []byte() casts for strings in append

* remove existing unneccessary cast

---------

Co-authored-by: Tuan Tran <[email protected]>
  • Loading branch information
Joe Bowman and tuantran1702 authored Mar 28, 2024
1 parent 42d83ff commit 7af9933
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 110 deletions.
2 changes: 1 addition & 1 deletion third-party-chains/osmosis-types/gamm/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion third-party-chains/osmosis-types/osmomath/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand Down
8 changes: 4 additions & 4 deletions utils/coins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
"",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
41 changes: 20 additions & 21 deletions x/airdrop/spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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.

6 changes: 3 additions & 3 deletions x/airdrop/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
6 changes: 3 additions & 3 deletions x/airdrop/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions x/claimsmanager/keeper/self_consensus_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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...))
}
19 changes: 9 additions & 10 deletions x/claimsmanager/spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,26 @@ 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 {
return GetGenericKeyClaim(KeyPrefixClaim, chainID, address, module, srcChainID)
}

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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -210,4 +210,3 @@ N/A
## End Block

N/A

24 changes: 12 additions & 12 deletions x/claimsmanager/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ 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 {
return GetGenericKeyClaim(KeyPrefixClaim, chainID, address, module, srcChainID)
}

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
}

Expand All @@ -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
}
24 changes: 12 additions & 12 deletions x/claimsmanager/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion x/interchainstaking/keeper/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 7af9933

Please sign in to comment.