Skip to content

Commit

Permalink
rewrite if-else chain to switch statements
Browse files Browse the repository at this point in the history
  • Loading branch information
tuantran1702 committed May 28, 2024
1 parent e9bb269 commit 439009a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions x/interchainstaking/types/redemptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,19 @@ func DetermineAllocationsForUndelegation(currentAllocations map[string]math.Int,
// use Amount+1 in the line below to avoid 1 remaining where truncation leaves 1 remaining - e.g. 1000 => 333/333/333 + 1.
outWeights[overAllocated[idx].ValoperAddress] = sdk.NewDecFromInt(overAllocated[idx].Amount).Quo(sdk.NewDecFromInt(sum)).Mul(sdk.NewDecFromInt(overAllocationSplit)).TruncateInt()
overAlloc := availablePerValidator[overAllocated[idx].ValoperAddress]
if overAlloc.IsNil() {
switch {
case overAlloc.IsNil():
availablePerValidator[overAllocated[idx].ValoperAddress] = sdk.ZeroInt()
} else if outWeights[overAllocated[idx].ValoperAddress].GT(overAlloc) {
case outWeights[overAllocated[idx].ValoperAddress].GT(overAlloc):

Check warning on line 63 in x/interchainstaking/types/redemptions.go

View check run for this annotation

Codecov / codecov/patch

x/interchainstaking/types/redemptions.go#L61-L63

Added lines #L61 - L63 were not covered by tests
// use up all of overAllocated[idx] and set available to zero.
outWeights[overAllocated[idx].ValoperAddress] = availablePerValidator[overAllocated[idx].ValoperAddress]
availablePerValidator[overAllocated[idx].ValoperAddress] = sdk.ZeroInt()
} else {
default:
// or don't, and reduce available as appropriate.
availablePerValidator[overAllocated[idx].ValoperAddress] = availablePerValidator[overAllocated[idx].ValoperAddress].Sub(outWeights[overAllocated[idx].ValoperAddress])

}

overAllocated[idx].Amount = overAllocated[idx].Amount.Sub(outWeights[overAllocated[idx].ValoperAddress])
outSum = outSum.Add(outWeights[overAllocated[idx].ValoperAddress])
}
Expand Down

0 comments on commit 439009a

Please sign in to comment.