[#1365] morph: Do not return errors if config key is missing
Return default values instead of casting errors in `HomomorphicHashDisabled` method. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
9bd1951ca4
commit
4a316ceae9
1 changed files with 19 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
package netmap
|
package netmap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
@ -112,9 +113,17 @@ func (c *Client) EigenTrustAlpha() (float64, error) {
|
||||||
|
|
||||||
// HomomorphicHashDisabled returns global configuration value of homomorphic hashing
|
// HomomorphicHashDisabled returns global configuration value of homomorphic hashing
|
||||||
// settings.
|
// settings.
|
||||||
|
//
|
||||||
|
// Returns (false, nil) if config key is not found in the contract.
|
||||||
func (c *Client) HomomorphicHashDisabled() (bool, error) {
|
func (c *Client) HomomorphicHashDisabled() (bool, error) {
|
||||||
|
const defaultValue = false
|
||||||
|
|
||||||
hashingDisabled, err := c.readBoolConfig(homomorphicHashingDisabledKey)
|
hashingDisabled, err := c.readBoolConfig(homomorphicHashingDisabledKey)
|
||||||
if err != nil {
|
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 false, fmt.Errorf("(%T) could not get homomorphic hash state: %w", c, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,8 +328,14 @@ func bytesToUint64(val []byte) uint64 {
|
||||||
return bigint.FromBytes(val).Uint64()
|
return bigint.FromBytes(val).Uint64()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrConfigNotFound is returned when the requested key was not found
|
||||||
|
// in the network config (returned value is `Null`).
|
||||||
|
var ErrConfigNotFound = errors.New("config value not found")
|
||||||
|
|
||||||
// config performs the test invoke of get config value
|
// config performs the test invoke of get config value
|
||||||
// method of NeoFS Netmap contract.
|
// method of NeoFS Netmap contract.
|
||||||
|
//
|
||||||
|
// Returns ErrConfigNotFound if config key is not found in the contract.
|
||||||
func (c *Client) config(key []byte, assert func(stackitem.Item) (interface{}, error)) (interface{}, error) {
|
func (c *Client) config(key []byte, assert func(stackitem.Item) (interface{}, error)) (interface{}, error) {
|
||||||
prm := client.TestInvokePrm{}
|
prm := client.TestInvokePrm{}
|
||||||
prm.SetMethod(configMethod)
|
prm.SetMethod(configMethod)
|
||||||
|
@ -337,6 +352,10 @@ func (c *Client) config(key []byte, assert func(stackitem.Item) (interface{}, er
|
||||||
configMethod, ln)
|
configMethod, ln)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, ok := items[0].(stackitem.Null); ok {
|
||||||
|
return nil, ErrConfigNotFound
|
||||||
|
}
|
||||||
|
|
||||||
return assert(items[0])
|
return assert(items[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue