[#465] innerring: Add audit fee fetcher to settlement processor

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-04-07 13:53:13 +03:00 committed by Alex Vanin
parent 0816f7b63b
commit 1d68e74636
4 changed files with 19 additions and 2 deletions

View file

@ -110,6 +110,7 @@ func defaultConfiguration(cfg *viper.Viper) {
cfg.SetDefault("audit.por.pool_size", "10") cfg.SetDefault("audit.por.pool_size", "10")
cfg.SetDefault("settlement.basic_income_rate", 0) cfg.SetDefault("settlement.basic_income_rate", 0)
cfg.SetDefault("settlement.audit_fee", 0)
cfg.SetDefault("indexer.cache_timeout", 15*time.Second) cfg.SetDefault("indexer.cache_timeout", 15*time.Second)

View file

@ -37,3 +37,12 @@ func (c *GlobalConfig) BasicIncomeRate() (uint64, error) {
return c.nm.BasinIncomeRate() return c.nm.BasinIncomeRate()
} }
func (c *GlobalConfig) AuditFee() (uint64, error) {
value := c.cfg.GetUint64("settlement.audit_fee")
if value != 0 {
return value, nil
}
return c.nm.AuditFee()
}

View file

@ -393,6 +393,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
nmSrc: nmClient, nmSrc: nmClient,
clientCache: clientCache, clientCache: clientCache,
balanceClient: balClient, balanceClient: balClient,
cfg: globalConfig,
} }
auditCalcDeps := &auditSettlementDeps{ auditCalcDeps := &auditSettlementDeps{
@ -402,7 +403,6 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
basicSettlementDeps := &basicIncomeSettlementDeps{ basicSettlementDeps := &basicIncomeSettlementDeps{
settlementDeps: settlementDeps, settlementDeps: settlementDeps,
cnrClient: cnrClient, cnrClient: cnrClient,
cfg: globalConfig,
} }
auditSettlementCalc := auditSettlement.NewCalculator( auditSettlementCalc := auditSettlement.NewCalculator(
@ -413,6 +413,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
SGStorage: auditCalcDeps, SGStorage: auditCalcDeps,
AccountStorage: auditCalcDeps, AccountStorage: auditCalcDeps,
Exchanger: auditCalcDeps, Exchanger: auditCalcDeps,
AuditFeeFetcher: auditCalcDeps,
}, },
auditSettlement.WithLogger(server.log), auditSettlement.WithLogger(server.log),
) )

View file

@ -28,6 +28,7 @@ import (
type globalConfig interface { type globalConfig interface {
BasicIncomeRate() (uint64, error) BasicIncomeRate() (uint64, error)
AuditFee() (uint64, error)
} }
type settlementDeps struct { type settlementDeps struct {
@ -42,6 +43,8 @@ type settlementDeps struct {
clientCache *ClientCache clientCache *ClientCache
balanceClient *balanceClient.Wrapper balanceClient *balanceClient.Wrapper
cfg globalConfig
} }
type auditSettlementDeps struct { type auditSettlementDeps struct {
@ -51,7 +54,6 @@ type auditSettlementDeps struct {
type basicIncomeSettlementDeps struct { type basicIncomeSettlementDeps struct {
*settlementDeps *settlementDeps
cnrClient *containerClient.Wrapper cnrClient *containerClient.Wrapper
cfg globalConfig
} }
type basicSettlementConstructor struct { type basicSettlementConstructor struct {
@ -227,6 +229,10 @@ func (a auditSettlementDeps) Transfer(sender, recipient *owner.ID, amount *big.I
a.transfer(sender, recipient, amount, transferAuditDetails) a.transfer(sender, recipient, amount, transferAuditDetails)
} }
func (a auditSettlementDeps) AuditFee() (uint64, error) {
return a.cfg.AuditFee()
}
func (b basicIncomeSettlementDeps) Transfer(sender, recipient *owner.ID, amount *big.Int) { func (b basicIncomeSettlementDeps) Transfer(sender, recipient *owner.ID, amount *big.Int) {
b.transfer(sender, recipient, amount, basicIncomeAuditDetails) b.transfer(sender, recipient, amount, basicIncomeAuditDetails)
} }