[#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("settlement.basic_income_rate", 0)
cfg.SetDefault("settlement.audit_fee", 0)
cfg.SetDefault("indexer.cache_timeout", 15*time.Second)

View file

@ -37,3 +37,12 @@ func (c *GlobalConfig) BasicIncomeRate() (uint64, error) {
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,
clientCache: clientCache,
balanceClient: balClient,
cfg: globalConfig,
}
auditCalcDeps := &auditSettlementDeps{
@ -402,7 +403,6 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
basicSettlementDeps := &basicIncomeSettlementDeps{
settlementDeps: settlementDeps,
cnrClient: cnrClient,
cfg: globalConfig,
}
auditSettlementCalc := auditSettlement.NewCalculator(
@ -413,6 +413,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
SGStorage: auditCalcDeps,
AccountStorage: auditCalcDeps,
Exchanger: auditCalcDeps,
AuditFeeFetcher: auditCalcDeps,
},
auditSettlement.WithLogger(server.log),
)

View file

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