From 4fe46ad10b2041b3467da13c06b299c44c8a71bb Mon Sep 17 00:00:00 2001 From: Jiri Vestfal <45360788+MissingNO57@users.noreply.github.com> Date: Fri, 25 Oct 2024 20:46:42 +0200 Subject: [PATCH] Fix: delegations movements (#413) --- app/upgrade_cudos.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/app/upgrade_cudos.go b/app/upgrade_cudos.go index 697400df..7217489d 100644 --- a/app/upgrade_cudos.go +++ b/app/upgrade_cudos.go @@ -1806,8 +1806,8 @@ func moveGenesisDelegation(genesisData *GenesisData, fromDelegatorAddress, toDel } // Source delegation must exist - sourceDelegations, sourceAmount := getDelegationData(genesisData, fromDelegatorAddress, validatorAddress) - if sourceDelegations == nil { + sourceValidatorsDelegations, sourceAmount := getDelegationData(genesisData, fromDelegatorAddress, validatorAddress) + if sourceValidatorsDelegations == nil { return fmt.Errorf("genesis source delegations of %s not found", fromDelegatorAddress) } if sourceAmount == nil { @@ -1818,26 +1818,25 @@ func moveGenesisDelegation(genesisData *GenesisData, fromDelegatorAddress, toDel return fmt.Errorf("amount to move is greater than delegated amount") } - destinationDelegations, destinationDelegatedAmount := getDelegationData(genesisData, toDelegatorAddress, validatorAddress) - if destinationDelegations == nil { + destinationValidatorsDelegations, destinationValidatorDelegatedAmount := getDelegationData(genesisData, toDelegatorAddress, validatorAddress) + if destinationValidatorsDelegations == nil { // No destination delegations - newMap := NewOrderedMap[string, sdk.Int]() - newMap.Set(toDelegatorAddress, amount) - genesisData.Delegations.Set(toDelegatorAddress, newMap) - } else if destinationDelegatedAmount == nil { - + destinationValidatorsDelegations = NewOrderedMap[string, sdk.Int]() + destinationValidatorsDelegations.Set(validatorAddress, amount) + genesisData.Delegations.Set(toDelegatorAddress, destinationValidatorsDelegations) + } else if destinationValidatorDelegatedAmount == nil { // No delegations to validator - destinationDelegations.Set(validatorAddress, amount) + destinationValidatorsDelegations.Set(validatorAddress, amount) } else { // Update existing balance - destinationDelegations.Set(validatorAddress, destinationDelegatedAmount.Add(amount)) + destinationValidatorsDelegations.Set(validatorAddress, destinationValidatorDelegatedAmount.Add(amount)) } // Subtract amount from source or remove if nothing left if amount.Equal(*sourceAmount) { - sourceDelegations.Delete(validatorAddress) + sourceValidatorsDelegations.Delete(validatorAddress) } else { - sourceDelegations.Set(validatorAddress, sourceAmount.Sub(amount)) + sourceValidatorsDelegations.Set(validatorAddress, sourceAmount.Sub(amount)) } registerManifestMoveDelegations(fromDelegatorAddress, toDelegatorAddress, validatorAddress, amount, memo, manifest)