processPercentageDistributions handles the second pass: percentage distributions
(distributions []Distribution, state *distributionState)
| 193 | |
| 194 | // processPercentageDistributions handles the second pass: percentage distributions |
| 195 | func processPercentageDistributions(distributions []Distribution, state *distributionState) error { |
| 196 | hundredDec := decimal.NewFromInt(100) |
| 197 | minValueDec := decimal.NewFromInt(1) |
| 198 | |
| 199 | for _, dist := range distributions { |
| 200 | if dist.isLeftDistribution() || !dist.isPercentageDistribution() { |
| 201 | continue |
| 202 | } |
| 203 | |
| 204 | percentageStr := dist.Distribution[:len(dist.Distribution)-1] |
| 205 | percentage, err := strconv.ParseFloat(percentageStr, 64) |
| 206 | if err != nil { |
| 207 | return errors.New("invalid percentage format") |
| 208 | } |
| 209 | |
| 210 | percentageDec := decimal.NewFromFloat(percentage) |
| 211 | state.totalPercentage = state.totalPercentage.Add(percentageDec) |
| 212 | |
| 213 | rawAmountDec := state.totalAmountDec.Mul(percentageDec).Div(hundredDec) |
| 214 | |
| 215 | if rawAmountDec.Sign() > 0 && rawAmountDec.Cmp(minValueDec) < 0 { |
| 216 | state.percentAmounts[dist.Identifier] = decimal.Zero |
| 217 | } else { |
| 218 | state.percentAmounts[dist.Identifier] = rawAmountDec |
| 219 | } |
| 220 | } |
| 221 | return nil |
| 222 | } |
| 223 | |
| 224 | // validateDistributions checks that total distributions don't exceed limits |
| 225 | func validateDistributions(state *distributionState) error { |
no test coverage detected