processFixedDistributions handles the first pass: fixed amount distributions
(distributions []Distribution, state *distributionState)
| 146 | |
| 147 | // processFixedDistributions handles the first pass: fixed amount distributions |
| 148 | func processFixedDistributions(distributions []Distribution, state *distributionState) error { |
| 149 | for _, dist := range distributions { |
| 150 | if dist.isLeftDistribution() || dist.isPercentageDistribution() { |
| 151 | continue |
| 152 | } |
| 153 | |
| 154 | fixedAmountDec, err := parseFixedAmount(dist, state.precisionDec) |
| 155 | if err != nil { |
| 156 | return err |
| 157 | } |
| 158 | if fixedAmountDec.IsZero() { |
| 159 | continue |
| 160 | } |
| 161 | |
| 162 | if fixedAmountDec.Cmp(state.amountLeftDec) > 0 { |
| 163 | return errors.New("fixed amount exceeds remaining transaction amount") |
| 164 | } |
| 165 | |
| 166 | state.fixedAmounts[dist.Identifier] = fixedAmountDec |
| 167 | state.fixedTotalDec = state.fixedTotalDec.Add(fixedAmountDec) |
| 168 | state.amountLeftDec = state.amountLeftDec.Sub(fixedAmountDec) |
| 169 | } |
| 170 | return nil |
| 171 | } |
| 172 | |
| 173 | // parseFixedAmount parses a fixed amount from a distribution |
| 174 | func parseFixedAmount(dist Distribution, precisionDec decimal.Decimal) (decimal.Decimal, error) { |
no test coverage detected