-
Notifications
You must be signed in to change notification settings - Fork 2
/
v12.go
130 lines (112 loc) · 4.05 KB
/
v12.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package stafi_decoder
import (
"encoding/json"
"github.com/huandu/xstrings"
"github.com/itering/scale.go/utiles"
)
type MetadataV12Decoder struct {
ScaleDecoder
}
type ExtrinsicMetadata struct {
SignedExtensions []string `json:"signedExtensions"`
}
func (m *MetadataV12Decoder) Init(data ScaleBytes, option *ScaleDecoderOption) {
m.ScaleDecoder.Init(data, option)
}
func (m *MetadataV12Decoder) Process() {
// var callModuleIndex, eventModuleIndex int
result := MetadataStruct{
Metadata: MetadataTag{
Modules: nil,
},
}
MetadataV11ModuleCall := m.ProcessAndUpdateData("Vec<MetadataV12Module>").([]interface{})
bm, _ := json.Marshal(MetadataV11ModuleCall)
var modulesType []MetadataModules
_ = json.Unmarshal(bm, &modulesType)
result.CallIndex = make(map[string]CallIndex)
result.EventIndex = make(map[string]EventIndex)
for k, module := range modulesType {
if module.Calls != nil {
for callIndex, call := range module.Calls {
modulesType[k].Calls[callIndex].Lookup = xstrings.RightJustify(utiles.IntToHex(module.Index), 2, "0") + xstrings.RightJustify(utiles.IntToHex(callIndex), 2, "0")
result.CallIndex[modulesType[k].Calls[callIndex].Lookup] = CallIndex{Module: module, Call: call}
}
}
if module.Events != nil {
for eventIndex, event := range module.Events {
modulesType[k].Events[eventIndex].Lookup = xstrings.RightJustify(utiles.IntToHex(module.Index), 2, "0") + xstrings.RightJustify(utiles.IntToHex(eventIndex), 2, "0")
result.EventIndex[modulesType[k].Events[eventIndex].Lookup] = EventIndex{Module: module, Call: event}
}
}
}
result.Metadata.Modules = modulesType
extrinsicMetadata := m.ProcessAndUpdateData("ExtrinsicMetadata").(map[string]interface{})
bm, _ = json.Marshal(extrinsicMetadata)
_ = json.Unmarshal(bm, &result.Extrinsic)
m.Value = result
}
type MetadataV12Module struct {
ScaleDecoder
Name string `json:"name"`
Prefix string `json:"prefix"`
CallIndex string `json:"call_index"`
HasStorage bool `json:"has_storage"`
Storage []MetadataStorage `json:"storage"`
HasCalls bool `json:"has_calls"`
Calls []MetadataModuleCall `json:"calls"`
HasEvents bool `json:"has_events"`
Events []MetadataEvents `json:"events"`
Constants []map[string]interface{} `json:"constants"`
Errors []MetadataModuleError `json:"errors"`
Index int `json:"index"`
}
func (m *MetadataV12Module) GetIdentifier() string {
return m.Name
}
func (m *MetadataV12Module) Process() {
cm := MetadataV12Module{}
cm.Name = m.ProcessAndUpdateData("String").(string)
// storage
cm.HasStorage = m.ProcessAndUpdateData("bool").(bool)
if cm.HasStorage {
storageValue := m.ProcessAndUpdateData("MetadataV7ModuleStorage").(MetadataV7ModuleStorage)
cm.Storage = storageValue.Items
cm.Prefix = storageValue.Prefix
}
// call
cm.HasCalls = m.ProcessAndUpdateData("bool").(bool)
if cm.HasCalls {
callValue := m.ProcessAndUpdateData("Vec<MetadataModuleCall>").([]interface{})
var calls []MetadataModuleCall
for _, v := range callValue {
calls = append(calls, v.(MetadataModuleCall))
}
cm.Calls = calls
}
// event
cm.HasEvents = m.ProcessAndUpdateData("bool").(bool)
if cm.HasEvents {
eventValue := m.ProcessAndUpdateData("Vec<MetadataModuleEvent>").([]interface{})
var events []MetadataEvents
for _, v := range eventValue {
events = append(events, v.(MetadataEvents))
}
cm.Events = events
}
// constant
constantValue := m.ProcessAndUpdateData("Vec<MetadataV7ModuleConstants>").([]interface{})
var constants []map[string]interface{}
for _, v := range constantValue {
constants = append(constants, v.(map[string]interface{}))
}
cm.Constants = constants
errorValue := m.ProcessAndUpdateData("Vec<MetadataModuleError>").([]interface{})
var errors []MetadataModuleError
for _, v := range errorValue {
errors = append(errors, v.(MetadataModuleError))
}
cm.Errors = errors
cm.Index = m.ProcessAndUpdateData("U8").(int)
m.Value = cm
}