-
Notifications
You must be signed in to change notification settings - Fork 2
/
v10.go
52 lines (45 loc) · 1.58 KB
/
v10.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
package stafi_decoder
import (
"encoding/json"
"github.com/huandu/xstrings"
"github.com/itering/scale.go/utiles"
)
type MetadataV10Decoder struct {
ScaleDecoder
}
func (m *MetadataV10Decoder) Init(data ScaleBytes, option *ScaleDecoderOption) {
m.ScaleDecoder.Init(data, option)
}
func (m *MetadataV10Decoder) Process() {
result := MetadataStruct{
Metadata: MetadataTag{
Modules: nil,
},
}
MetadataV10ModuleCall := m.ProcessAndUpdateData("Vec<MetadataV8Module>").([]interface{})
callModuleIndex := 0
eventModuleIndex := 0
result.CallIndex = make(map[string]CallIndex)
result.EventIndex = make(map[string]EventIndex)
bm, _ := json.Marshal(MetadataV10ModuleCall)
var modulesType []MetadataModules
_ = json.Unmarshal(bm, &modulesType)
for k, module := range modulesType {
if module.Calls != nil {
for callIndex, call := range module.Calls {
modulesType[k].Calls[callIndex].Lookup = xstrings.RightJustify(utiles.IntToHex(callModuleIndex), 2, "0") + xstrings.RightJustify(utiles.IntToHex(callIndex), 2, "0")
result.CallIndex[modulesType[k].Calls[callIndex].Lookup] = CallIndex{Module: module, Call: call}
}
callModuleIndex++
}
if module.Events != nil {
for eventIndex, event := range module.Events {
modulesType[k].Events[eventIndex].Lookup = xstrings.RightJustify(utiles.IntToHex(eventModuleIndex), 2, "0") + xstrings.RightJustify(utiles.IntToHex(eventIndex), 2, "0")
result.EventIndex[modulesType[k].Events[eventIndex].Lookup] = EventIndex{Module: module, Call: event}
}
eventModuleIndex++
}
}
result.Metadata.Modules = modulesType
m.Value = result
}