forked from blockwatch-cc/tzgo
/
pvm.go
55 lines (46 loc) · 905 Bytes
/
pvm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2023 Blockwatch Data Inc.
// Author: alex@blockwatch.cc
package mavryk
import (
"fmt"
)
type PvmKind byte
const (
PvmKindArith PvmKind = iota // 0
PvmKindWasm200 // 1
PvmKindInvalid = 255
)
func (t PvmKind) IsValid() bool {
return t != PvmKindInvalid
}
func (t *PvmKind) UnmarshalText(data []byte) error {
v := ParsePvmKind(string(data))
if !v.IsValid() {
return fmt.Errorf("tezos: invalid PVM kind '%s'", string(data))
}
*t = v
return nil
}
func (t PvmKind) MarshalText() ([]byte, error) {
return []byte(t.String()), nil
}
func ParsePvmKind(s string) PvmKind {
switch s {
case "arith":
return PvmKindArith
case "wasm_2_0_0":
return PvmKindWasm200
default:
return PvmKindInvalid
}
}
func (t PvmKind) String() string {
switch t {
case PvmKindArith:
return "arith"
case PvmKindWasm200:
return "wasm_2_0_0"
default:
return ""
}
}