MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / parseFixedAmount

Function parseFixedAmount

model/transaction.go:174–192  ·  view source on GitHub ↗

parseFixedAmount parses a fixed amount from a distribution

(dist Distribution, precisionDec decimal.Decimal)

Source from the content-addressed store, hash-verified

172
173// parseFixedAmount parses a fixed amount from a distribution
174func parseFixedAmount(dist Distribution, precisionDec decimal.Decimal) (decimal.Decimal, error) {
175 if dist.PreciseDistribution != "" {
176 preciseAmount, err := strconv.ParseInt(dist.PreciseDistribution, 10, 64)
177 if err != nil {
178 return decimal.Zero, errors.New("invalid precise_distribution format: must be an integer value in minor units")
179 }
180 return decimal.NewFromInt(preciseAmount), nil
181 }
182
183 if dist.Distribution != "" {
184 fixedAmount, err := strconv.ParseFloat(dist.Distribution, 64)
185 if err != nil {
186 return decimal.Zero, errors.New("invalid fixed amount format")
187 }
188 return decimal.NewFromFloat(fixedAmount).Mul(precisionDec), nil
189 }
190
191 return decimal.Zero, nil
192}
193
194// processPercentageDistributions handles the second pass: percentage distributions
195func processPercentageDistributions(distributions []Distribution, state *distributionState) error {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected