From e0194dbde5a16ad8499541880b37c7e28875144a Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 19 Sep 2022 19:03:54 +0400 Subject: [PATCH] [#1681] morph/netmap: Refactor reading the boolean configurations `readBoolConfig` method is going to be reused for reading other configuration values. All boolean settings are `false` by default, so it makes sense to return default value on missing key directly from `readBoolConfig`. Handle `ErrConfigNotFound` case in `readBoolConfig` method. Change `HomomorphicHashDisabled` method to call `readBoolConfig` directly. Signed-off-by: Leonard Lyubich --- pkg/morph/client/netmap/config.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/pkg/morph/client/netmap/config.go b/pkg/morph/client/netmap/config.go index 8ab4bf126f..0d02a57dab 100644 --- a/pkg/morph/client/netmap/config.go +++ b/pkg/morph/client/netmap/config.go @@ -116,18 +116,7 @@ func (c *Client) EigenTrustAlpha() (float64, error) { // // Returns (false, nil) if config key is not found in the contract. func (c *Client) HomomorphicHashDisabled() (bool, error) { - const defaultValue = false - - hashingDisabled, err := c.readBoolConfig(homomorphicHashingDisabledKey) - if err != nil { - if errors.Is(err, ErrConfigNotFound) { - return defaultValue, nil - } - - return false, fmt.Errorf("(%T) could not get homomorphic hash state: %w", c, err) - } - - return hashingDisabled, nil + return c.readBoolConfig(homomorphicHashingDisabledKey) } // InnerRingCandidateFee returns global configuration value of fee paid by @@ -172,10 +161,16 @@ func (c *Client) readStringConfig(key string) (string, error) { return v.(string), nil } +// reads boolean value by the given key from the NeoFS network configuration +// stored in the Sidechain. Returns false if key is not presented. func (c *Client) readBoolConfig(key string) (bool, error) { v, err := c.config([]byte(key), BoolAssert) if err != nil { - return false, err + if errors.Is(err, ErrConfigNotFound) { + return false, nil + } + + return false, fmt.Errorf("read boolean configuration value %s from the Sidechain: %w", key, err) } // BoolAssert is guaranteed to return bool if the error is nil.