[#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:
Leonard Lyubich 2021-01-28 20:11:09 +03:00 committed by Alex Vanin
parent 2bca5879cd
commit a6a5a84f36

View file

@ -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)
})
}