2021-01-26 10:27:30 +00:00
|
|
|
package audit
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Calculator represents a component for calculating payments
|
2021-01-26 10:27:30 +00:00
|
|
|
// based on data audit results and sending remittances to the chain.
|
|
|
|
type Calculator struct {
|
|
|
|
prm *CalculatorPrm
|
|
|
|
|
|
|
|
opts *options
|
|
|
|
}
|
|
|
|
|
|
|
|
// CalculatorOption is a Calculator constructor's option.
|
|
|
|
type CalculatorOption func(*options)
|
|
|
|
|
|
|
|
type options struct {
|
|
|
|
log *logger.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultOptions() *options {
|
|
|
|
return &options{
|
2022-09-28 07:41:01 +00:00
|
|
|
log: &logger.Logger{Logger: zap.L()},
|
2021-01-26 10:27:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// NewCalculator creates, initializes and returns a new Calculator instance.
|
2021-01-26 10:27:30 +00:00
|
|
|
func NewCalculator(p *CalculatorPrm, opts ...CalculatorOption) *Calculator {
|
|
|
|
o := defaultOptions()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](o)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Calculator{
|
|
|
|
prm: p,
|
|
|
|
opts: o,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// WithLogger returns an option to specify the logging component.
|
2021-01-26 10:27:30 +00:00
|
|
|
func WithLogger(l *logger.Logger) CalculatorOption {
|
|
|
|
return func(o *options) {
|
|
|
|
o.log = l
|
|
|
|
}
|
|
|
|
}
|