Anton Nikiforov
802192cfef
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 1m57s
DCO action / DCO (pull_request) Successful in 3m3s
Build / Build Components (1.21) (pull_request) Successful in 5m0s
Build / Build Components (1.20) (pull_request) Successful in 5m6s
Tests and linters / Tests (1.20) (pull_request) Successful in 7m1s
Tests and linters / Staticcheck (pull_request) Successful in 6m55s
Tests and linters / Lint (pull_request) Successful in 7m30s
Tests and linters / Tests (1.21) (pull_request) Successful in 7m53s
Tests and linters / Tests with -race (pull_request) Successful in 8m21s
To avoid conflicts with `util` packages in other imports. Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
35 lines
791 B
Go
35 lines
791 B
Go
package helper
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
const frostfsIDAdminConfigKey = "frostfsid.admin"
|
|
|
|
func GetFrostfsIDAdmin(v *viper.Viper) (util.Uint160, bool, error) {
|
|
admin := v.GetString(frostfsIDAdminConfigKey)
|
|
if admin == "" {
|
|
return util.Uint160{}, false, nil
|
|
}
|
|
|
|
h, err := address.StringToUint160(admin)
|
|
if err == nil {
|
|
return h, true, nil
|
|
}
|
|
|
|
h, err = util.Uint160DecodeStringLE(admin)
|
|
if err == nil {
|
|
return h, true, nil
|
|
}
|
|
|
|
pk, err := keys.NewPublicKeyFromString(admin)
|
|
if err == nil {
|
|
return pk.GetScriptHash(), true, nil
|
|
}
|
|
return util.Uint160{}, true, fmt.Errorf("frostfsid: admin is invalid: '%s'", admin)
|
|
}
|