From a6a5a84f3657897c63b63499c466b8f99a07ab60 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 28 Jan 2021 20:11:09 +0300 Subject: [PATCH] [#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 --- .../processors/settlement/audit/calculate.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/innerring/processors/settlement/audit/calculate.go b/pkg/innerring/processors/settlement/audit/calculate.go index fd498f593..0b5f5de6d 100644 --- a/pkg/innerring/processors/settlement/audit/calculate.go +++ b/pkg/innerring/processors/settlement/audit/calculate.go @@ -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) }) }