/
interop_service.go
50 lines (42 loc) · 1.55 KB
/
interop_service.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
package vm
type InteropService struct {
dictionary map[string]func(*ExecutionEngine) bool
}
func NewInteropService() *InteropService {
var is InteropService
is.dictionary = make(map[string]func(*ExecutionEngine) bool, 0)
is.Register("System.ScriptEngine.GetScriptContainer", is.GetScriptContainer)
is.Register("System.ScriptEngine.GetExecutingScriptHash", is.GetExecutingScriptHash)
is.Register("System.ScriptEngine.GetCallingScriptHash", is.GetCallingScriptHash)
is.Register("System.ScriptEngine.GetEntryScriptHash", is.GetEntryScriptHash)
return &is
}
func (is *InteropService) Register(method string, handler func(*ExecutionEngine) bool) bool {
if _, ok := is.dictionary[method]; ok {
return false
}
is.dictionary[method] = handler
return true
}
func (is *InteropService) Invoke(method string, engine *ExecutionEngine) bool {
if v, ok := is.dictionary[method]; ok {
return v(engine)
}
return false
}
func (is *InteropService) GetScriptContainer(engine *ExecutionEngine) bool {
engine.evaluationStack.Push(engine.scriptContainer)
return true
}
func (is *InteropService) GetExecutingScriptHash(engine *ExecutionEngine) bool {
engine.evaluationStack.Push(engine.crypto.Hash160(engine.ExecutingScript()))
return true
}
func (is *InteropService) GetCallingScriptHash(engine *ExecutionEngine) bool {
engine.evaluationStack.Push(engine.crypto.Hash160(engine.CallingScript()))
return true
}
func (is *InteropService) GetEntryScriptHash(engine *ExecutionEngine) bool {
engine.evaluationStack.Push(engine.crypto.Hash160(engine.EntryScript()))
return true
}