2024-02-02 12:36:14 +00:00
|
|
|
package helper
|
2024-02-02 06:49:03 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|