-
Notifications
You must be signed in to change notification settings - Fork 109
/
wasm.go
82 lines (67 loc) · 1.69 KB
/
wasm.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package types
import (
"reflect"
"regexp"
"github.com/33cn/chain33/types"
)
var NameReg *regexp.Regexp
const (
WasmX = "wasm"
NameRegExp = "^[a-z0-9]+$"
//TODO: max size to define
MaxCodeSize = 1 << 20
)
// action for executor
const (
WasmActionCreate = iota + 1
WasmActionUpdate
WasmActionCall
)
// log ty for executor
const (
TyLogWasmCreate = iota + 100
TyLogWasmUpdate
TyLogWasmCall
TyLogCustom
TyLogLocalData
)
func init() {
types.AllowUserExec = append(types.AllowUserExec, []byte(WasmX))
types.RegFork(WasmX, InitFork)
types.RegExec(WasmX, InitExecutor)
NameReg, _ = regexp.Compile(NameRegExp)
}
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(WasmX, "Enable", 0)
}
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(WasmX, NewType(cfg))
}
type WasmType struct {
types.ExecTypeBase
}
func NewType(cfg *types.Chain33Config) *WasmType {
c := &WasmType{}
c.SetChild(c)
c.SetConfig(cfg)
return c
}
func (t *WasmType) GetPayload() types.Message {
return &WasmAction{}
}
func (t *WasmType) GetTypeMap() map[string]int32 {
return map[string]int32{
"Create": WasmActionCreate,
"Update": WasmActionUpdate,
"Call": WasmActionCall,
}
}
func (t *WasmType) GetLogMap() map[int64]*types.LogInfo {
return map[int64]*types.LogInfo{
TyLogWasmCreate: {Ty: reflect.TypeOf(CreateContractLog{}), Name: "LogWasmCreate"},
TyLogWasmUpdate: {Ty: reflect.TypeOf(UpdateContractLog{}), Name: "LogWasmUpdate"},
TyLogWasmCall: {Ty: reflect.TypeOf(CallContractLog{}), Name: "LogWasmCall"},
TyLogCustom: {Ty: reflect.TypeOf(CustomLog{}), Name: "LogWasmCustom"},
TyLogLocalData: {Ty: reflect.TypeOf(LocalDataLog{}), Name: "LogWasmLocalData"},
}
}