ApplyRate applies the exchange rate to the precise amount and returns a *big.Int. The rate is applied after precision to maintain accuracy.
(preciseAmount *big.Int, rate float64)
| 388 | // ApplyRate applies the exchange rate to the precise amount and returns a *big.Int. |
| 389 | // The rate is applied after precision to maintain accuracy. |
| 390 | func ApplyRate(preciseAmount *big.Int, rate float64) *big.Int { |
| 391 | if rate == 0 { |
| 392 | rate = 1 |
| 393 | } |
| 394 | |
| 395 | // Create a new big.Float from the precise amount |
| 396 | preciseAmountFloat := new(big.Float).SetInt(preciseAmount) |
| 397 | |
| 398 | // Create a big.Float for the rate |
| 399 | rateFloat := new(big.Float).SetFloat64(rate) |
| 400 | |
| 401 | // Multiply the amount by the rate |
| 402 | result := new(big.Float).Mul(preciseAmountFloat, rateFloat) |
| 403 | |
| 404 | // Convert back to big.Int (rounding if necessary) |
| 405 | resultBigInt := new(big.Int) |
| 406 | result.Int(resultBigInt) |
| 407 | |
| 408 | return resultBigInt |
| 409 | } |
| 410 | |
| 411 | // validate checks if the transaction is valid (e.g., ensuring positive amount). |
| 412 | func (transaction *Transaction) validate() error { |
no outgoing calls