address bucky comments - rearrange appends

This commit is contained in:
rigelrozanski 2018-07-03 13:37:17 -04:00
parent 271fbb2db3
commit 4f0c7d8746
2 changed files with 18 additions and 25 deletions

View File

@ -179,7 +179,7 @@ func TestUnbondDelegation(t *testing.T) {
require.Equal(t, int64(4), pool.BondedTokens)
}
// tests Get/Set/Remove/Has UnbondingDelegation
// Make sure that that the retrieving the delegations doesn't affect the state
func TestGetRedelegationsFromValidator(t *testing.T) {
ctx, _, keeper := CreateTestInput(t, false, 0)
@ -198,10 +198,12 @@ func TestGetRedelegationsFromValidator(t *testing.T) {
resBond, found := keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
require.True(t, found)
// get the redelegations one time
redelegations := keeper.GetRedelegationsFromValidator(ctx, addrVals[0])
require.Equal(t, 1, len(redelegations))
require.True(t, redelegations[0].Equal(resBond))
// get the redelegations a second time, should be exactly the same
redelegations = keeper.GetRedelegationsFromValidator(ctx, addrVals[0])
require.Equal(t, 1, len(redelegations))
require.True(t, redelegations[0].Equal(resBond))

View File

@ -52,7 +52,7 @@ func GetValidatorsBondedIndexKey(ownerAddr sdk.Address) []byte {
return append(ValidatorsBondedIndexKey, ownerAddr.Bytes()...)
}
// rearrange the ValBondedIndexKey to get the ValidatorKey
// Get the validator owner address from ValBondedIndexKey
func GetAddressFromValBondedIndexKey(IndexKey []byte) []byte {
return IndexKey[1:] // remove prefix bytes
}
@ -84,10 +84,12 @@ func getValidatorPowerRank(validator types.Validator, pool types.Pool) []byte {
counterBytes := make([]byte, 2)
binary.BigEndian.PutUint16(counterBytes, ^uint16(validator.BondIntraTxCounter)) // invert counter (first txns have priority)
return append(ValidatorsByPowerIndexKey,
append(revokedBytes,
append(powerBytes,
append(heightBytes, counterBytes...)...)...)...)
return append(append(append(append(
ValidatorsByPowerIndexKey,
revokedBytes...),
powerBytes...),
heightBytes...),
counterBytes...)
}
// get the key for the accumulated update validators.
@ -115,12 +117,8 @@ func GetDelegationsKey(delegatorAddr sdk.Address) []byte {
// get the key for an unbonding delegation by delegator and validator addr.
// VALUE: stake/types.UnbondingDelegation
func GetUBDKey(delegatorAddr, validatorAddr sdk.Address) []byte {
key := make([]byte, len(delegatorAddr.Bytes()))
copy(key, delegatorAddr.Bytes())
return append(
GetUBDsKey(key),
GetUBDsKey(delegatorAddr.Bytes()),
validatorAddr.Bytes()...)
}
@ -161,11 +159,8 @@ func GetUBDsByValIndexKey(validatorAddr sdk.Address) []byte {
func GetREDKey(delegatorAddr, validatorSrcAddr,
validatorDstAddr sdk.Address) []byte {
key := make([]byte, len(delegatorAddr.Bytes()))
copy(key, delegatorAddr.Bytes())
return append(append(
GetREDsKey(key),
GetREDsKey(delegatorAddr.Bytes()),
validatorSrcAddr.Bytes()...),
validatorDstAddr.Bytes()...)
}
@ -175,12 +170,10 @@ func GetREDKey(delegatorAddr, validatorSrcAddr,
func GetREDByValSrcIndexKey(delegatorAddr, validatorSrcAddr,
validatorDstAddr sdk.Address) []byte {
return append(
return append(append(
GetREDsFromValSrcIndexKey(validatorSrcAddr),
append(
delegatorAddr.Bytes(),
validatorDstAddr.Bytes()...)...,
)
delegatorAddr.Bytes()...),
validatorDstAddr.Bytes()...)
}
// get the index-key for a redelegation, stored by destination-validator-index
@ -188,12 +181,10 @@ func GetREDByValSrcIndexKey(delegatorAddr, validatorSrcAddr,
func GetREDByValDstIndexKey(delegatorAddr, validatorSrcAddr,
validatorDstAddr sdk.Address) []byte {
return append(
return append(append(
GetREDsToValDstIndexKey(validatorDstAddr),
append(
delegatorAddr.Bytes(),
validatorSrcAddr.Bytes()...)...,
)
delegatorAddr.Bytes()...),
validatorSrcAddr.Bytes()...)
}
// rearrange the ValSrcIndexKey to get the REDKey