[#326] settlement/audit: Prevent negative amount arguments of Exchanger
Do not pass zero transfers from the calculation table to Exchanger. Revert transfers with negative amount since Exchanger interface requires positive amounts of funds. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
2bca5879cd
commit
a6a5a84f36
1 changed files with 11 additions and 0 deletions
|
@ -82,6 +82,17 @@ func (c *Calculator) Calculate(p *CalculatePrm) {
|
|||
log.Debug("processing transfers")
|
||||
|
||||
table.iterate(func(tx *transferTx) {
|
||||
sign := tx.amount.Sign()
|
||||
if sign == 0 {
|
||||
log.Debug("ignore zero transfer")
|
||||
return
|
||||
}
|
||||
|
||||
if sign < 0 {
|
||||
tx.from, tx.to = tx.to, tx.from
|
||||
tx.amount.Neg(tx.amount)
|
||||
}
|
||||
|
||||
c.prm.Exchanger.Transfer(tx.from, tx.to, tx.amount)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue