neo-go/pkg/vm/opcode/from_string.go
Elizaveta Chichindaeva 28908aa3cf [#2442] English Check
Signed-off-by: Elizaveta Chichindaeva <elizaveta@nspcc.ru>
2022-05-04 19:48:27 +03:00

20 lines
390 B
Go

package opcode
import "errors"
var stringToOpcode = make(map[string]Opcode)
func init() {
for i := 0; i < 255; i++ {
op := Opcode(i)
stringToOpcode[op.String()] = op
}
}
// FromString converts string representation to an opcode itself.
func FromString(s string) (Opcode, error) {
if op, ok := stringToOpcode[s]; ok {
return op, nil
}
return 0, errors.New("invalid opcode")
}