From aa243565ce70893f5cfa5328e51d5c08a518f96b Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Mon, 2 Jul 2018 20:09:57 -0400 Subject: [PATCH] fix appending over key --- x/stake/keeper/delegation.go | 1 + x/stake/keeper/key.go | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/x/stake/keeper/delegation.go b/x/stake/keeper/delegation.go index 0fe4406c3..ded603abd 100644 --- a/x/stake/keeper/delegation.go +++ b/x/stake/keeper/delegation.go @@ -162,6 +162,7 @@ func (k Keeper) GetRedelegationsFromValidator(ctx sdk.Context, valAddr sdk.Addre fmt.Println("called") //redelegationKey := iterator.Value() iKey := iterator.Key() + fmt.Println("LEN IT", len(iKey)) redelegationKey := GetREDKeyFromValSrcIndexKey(iKey) fmt.Printf("debug iteratorValue: %v\n", iterator.Value()) fmt.Printf("debug iteratorKey: %v\n", iKey) diff --git a/x/stake/keeper/key.go b/x/stake/keeper/key.go index 248ee9db0..b831de5f2 100644 --- a/x/stake/keeper/key.go +++ b/x/stake/keeper/key.go @@ -162,12 +162,13 @@ func GetUBDsByValIndexKey(validatorAddr sdk.Address) []byte { func GetREDKey(delegatorAddr, validatorSrcAddr, validatorDstAddr sdk.Address) []byte { - return append( - GetREDsKey(delegatorAddr), - append( - validatorSrcAddr.Bytes(), - validatorDstAddr.Bytes()...)..., - ) + fmt.Println("KEY", delegatorAddr.Bytes()) + key := make([]byte, len(delegatorAddr.Bytes())) + copy(key, delegatorAddr.Bytes()) + + return append(append( + GetREDsKey(key), validatorSrcAddr.Bytes()...), + validatorDstAddr.Bytes()...) } // get the index-key for a redelegation, stored by source-validator-index @@ -206,10 +207,18 @@ func GetREDKeyFromValSrcIndexKey(IndexKey []byte) []byte { valSrcAddr := addrs[:split] delAddr := addrs[split : 2*split] valDstAddr := addrs[2*split:] - fmt.Printf("debug delAddr: %v\n", delAddr) + fmt.Printf("debug indexKey: %v\n", IndexKey) fmt.Printf("debug valSrcAddr: %v\n", valSrcAddr) + fmt.Printf("debug delAddr: %v\n", delAddr) fmt.Printf("debug valDstAddr: %v\n", valDstAddr) - return GetREDKey(delAddr, valSrcAddr, valDstAddr) + redKey := GetREDKey(delAddr, valSrcAddr, valDstAddr) + fmt.Println("------") + fmt.Printf("debug indexKey: %v\n", IndexKey) + fmt.Printf("debug valSrcAddr: %v\n", valSrcAddr) + fmt.Printf("debug delAddr: %v\n", delAddr) + fmt.Printf("debug valDstAddr: %v\n", valDstAddr) + fmt.Println("") + return redKey } // rearrange the ValDstIndexKey to get the REDKey