github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/vm/opcode/from_string.go (about) 1 package opcode 2 3 import "errors" 4 5 var stringToOpcode = make(map[string]Opcode) 6 7 func init() { 8 for i := 0; i < 255; i++ { 9 op := Opcode(i) 10 stringToOpcode[op.String()] = op 11 } 12 } 13 14 // FromString converts string representation to an opcode itself. 15 func FromString(s string) (Opcode, error) { 16 if op, ok := stringToOpcode[s]; ok { 17 return op, nil 18 } 19 return 0, errors.New("invalid opcode") 20 }