diff --git a/pkg/innerring/processors/settlement/basic/collect.go b/pkg/innerring/processors/settlement/basic/collect.go index ad205afd..2c978c9c 100644 --- a/pkg/innerring/processors/settlement/basic/collect.go +++ b/pkg/innerring/processors/settlement/basic/collect.go @@ -18,8 +18,6 @@ func (inc *IncomeSettlementContext) Collect() { inc.mu.Lock() defer inc.mu.Unlock() - // todo: save state of bank wallet - cachedRate, err := inc.rate.BasicRate() if err != nil { inc.log.Error("can't get basic income rate", diff --git a/pkg/innerring/processors/settlement/basic/context.go b/pkg/innerring/processors/settlement/basic/context.go index 1b46fbe4..6528fed3 100644 --- a/pkg/innerring/processors/settlement/basic/context.go +++ b/pkg/innerring/processors/settlement/basic/context.go @@ -1,6 +1,7 @@ package basic import ( + "math/big" "sync" "github.com/mr-tron/base58" @@ -21,6 +22,11 @@ type ( BasicRate() (uint64, error) } + // BalanceFetcher uses NEP-17 compatible balance contract + BalanceFetcher interface { + Balance(id *owner.ID) (*big.Int, error) + } + IncomeSettlementContext struct { mu sync.Mutex // lock to prevent collection and distribution in the same time @@ -29,6 +35,7 @@ type ( rate RateFetcher estimations EstimationFetcher + balances BalanceFetcher container common.ContainerStorage placement common.PlacementCalculator exchange common.Exchanger @@ -42,6 +49,7 @@ type ( Epoch uint64 Rate RateFetcher Estimations EstimationFetcher + Balances BalanceFetcher Container common.ContainerStorage Placement common.PlacementCalculator Exchange common.Exchanger @@ -59,6 +67,7 @@ func NewIncomeSettlementContext(p *IncomeSettlementContextPrms) (*IncomeSettleme epoch: p.Epoch, rate: p.Rate, estimations: p.Estimations, + balances: p.Balances, container: p.Container, placement: p.Placement, exchange: p.Exchange, diff --git a/pkg/innerring/processors/settlement/basic/distribute.go b/pkg/innerring/processors/settlement/basic/distribute.go index 3ec5e979..70eb13d2 100644 --- a/pkg/innerring/processors/settlement/basic/distribute.go +++ b/pkg/innerring/processors/settlement/basic/distribute.go @@ -1,6 +1,20 @@ package basic +import ( + "go.uber.org/zap" +) + func (inc *IncomeSettlementContext) Distribute() { inc.mu.Lock() defer inc.mu.Unlock() + + bankBalance, err := inc.balances.Balance(inc.bankOwner) + if err != nil { + inc.log.Error("can't fetch balance of banking account", + zap.String("error", err.Error())) + + return + } + + _ = bankBalance } diff --git a/pkg/innerring/settlement.go b/pkg/innerring/settlement.go index 598fadee..080c5c4f 100644 --- a/pkg/innerring/settlement.go +++ b/pkg/innerring/settlement.go @@ -259,6 +259,10 @@ func (b basicIncomeSettlementDeps) Estimations(epoch uint64) ([]*wrapper.Estimat return result, nil } +func (b basicIncomeSettlementDeps) Balance(id *owner.ID) (*big.Int, error) { + return b.balanceClient.BalanceOf(id) +} + func (s *auditSettlementCalculator) ProcessAuditSettlements(epoch uint64) { (*audit.Calculator)(s).Calculate(&audit.CalculatePrm{ Epoch: epoch, @@ -271,6 +275,7 @@ func (b *basicSettlementConstructor) CreateContext(epoch uint64) (*basic.IncomeS Epoch: epoch, Rate: b.dep, Estimations: b.dep, + Balances: b.dep, Container: b.dep, Placement: b.dep, Exchange: b.dep,