2020-10-22 14:19:43 +00:00
|
|
|
package wrapper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2021-02-02 11:12:41 +00:00
|
|
|
const (
|
|
|
|
maxObjectSizeConfig = "MaxObjectSize"
|
|
|
|
basicIncomeRateConfig = "BasicIncomeRate"
|
2021-04-15 06:42:35 +00:00
|
|
|
auditFeeConfig = "AuditFee"
|
|
|
|
epochDurationConfig = "EpochDuration"
|
|
|
|
containerFeeConfig = "ContainerFee"
|
|
|
|
etIterationsConfig = "EigenTrustIterations"
|
2021-04-21 12:25:44 +00:00
|
|
|
irCandidateFeeConfig = "InnerRingCandidateFee"
|
|
|
|
withdrawFeeConfig = "WithdrawFee"
|
2021-02-02 11:12:41 +00:00
|
|
|
)
|
2020-10-22 14:19:43 +00:00
|
|
|
|
|
|
|
// MaxObjectSize receives max object size configuration
|
|
|
|
// value through the Netmap contract call.
|
|
|
|
func (w *Wrapper) MaxObjectSize() (uint64, error) {
|
2021-02-02 11:12:41 +00:00
|
|
|
objectSize, err := w.readUInt64Config(maxObjectSizeConfig)
|
|
|
|
if err != nil {
|
|
|
|
return 0, errors.Wrapf(err, "(%T) could not get epoch number", w)
|
|
|
|
}
|
|
|
|
|
|
|
|
return objectSize, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// BasicIncomeRate returns basic income rate configuration value from network
|
|
|
|
// config in netmap contract.
|
2021-04-15 06:42:35 +00:00
|
|
|
func (w *Wrapper) BasicIncomeRate() (uint64, error) {
|
2021-02-02 11:12:41 +00:00
|
|
|
rate, err := w.readUInt64Config(basicIncomeRateConfig)
|
|
|
|
if err != nil {
|
|
|
|
return 0, errors.Wrapf(err, "(%T) could not get basic income rate", w)
|
|
|
|
}
|
|
|
|
|
|
|
|
return rate, nil
|
|
|
|
}
|
|
|
|
|
2021-04-07 10:48:46 +00:00
|
|
|
// AuditFee returns audit fee configuration value from network
|
|
|
|
// config in netmap contract.
|
|
|
|
func (w *Wrapper) AuditFee() (uint64, error) {
|
2021-04-15 06:42:35 +00:00
|
|
|
fee, err := w.readUInt64Config(auditFeeConfig)
|
2021-04-07 10:48:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, errors.Wrapf(err, "(%T) could not get audit fee", w)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fee, nil
|
|
|
|
}
|
|
|
|
|
2021-04-15 06:42:35 +00:00
|
|
|
// EpochDuration returns number of sidechain blocks per one NeoFS epoch.
|
|
|
|
func (w *Wrapper) EpochDuration() (uint64, error) {
|
|
|
|
epochDuration, err := w.readUInt64Config(epochDurationConfig)
|
|
|
|
if err != nil {
|
|
|
|
return 0, errors.Wrapf(err, "(%T) could not get epoch duration", w)
|
|
|
|
}
|
|
|
|
|
|
|
|
return epochDuration, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ContainerFee returns fee paid by container owner to each alphabet node
|
|
|
|
// for container registration.
|
|
|
|
func (w *Wrapper) ContainerFee() (uint64, error) {
|
|
|
|
fee, err := w.readUInt64Config(containerFeeConfig)
|
|
|
|
if err != nil {
|
|
|
|
return 0, errors.Wrapf(err, "(%T) could not get container fee", w)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fee, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// EigenTrustIterations returns global configuration value of iteration cycles
|
|
|
|
// for EigenTrust algorithm per epoch.
|
|
|
|
func (w *Wrapper) EigenTrustIterations() (uint64, error) {
|
|
|
|
iterations, err := w.readUInt64Config(etIterationsConfig)
|
|
|
|
if err != nil {
|
|
|
|
return 0, errors.Wrapf(err, "(%T) could not get eigen trust iterations", w)
|
|
|
|
}
|
|
|
|
|
|
|
|
return iterations, nil
|
|
|
|
}
|
|
|
|
|
2021-04-29 13:53:54 +00:00
|
|
|
// InnerRingCandidateFee returns global configuration value of fee paid by
|
2021-04-21 12:25:44 +00:00
|
|
|
// node to be in inner ring candidates list.
|
|
|
|
func (w *Wrapper) InnerRingCandidateFee() (uint64, error) {
|
|
|
|
fee, err := w.readUInt64Config(irCandidateFeeConfig)
|
|
|
|
if err != nil {
|
|
|
|
return 0, errors.Wrapf(err, "(%T) could not get inner ring candidate fee", w)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fee, nil
|
|
|
|
}
|
|
|
|
|
2021-04-29 13:53:54 +00:00
|
|
|
// WithdrawFee returns global configuration value of fee paid by user to
|
2021-04-21 12:25:44 +00:00
|
|
|
// withdraw assets from NeoFS contract.
|
|
|
|
func (w *Wrapper) WithdrawFee() (uint64, error) {
|
|
|
|
fee, err := w.readUInt64Config(withdrawFeeConfig)
|
|
|
|
if err != nil {
|
|
|
|
return 0, errors.Wrapf(err, "(%T) could not get withdraw fee", w)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fee, nil
|
|
|
|
}
|
|
|
|
|
2021-02-02 11:12:41 +00:00
|
|
|
func (w *Wrapper) readUInt64Config(key string) (uint64, error) {
|
2020-10-22 14:19:43 +00:00
|
|
|
args := netmap.ConfigArgs{}
|
2021-02-02 11:12:41 +00:00
|
|
|
args.SetKey([]byte(key))
|
2020-10-22 14:19:43 +00:00
|
|
|
|
|
|
|
vals, err := w.client.Config(args, netmap.IntegerAssert)
|
|
|
|
if err != nil {
|
2021-02-02 11:12:41 +00:00
|
|
|
return 0, err
|
2020-10-22 14:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
v := vals.Value()
|
|
|
|
|
|
|
|
sz, ok := v.(int64)
|
|
|
|
if !ok {
|
2021-02-02 11:12:41 +00:00
|
|
|
return 0, errors.Errorf("(%T) invalid value type %T", w, v)
|
2020-10-22 14:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return uint64(sz), nil
|
|
|
|
}
|