github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/core/native/noderoles/role.go (about) 1 package noderoles 2 3 //go:generate stringer -type=Role 4 5 // Role represents the type of the participant. 6 type Role byte 7 8 // Role enumeration. 9 const ( 10 _ Role = 1 << iota 11 _ 12 StateValidator 13 Oracle 14 NeoFSAlphabet 15 P2PNotary 16 // last denotes the end of roles enum. Consider adding new roles before the last. 17 last 18 ) 19 20 // Roles is a set of all available roles sorted by values. 21 var Roles []Role 22 23 // roles is a map of valid Role string representation to its type. 24 var roles map[string]Role 25 26 func init() { 27 roles = make(map[string]Role) 28 for i := StateValidator; i < last; i = i << 1 { 29 roles[i.String()] = i 30 Roles = append(Roles, i) 31 } 32 } 33 34 // FromString returns a node role parsed from its string representation and a 35 // boolean value denoting whether the conversion was OK and the role exists. 36 func FromString(s string) (Role, bool) { 37 r, ok := roles[s] 38 return r, ok 39 }