2021-02-02 11:12:41 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
/*
|
|
|
|
Config package contains GlobalConfig structure that implements config
|
2022-04-21 11:28:05 +00:00
|
|
|
reader from both local and global configurations. Most of the time the inner ring
|
|
|
|
does not need this; as for application, it has static config with timeouts,
|
|
|
|
caches sizes etc. However, there are routines that use global configuration
|
2021-02-02 11:12:41 +00:00
|
|
|
values that can be changed in runtime, e.g. basic income rate. Local
|
2022-04-21 11:28:05 +00:00
|
|
|
configuration value overrides the global one so it is easy to debug and test
|
2021-02-02 11:12:41 +00:00
|
|
|
in different environments.
|
|
|
|
|
|
|
|
Implemented as a part of https://github.com/nspcc-dev/neofs-node/issues/363
|
|
|
|
*/
|
|
|
|
|
|
|
|
import (
|
2021-06-09 11:00:55 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/misc"
|
2022-01-31 11:58:55 +00:00
|
|
|
netmapClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
2021-02-02 11:12:41 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GlobalConfig struct {
|
|
|
|
cfg *viper.Viper
|
2022-01-31 11:58:55 +00:00
|
|
|
nm *netmapClient.Client
|
2021-02-02 11:12:41 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 11:58:55 +00:00
|
|
|
func NewGlobalConfigReader(cfg *viper.Viper, nm *netmapClient.Client) *GlobalConfig {
|
2021-02-02 11:12:41 +00:00
|
|
|
return &GlobalConfig{
|
|
|
|
cfg: cfg,
|
|
|
|
nm: nm,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *GlobalConfig) BasicIncomeRate() (uint64, error) {
|
2021-06-09 11:00:55 +00:00
|
|
|
if isDebug() {
|
|
|
|
value := c.cfg.GetUint64("settlement.basic_income_rate")
|
|
|
|
if value != 0 {
|
|
|
|
return value, nil
|
|
|
|
}
|
2021-02-02 11:12:41 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 06:42:35 +00:00
|
|
|
return c.nm.BasicIncomeRate()
|
2021-02-02 11:12:41 +00:00
|
|
|
}
|
2021-04-07 10:53:13 +00:00
|
|
|
|
|
|
|
func (c *GlobalConfig) AuditFee() (uint64, error) {
|
2021-06-09 11:00:55 +00:00
|
|
|
if isDebug() {
|
|
|
|
value := c.cfg.GetUint64("settlement.audit_fee")
|
|
|
|
if value != 0 {
|
|
|
|
return value, nil
|
|
|
|
}
|
2021-04-07 10:53:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return c.nm.AuditFee()
|
|
|
|
}
|
2021-04-15 06:43:49 +00:00
|
|
|
|
2021-06-09 11:00:55 +00:00
|
|
|
func isDebug() bool {
|
|
|
|
return misc.Debug == "true"
|
|
|
|
}
|