scale_rb 0.1.15 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,203 +1,207 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Metadata
4
- module MetadataV14
5
- class << self
6
- def build_registry(metadata)
7
- types = metadata._get(:lookup)._get(:types)
8
- types.map { |type| [type._get(:id), type._get(:type)] }.to_h
9
- end
3
+ module ScaleRb
4
+ module Metadata
5
+ module MetadataV14
6
+ class << self
7
+ def build_registry(metadata)
8
+ types = metadata._get(:lookup)._get(:types)
9
+ types.map { |type| [type._get(:id), type._get(:type)] }.to_h
10
+ end
10
11
 
11
- def get_module(pallet_name, metadata)
12
- metadata._get(:metadata)._get(:v14)._get(:pallets).find do |p|
13
- p._get(:name) == pallet_name
12
+ def get_module(pallet_name, metadata)
13
+ metadata._get(:metadata)._get(:v14)._get(:pallets).find do |p|
14
+ p._get(:name) == pallet_name
15
+ end
14
16
  end
15
- end
16
17
 
17
- def get_module_by_index(pallet_index, metadata)
18
- metadata._get(:metadata)._get(:v14)._get(:pallets).find do |p|
19
- p._get(:index) == pallet_index
18
+ def get_module_by_index(pallet_index, metadata)
19
+ metadata._get(:metadata)._get(:v14)._get(:pallets).find do |p|
20
+ p._get(:index) == pallet_index
21
+ end
20
22
  end
21
- end
22
23
 
23
- def get_storage_item(pallet_name, item_name, metadata)
24
- pallet = get_module(pallet_name, metadata)
25
- raise "Pallet `#{pallet_name}` not found" if pallet.nil?
26
- pallet._get(:storage)._get(:items).find do |item|
27
- item._get(:name) == item_name
24
+ def get_storage_item(pallet_name, item_name, metadata)
25
+ pallet = get_module(pallet_name, metadata)
26
+ raise "Pallet `#{pallet_name}` not found" if pallet.nil?
27
+
28
+ pallet._get(:storage)._get(:items).find do |item|
29
+ item._get(:name) == item_name
30
+ end
28
31
  end
29
- end
30
32
 
31
- def get_calls_type_id(pallet_name, metadata)
32
- pallet = get_module(pallet_name, metadata)
33
- raise "Pallet `#{pallet_name}` not found" if pallet.nil?
34
- pallet._get(:calls)._get(:type)
35
- end
33
+ def get_calls_type_id(pallet_name, metadata)
34
+ pallet = get_module(pallet_name, metadata)
35
+ raise "Pallet `#{pallet_name}` not found" if pallet.nil?
36
36
 
37
- def get_calls_type(pallet_name, metadata)
38
- type_id = get_calls_type_id(pallet_name, metadata)
39
- metadata._get(:metadata)._get(:v14)._get(:lookup)._get(:types).find do |type|
40
- type._get(:id) == type_id
37
+ pallet._get(:calls)._get(:type)
38
+ end
39
+
40
+ def get_calls_type(pallet_name, metadata)
41
+ type_id = get_calls_type_id(pallet_name, metadata)
42
+ metadata._get(:metadata)._get(:v14)._get(:lookup)._get(:types).find do |type|
43
+ type._get(:id) == type_id
44
+ end
41
45
  end
42
- end
43
46
 
44
- def get_call_type(pallet_name, call_name, metadata)
45
- calls_type = get_calls_type(pallet_name, metadata)
46
- calls_type._get(:type)._get(:def)._get(:variant)._get(:variants).find do |variant|
47
- variant._get(:name).downcase == call_name.downcase
47
+ def get_call_type(pallet_name, call_name, metadata)
48
+ calls_type = get_calls_type(pallet_name, metadata)
49
+ calls_type._get(:type)._get(:def)._get(:variant)._get(:variants).find do |variant|
50
+ variant._get(:name).downcase == call_name.downcase
51
+ end
48
52
  end
49
53
  end
50
- end
51
54
 
52
- TYPES = {
53
- MetadataV14: {
54
- lookup: 'PortableRegistry',
55
- pallets: 'Vec<PalletMetadataV14>',
56
- extrinsic: 'ExtrinsicMetadataV14',
57
- type: 'SiLookupTypeId'
58
- },
55
+ TYPES = {
56
+ MetadataV14: {
57
+ lookup: 'PortableRegistry',
58
+ pallets: 'Vec<PalletMetadataV14>',
59
+ extrinsic: 'ExtrinsicMetadataV14',
60
+ type: 'SiLookupTypeId'
61
+ },
59
62
 
60
- # PortableRegistry begin
61
- PortableRegistry: {
62
- types: 'Vec<PortableTypeV14>'
63
- },
64
- PortableTypeV14: {
65
- id: 'Si1LookupTypeId',
66
- type: 'Si1Type'
67
- },
68
- Si1LookupTypeId: 'Compact',
69
- Si1Type: {
70
- path: 'Si1Path',
71
- params: 'Vec<Si1TypeParameter>',
72
- def: 'Si1TypeDef',
73
- docs: 'Vec<Text>'
74
- },
75
- Si1Path: 'Vec<Text>',
76
- Si1TypeParameter: {
77
- name: 'Text',
78
- type: 'Option<Si1LookupTypeId>'
79
- },
80
- Si1TypeDef: {
81
- _enum: {
82
- composite: 'Si1TypeDefComposite',
83
- variant: 'Si1TypeDefVariant',
84
- sequence: 'Si1TypeDefSequence',
85
- array: 'Si1TypeDefArray',
86
- tuple: 'Si1TypeDefTuple',
87
- primitive: 'Si1TypeDefPrimitive',
88
- compact: 'Si1TypeDefCompact',
89
- bitSequence: 'Si1TypeDefBitSequence',
90
- historicMetaCompat: 'Text' # TODO: sanitize?
91
- }
92
- },
93
- Si1TypeDefComposite: {
94
- fields: 'Vec<Si1Field>'
95
- },
96
- Si1Field: {
97
- name: 'Option<Text>',
98
- type: 'Si1LookupTypeId',
99
- typeName: 'Option<Text>',
100
- docs: 'Vec<Text>'
101
- },
102
- Si1TypeDefVariant: {
103
- variants: 'Vec<Si1Variant>'
104
- },
105
- Si1Variant: {
106
- name: 'Text',
107
- fields: 'Vec<Si1Field>',
108
- index: 'u8',
109
- docs: 'Vec<Text>'
110
- },
111
- Si1TypeDefSequence: {
112
- type: 'Si1LookupTypeId'
113
- },
114
- Si1TypeDefArray: {
115
- len: 'u32',
116
- type: 'Si1LookupTypeId'
117
- },
118
- Si1TypeDefTuple: 'Vec<Si1LookupTypeId>',
119
- Si1TypeDefPrimitive: {
120
- _enum: %w[
121
- Bool Char Str U8 U16 U32 U64 U128 U256 I8 I16 I32 I64 I128 I256
122
- ]
123
- },
124
- Si1TypeDefCompact: {
125
- type: 'Si1LookupTypeId'
126
- },
127
- Si1TypeDefBitSequence: {
128
- bitStoreType: 'Si1LookupTypeId',
129
- bitOrderType: 'Si1LookupTypeId'
130
- },
131
- # PortableRegistry end
63
+ # PortableRegistry begin
64
+ PortableRegistry: {
65
+ types: 'Vec<PortableTypeV14>'
66
+ },
67
+ PortableTypeV14: {
68
+ id: 'Si1LookupTypeId',
69
+ type: 'Si1Type'
70
+ },
71
+ Si1LookupTypeId: 'Compact',
72
+ Si1Type: {
73
+ path: 'Si1Path',
74
+ params: 'Vec<Si1TypeParameter>',
75
+ def: 'Si1TypeDef',
76
+ docs: 'Vec<Text>'
77
+ },
78
+ Si1Path: 'Vec<Text>',
79
+ Si1TypeParameter: {
80
+ name: 'Text',
81
+ type: 'Option<Si1LookupTypeId>'
82
+ },
83
+ Si1TypeDef: {
84
+ _enum: {
85
+ composite: 'Si1TypeDefComposite',
86
+ variant: 'Si1TypeDefVariant',
87
+ sequence: 'Si1TypeDefSequence',
88
+ array: 'Si1TypeDefArray',
89
+ tuple: 'Si1TypeDefTuple',
90
+ primitive: 'Si1TypeDefPrimitive',
91
+ compact: 'Si1TypeDefCompact',
92
+ bitSequence: 'Si1TypeDefBitSequence',
93
+ historicMetaCompat: 'Text' # TODO: sanitize?
94
+ }
95
+ },
96
+ Si1TypeDefComposite: {
97
+ fields: 'Vec<Si1Field>'
98
+ },
99
+ Si1Field: {
100
+ name: 'Option<Text>',
101
+ type: 'Si1LookupTypeId',
102
+ typeName: 'Option<Text>',
103
+ docs: 'Vec<Text>'
104
+ },
105
+ Si1TypeDefVariant: {
106
+ variants: 'Vec<Si1Variant>'
107
+ },
108
+ Si1Variant: {
109
+ name: 'Text',
110
+ fields: 'Vec<Si1Field>',
111
+ index: 'u8',
112
+ docs: 'Vec<Text>'
113
+ },
114
+ Si1TypeDefSequence: {
115
+ type: 'Si1LookupTypeId'
116
+ },
117
+ Si1TypeDefArray: {
118
+ len: 'u32',
119
+ type: 'Si1LookupTypeId'
120
+ },
121
+ Si1TypeDefTuple: 'Vec<Si1LookupTypeId>',
122
+ Si1TypeDefPrimitive: {
123
+ _enum: %w[
124
+ Bool Char Str U8 U16 U32 U64 U128 U256 I8 I16 I32 I64 I128 I256
125
+ ]
126
+ },
127
+ Si1TypeDefCompact: {
128
+ type: 'Si1LookupTypeId'
129
+ },
130
+ Si1TypeDefBitSequence: {
131
+ bitStoreType: 'Si1LookupTypeId',
132
+ bitOrderType: 'Si1LookupTypeId'
133
+ },
134
+ # PortableRegistry end
132
135
 
133
- # PalletMetadataV14 begin
134
- PalletMetadataV14: {
135
- name: 'Text',
136
- storage: 'Option<PalletStorageMetadataV14>',
137
- calls: 'Option<PalletCallMetadataV14>',
138
- events: 'Option<PalletEventMetadataV14>',
139
- constants: 'Vec<PalletConstantMetadataV14>',
140
- errors: 'Option<PalletErrorMetadataV14>',
141
- index: 'U8'
142
- },
143
- PalletStorageMetadataV14: {
144
- prefix: 'Text',
145
- items: 'Vec<StorageEntryMetadataV14>'
146
- },
147
- StorageEntryMetadataV14: {
148
- name: 'Text',
149
- modifier: 'StorageEntryModifierV14',
150
- type: 'StorageEntryTypeV14',
151
- fallback: 'Bytes',
152
- docs: 'Vec<Text>'
153
- },
154
- StorageEntryModifierV14: {
155
- _enum: %w[Optional Default Required]
156
- },
157
- StorageEntryTypeV14: {
158
- _enum: {
159
- plain: 'SiLookupTypeId',
160
- map: {
161
- hashers: 'Vec<StorageHasherV14>',
162
- key: 'SiLookupTypeId',
163
- value: 'SiLookupTypeId'
136
+ # PalletMetadataV14 begin
137
+ PalletMetadataV14: {
138
+ name: 'Text',
139
+ storage: 'Option<PalletStorageMetadataV14>',
140
+ calls: 'Option<PalletCallMetadataV14>',
141
+ events: 'Option<PalletEventMetadataV14>',
142
+ constants: 'Vec<PalletConstantMetadataV14>',
143
+ errors: 'Option<PalletErrorMetadataV14>',
144
+ index: 'U8'
145
+ },
146
+ PalletStorageMetadataV14: {
147
+ prefix: 'Text',
148
+ items: 'Vec<StorageEntryMetadataV14>'
149
+ },
150
+ StorageEntryMetadataV14: {
151
+ name: 'Text',
152
+ modifier: 'StorageEntryModifierV14',
153
+ type: 'StorageEntryTypeV14',
154
+ fallback: 'Bytes',
155
+ docs: 'Vec<Text>'
156
+ },
157
+ StorageEntryModifierV14: {
158
+ _enum: %w[Optional Default Required]
159
+ },
160
+ StorageEntryTypeV14: {
161
+ _enum: {
162
+ plain: 'SiLookupTypeId',
163
+ map: {
164
+ hashers: 'Vec<StorageHasherV14>',
165
+ key: 'SiLookupTypeId',
166
+ value: 'SiLookupTypeId'
167
+ }
164
168
  }
165
- }
166
- },
167
- StorageHasherV14: {
168
- _enum: %w[Blake2128 Blake2256 Blake2128Concat Twox128 Twox256 Twox64Concat Identity]
169
- },
170
- PalletCallMetadataV14: {
171
- type: 'Si1LookupTypeId'
172
- },
173
- PalletEventMetadataV14: {
174
- type: 'SiLookupTypeId'
175
- },
176
- PalletConstantMetadataV14: {
177
- name: 'Text',
178
- type: 'SiLookupTypeId',
179
- value: 'Bytes',
180
- docs: 'Vec<Text>'
181
- },
182
- PalletErrorMetadataV14: {
183
- type: 'SiLookupTypeId'
184
- },
185
- # PalletMetadataV14 end
169
+ },
170
+ StorageHasherV14: {
171
+ _enum: %w[Blake2128 Blake2256 Blake2128Concat Twox128 Twox256 Twox64Concat Identity]
172
+ },
173
+ PalletCallMetadataV14: {
174
+ type: 'Si1LookupTypeId'
175
+ },
176
+ PalletEventMetadataV14: {
177
+ type: 'SiLookupTypeId'
178
+ },
179
+ PalletConstantMetadataV14: {
180
+ name: 'Text',
181
+ type: 'SiLookupTypeId',
182
+ value: 'Bytes',
183
+ docs: 'Vec<Text>'
184
+ },
185
+ PalletErrorMetadataV14: {
186
+ type: 'SiLookupTypeId'
187
+ },
188
+ # PalletMetadataV14 end
186
189
 
187
- # ExtrinsicMetadataV14 begin
188
- ExtrinsicMetadataV14: {
189
- type: 'SiLookupTypeId',
190
- version: 'u8',
191
- signedExtensions: 'Vec<SignedExtensionMetadataV14>'
192
- },
193
- SignedExtensionMetadataV14: {
194
- identifier: 'Text',
195
- type: 'SiLookupTypeId',
196
- additionalSigned: 'SiLookupTypeId'
197
- },
198
- # ExtrinsicMetadataV14 end
190
+ # ExtrinsicMetadataV14 begin
191
+ ExtrinsicMetadataV14: {
192
+ type: 'SiLookupTypeId',
193
+ version: 'u8',
194
+ signedExtensions: 'Vec<SignedExtensionMetadataV14>'
195
+ },
196
+ SignedExtensionMetadataV14: {
197
+ identifier: 'Text',
198
+ type: 'SiLookupTypeId',
199
+ additionalSigned: 'SiLookupTypeId'
200
+ },
201
+ # ExtrinsicMetadataV14 end
199
202
 
200
- SiLookupTypeId: 'Compact'
201
- }.freeze
203
+ SiLookupTypeId: 'Compact'
204
+ }.freeze
205
+ end
202
206
  end
203
207
  end
@@ -1,100 +1,103 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Metadata
4
- module MetadataV9
5
- class << self
6
- def get_module(module_name, metadata)
7
- metadata._get(:metadata)._get(:v9)._get(:modules).find do |m|
8
- m._get(:name) == module_name
3
+ module ScaleRb
4
+ module Metadata
5
+ module MetadataV9
6
+ class << self
7
+ def get_module(module_name, metadata)
8
+ metadata._get(:metadata)._get(:v9)._get(:modules).find do |m|
9
+ m._get(:name) == module_name
10
+ end
9
11
  end
10
- end
11
12
 
12
- def get_storage_item(module_name, item_name, metadata)
13
- modula = get_module(module_name, metadata)
14
- raise "Module `#{module_name}` not found" if modula.nil?
15
- modula._get(:storage)._get(:items).find do |item|
16
- item._get(:name) == item_name
13
+ def get_storage_item(module_name, item_name, metadata)
14
+ modula = get_module(module_name, metadata)
15
+ raise "Module `#{module_name}` not found" if modula.nil?
16
+
17
+ modula._get(:storage)._get(:items).find do |item|
18
+ item._get(:name) == item_name
19
+ end
17
20
  end
18
21
  end
19
- end
20
22
 
21
- TYPES = {
22
- ErrorMetadataV9: {
23
- name: 'Text',
24
- docs: 'Vec<Text>'
25
- },
26
- EventMetadataV9: {
27
- name: 'Text',
28
- args: 'Vec<Type>',
29
- docs: 'Vec<Text>'
30
- },
31
- FunctionArgumentMetadataV9: {
32
- name: 'Text',
33
- type: 'Type'
34
- },
35
- FunctionMetadataV9: {
36
- name: 'Text',
37
- args: 'Vec<FunctionArgumentMetadataV9>',
38
- docs: 'Vec<Text>'
39
- },
40
- MetadataV9: {
41
- modules: 'Vec<ModuleMetadataV9>'
42
- },
43
- ModuleConstantMetadataV9: {
44
- name: 'Text',
45
- type: 'Type',
46
- value: 'Bytes',
47
- docs: 'Vec<Text>'
48
- },
49
- ModuleMetadataV9: {
50
- name: 'Text',
51
- storage: 'Option<StorageMetadataV9>',
52
- calls: 'Option<Vec<FunctionMetadataV9>>',
53
- events: 'Option<Vec<EventMetadataV9>>',
54
- constants: 'Vec<ModuleConstantMetadataV9>',
55
- errors: 'Vec<ErrorMetadataV9>'
56
- },
57
- StorageEntryMetadataV9: {
58
- name: 'Text',
59
- modifier: 'StorageEntryModifierV9',
60
- type: 'StorageEntryTypeV9',
61
- fallback: 'Bytes',
62
- docs: 'Vec<Text>'
63
- },
64
- StorageEntryModifierV9: {
65
- _enum: %w[Optional Default Required]
66
- },
67
- StorageEntryTypeV9: {
68
- _enum: {
69
- Plain: 'Type',
70
- Map: {
71
- hasher: 'StorageHasherV9',
72
- key: 'Type',
73
- value: 'Type',
74
- linked: 'bool'
75
- },
76
- DoubleMap: {
77
- hasher: 'StorageHasherV9',
78
- key1: 'Type',
79
- key2: 'Type',
80
- value: 'Type',
81
- key2Hasher: 'StorageHasherV9'
23
+ TYPES = {
24
+ ErrorMetadataV9: {
25
+ name: 'Text',
26
+ docs: 'Vec<Text>'
27
+ },
28
+ EventMetadataV9: {
29
+ name: 'Text',
30
+ args: 'Vec<Type>',
31
+ docs: 'Vec<Text>'
32
+ },
33
+ FunctionArgumentMetadataV9: {
34
+ name: 'Text',
35
+ type: 'Type'
36
+ },
37
+ FunctionMetadataV9: {
38
+ name: 'Text',
39
+ args: 'Vec<FunctionArgumentMetadataV9>',
40
+ docs: 'Vec<Text>'
41
+ },
42
+ MetadataV9: {
43
+ modules: 'Vec<ModuleMetadataV9>'
44
+ },
45
+ ModuleConstantMetadataV9: {
46
+ name: 'Text',
47
+ type: 'Type',
48
+ value: 'Bytes',
49
+ docs: 'Vec<Text>'
50
+ },
51
+ ModuleMetadataV9: {
52
+ name: 'Text',
53
+ storage: 'Option<StorageMetadataV9>',
54
+ calls: 'Option<Vec<FunctionMetadataV9>>',
55
+ events: 'Option<Vec<EventMetadataV9>>',
56
+ constants: 'Vec<ModuleConstantMetadataV9>',
57
+ errors: 'Vec<ErrorMetadataV9>'
58
+ },
59
+ StorageEntryMetadataV9: {
60
+ name: 'Text',
61
+ modifier: 'StorageEntryModifierV9',
62
+ type: 'StorageEntryTypeV9',
63
+ fallback: 'Bytes',
64
+ docs: 'Vec<Text>'
65
+ },
66
+ StorageEntryModifierV9: {
67
+ _enum: %w[Optional Default Required]
68
+ },
69
+ StorageEntryTypeV9: {
70
+ _enum: {
71
+ Plain: 'Type',
72
+ Map: {
73
+ hasher: 'StorageHasherV9',
74
+ key: 'Type',
75
+ value: 'Type',
76
+ linked: 'bool'
77
+ },
78
+ DoubleMap: {
79
+ hasher: 'StorageHasherV9',
80
+ key1: 'Type',
81
+ key2: 'Type',
82
+ value: 'Type',
83
+ key2Hasher: 'StorageHasherV9'
84
+ }
82
85
  }
86
+ },
87
+ StorageHasherV9: {
88
+ _enum: %w[
89
+ Blake2_128
90
+ Blake2_256
91
+ Twox128
92
+ Twox256
93
+ Twox64Concat
94
+ ]
95
+ },
96
+ StorageMetadataV9: {
97
+ prefix: 'Text',
98
+ items: 'Vec<StorageEntryMetadataV9>'
83
99
  }
84
- },
85
- StorageHasherV9: {
86
- _enum: %w[
87
- Blake2_128
88
- Blake2_256
89
- Twox128
90
- Twox256
91
- Twox64Concat
92
- ]
93
- },
94
- StorageMetadataV9: {
95
- prefix: 'Text',
96
- items: 'Vec<StorageEntryMetadataV9>'
97
- }
98
- }.freeze
100
+ }.freeze
101
+ end
99
102
  end
100
103
  end