scale_rb 0.1.14 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,129 +1,137 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Metadata
4
- class << self
5
- def decode_metadata(bytes)
6
- metadata, = ScaleRb.decode('MetadataTop', bytes, TYPES)
7
- metadata
3
+ module ScaleRb
4
+ module Metadata
5
+ class << self
6
+ def decode_metadata(bytes)
7
+ metadata, = ScaleRb.decode('MetadataTop', bytes, TYPES)
8
+ metadata
9
+ end
10
+
11
+ def build_registry(metadata)
12
+ raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless metadata._get(:metadata)._key?(:v14)
13
+
14
+ metadata_v14 = metadata._get(:metadata)._get(:v14)
15
+ MetadataV14.build_registry(metadata_v14)
16
+ end
17
+
18
+ def get_module(pallet_name, metadata)
19
+ version = metadata._get(:metadata).keys.first
20
+ raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless %w[v9 v10 v11 v12 v13
21
+ v14].include?(version.to_s)
22
+
23
+ Metadata.const_get("Metadata#{version.upcase}").get_module(pallet_name, metadata)
24
+ end
25
+
26
+ def get_module_by_index(pallet_index, metadata)
27
+ version = metadata._get(:metadata).keys.first
28
+ raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless %w[v9 v10 v11 v12 v13
29
+ v14].include?(version.to_s)
30
+
31
+ Metadata.const_get("Metadata#{version.upcase}").get_module_by_index(pallet_index, metadata)
32
+ end
33
+
34
+ def get_storage_item(pallet_name, item_name, metadata)
35
+ version = metadata._get(:metadata).keys.first
36
+ raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless %w[v9 v10 v11 v12 v13
37
+ v14].include?(version.to_s)
38
+
39
+ Metadata.const_get("Metadata#{version.upcase}").get_storage_item(pallet_name, item_name, metadata)
40
+ end
41
+
42
+ def get_calls_type(pallet_name, metadata)
43
+ version = metadata._get(:metadata).keys.first
44
+ raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless %w[v9 v10 v11 v12 v13
45
+ v14].include?(version.to_s)
46
+
47
+ Metadata.const_get("Metadata#{version.upcase}").get_calls_type(pallet_name, metadata)
48
+ end
49
+
50
+ def get_calls_type_id(pallet_name, metadata)
51
+ version = metadata._get(:metadata).keys.first
52
+ raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless %w[v9 v10 v11 v12 v13
53
+ v14].include?(version.to_s)
54
+
55
+ Metadata.const_get("Metadata#{version.upcase}").get_calls_type_id(pallet_name, metadata)
56
+ end
57
+
58
+ def get_call_type(pallet_name, call_name, metadata)
59
+ version = metadata._get(:metadata).keys.first
60
+ raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless %w[v9 v10 v11 v12 v13
61
+ v14].include?(version.to_s)
62
+
63
+ Metadata.const_get("Metadata#{version.upcase}").get_call_type(pallet_name, call_name, metadata)
64
+ end
65
+
66
+ # call examples:
67
+ # {:pallet_name=>"Deposit", :call_name=>"Claim", :call=>["claim", []]}
68
+ # {:pallet_name=>"Balances", :call_name=>"Transfer", :call=>[{:transfer=>{:dest=>[10, 18, 135, 151, 117, 120, 248, 136, 189, 193, 199, 98, 119, 129, 175, 28, 192, 0, 230, 171], :value=>11000000000000000000}}, []]}
69
+ def encode_call(call, metadata)
70
+ calls_type_id = get_calls_type_id(call[:pallet_name], metadata)
71
+ pallet_index = get_module(call[:pallet_name], metadata)._get(:index)
72
+ [pallet_index] + PortableCodec.encode(calls_type_id, call[:call].first, build_registry(metadata))
73
+ end
74
+
75
+ # callbytes's structure is: pallet_index + call_index + argsbytes
76
+ #
77
+ # callbytes examples:
78
+ # "0x0901"._to_bytes
79
+ # "0x05000a1287977578f888bdc1c7627781af1cc000e6ab1300004c31b8d9a798"._to_bytes
80
+ def decode_call(callbytes, metadata)
81
+ pallet_index = callbytes[0]
82
+ pallet = get_module_by_index(pallet_index, metadata)
83
+
84
+ pallet_name = pallet._get(:name)
85
+
86
+ # Remove the pallet_index
87
+ # The callbytes we used below should not contain the pallet index.
88
+ # This is because the pallet index is not part of the call type.
89
+ # Its structure is: call_index + call_args
90
+ callbytes_without_pallet_index = callbytes[1..]
91
+ calls_type_id = pallet._get(:calls)._get(:type)
92
+ decoded = PortableCodec.decode(
93
+ calls_type_id,
94
+ callbytes_without_pallet_index,
95
+ build_registry(metadata)
96
+ )
97
+
98
+ {
99
+ pallet_name: pallet_name,
100
+ call_name: decoded.first.is_a?(String) ? decoded.first._to_camel : decoded.first.keys.first.to_s._to_camel,
101
+ call: decoded
102
+ }
103
+ end
8
104
  end
9
105
 
10
- def build_registry(metadata)
11
- raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless metadata._get(:metadata)._key?(:v14)
12
-
13
- metadata_v14 = metadata._get(:metadata)._get(:v14)
14
- MetadataV14.build_registry(metadata_v14)
15
- end
16
-
17
- def get_module(pallet_name, metadata)
18
- version = metadata._get(:metadata).keys.first
19
- raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless %w[v9 v10 v11 v12 v13 v14].include?(version.to_s)
20
-
21
- Metadata.const_get("Metadata#{version.upcase}").get_module(pallet_name, metadata)
22
- end
23
-
24
- def get_module_by_index(pallet_index, metadata)
25
- version = metadata._get(:metadata).keys.first
26
- raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless %w[v9 v10 v11 v12 v13 v14].include?(version.to_s)
27
-
28
- Metadata.const_get("Metadata#{version.upcase}").get_module_by_index(pallet_index, metadata)
29
- end
30
-
31
- def get_storage_item(pallet_name, item_name, metadata)
32
- version = metadata._get(:metadata).keys.first
33
- raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless %w[v9 v10 v11 v12 v13 v14].include?(version.to_s)
34
-
35
- Metadata.const_get("Metadata#{version.upcase}").get_storage_item(pallet_name, item_name, metadata)
36
- end
37
-
38
- def get_calls_type(pallet_name, metadata)
39
- version = metadata._get(:metadata).keys.first
40
- raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless %w[v9 v10 v11 v12 v13 v14].include?(version.to_s)
41
-
42
- Metadata.const_get("Metadata#{version.upcase}").get_calls_type(pallet_name, metadata)
43
- end
44
-
45
- def get_calls_type_id(pallet_name, metadata)
46
- version = metadata._get(:metadata).keys.first
47
- raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless %w[v9 v10 v11 v12 v13 v14].include?(version.to_s)
48
-
49
- Metadata.const_get("Metadata#{version.upcase}").get_calls_type_id(pallet_name, metadata)
50
- end
51
-
52
- def get_call_type(pallet_name, call_name, metadata)
53
- version = metadata._get(:metadata).keys.first
54
- raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless %w[v9 v10 v11 v12 v13 v14].include?(version.to_s)
55
-
56
- Metadata.const_get("Metadata#{version.upcase}").get_call_type(pallet_name, call_name, metadata)
57
- end
58
-
59
- # call examples:
60
- # {:pallet_name=>"Deposit", :call_name=>"Claim", :call=>["claim", []]}
61
- # {:pallet_name=>"Balances", :call_name=>"Transfer", :call=>[{:transfer=>{:dest=>[10, 18, 135, 151, 117, 120, 248, 136, 189, 193, 199, 98, 119, 129, 175, 28, 192, 0, 230, 171], :value=>11000000000000000000}}, []]}
62
- def encode_call(call, metadata)
63
- calls_type_id = get_calls_type_id(call[:pallet_name], metadata)
64
- pallet_index = get_module(call[:pallet_name], metadata)._get(:index)
65
- [pallet_index] + PortableCodec.encode(calls_type_id, call[:call].first, build_registry(metadata))
66
- end
67
-
68
- # callbytes's structure is: pallet_index + call_index + argsbytes
69
- #
70
- # callbytes examples:
71
- # "0x0901".to_bytes
72
- # "0x05000a1287977578f888bdc1c7627781af1cc000e6ab1300004c31b8d9a798".to_bytes
73
- def decode_call(callbytes, metadata)
74
- pallet_index = callbytes[0]
75
- pallet = get_module_by_index(pallet_index, metadata)
76
-
77
- pallet_name = pallet._get(:name)
78
-
79
- # Remove the pallet_index
80
- # The callbytes we used below should not contain the pallet index.
81
- # This is because the pallet index is not part of the call type.
82
- # Its structure is: call_index + call_args
83
- callbytes_without_pallet_index = callbytes[1..]
84
- calls_type_id = pallet._get(:calls)._get(:type)
85
- decoded = PortableCodec.decode(
86
- calls_type_id,
87
- callbytes_without_pallet_index,
88
- build_registry(metadata)
89
- )
90
-
91
- {
92
- pallet_name: pallet_name,
93
- call_name: decoded.first.is_a?(String) ? decoded.first.to_camel : decoded.first.keys.first.to_s.to_camel,
94
- call: decoded
106
+ TYPES = {
107
+ 'MetadataTop' => {
108
+ magicNumber: 'U32',
109
+ metadata: 'Metadata'
110
+ },
111
+ 'Metadata' => {
112
+ _enum: {
113
+ v0: 'MetadataV0',
114
+ v1: 'MetadataV1',
115
+ v2: 'MetadataV2',
116
+ v3: 'MetadataV3',
117
+ v4: 'MetadataV4',
118
+ v5: 'MetadataV5',
119
+ v6: 'MetadataV6',
120
+ v7: 'MetadataV7',
121
+ v8: 'MetadataV8',
122
+ v9: 'MetadataV9',
123
+ v10: 'MetadataV10',
124
+ v11: 'MetadataV11',
125
+ v12: 'MetadataV12',
126
+ v13: 'MetadataV13',
127
+ v14: 'MetadataV14'
128
+ }
95
129
  }
96
- end
130
+ }.merge(MetadataV14::TYPES)
131
+ .merge(MetadataV13::TYPES)
132
+ .merge(MetadataV12::TYPES)
133
+ .merge(MetadataV11::TYPES)
134
+ .merge(MetadataV10::TYPES)
135
+ .merge(MetadataV9::TYPES)
97
136
  end
98
-
99
- TYPES = {
100
- 'MetadataTop' => {
101
- magicNumber: 'U32',
102
- metadata: 'Metadata'
103
- },
104
- 'Metadata' => {
105
- _enum: {
106
- v0: 'MetadataV0',
107
- v1: 'MetadataV1',
108
- v2: 'MetadataV2',
109
- v3: 'MetadataV3',
110
- v4: 'MetadataV4',
111
- v5: 'MetadataV5',
112
- v6: 'MetadataV6',
113
- v7: 'MetadataV7',
114
- v8: 'MetadataV8',
115
- v9: 'MetadataV9',
116
- v10: 'MetadataV10',
117
- v11: 'MetadataV11',
118
- v12: 'MetadataV12',
119
- v13: 'MetadataV13',
120
- v14: 'MetadataV14'
121
- }
122
- }
123
- }.merge(MetadataV14::TYPES)
124
- .merge(MetadataV13::TYPES)
125
- .merge(MetadataV12::TYPES)
126
- .merge(MetadataV11::TYPES)
127
- .merge(MetadataV10::TYPES)
128
- .merge(MetadataV9::TYPES)
129
137
  end
@@ -1,80 +1,83 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Metadata
4
- module MetadataV10
5
- class << self
6
- def get_module(module_name, metadata)
7
- metadata._get(:metadata)._get(:v10)._get(:modules).find do |m|
8
- m._get(:name) == module_name
3
+ module ScaleRb
4
+ module Metadata
5
+ module MetadataV10
6
+ class << self
7
+ def get_module(module_name, metadata)
8
+ metadata._get(:metadata)._get(:v10)._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
- ErrorMetadataV10: 'ErrorMetadataV9',
23
- EventMetadataV10: 'EventMetadataV9',
24
- FunctionArgumentMetadataV10: 'FunctionArgumentMetadataV9',
25
- FunctionMetadataV10: 'FunctionMetadataV9',
26
- MetadataV10: {
27
- modules: 'Vec<ModuleMetadataV10>'
28
- },
29
- ModuleConstantMetadataV10: 'ModuleConstantMetadataV9',
30
- ModuleMetadataV10: {
31
- name: 'Text',
32
- storage: 'Option<StorageMetadataV10>',
33
- calls: 'Option<Vec<FunctionMetadataV10>>',
34
- events: 'Option<Vec<EventMetadataV10>>',
35
- constants: 'Vec<ModuleConstantMetadataV10>',
36
- errors: 'Vec<ErrorMetadataV10>'
37
- },
38
- StorageEntryModifierV10: 'StorageEntryModifierV9',
39
- StorageEntryMetadataV10: {
40
- name: 'Text',
41
- modifier: 'StorageEntryModifierV10',
42
- type: 'StorageEntryTypeV10',
43
- fallback: 'Bytes',
44
- docs: 'Vec<Text>'
45
- },
46
- StorageEntryTypeV10: {
47
- _enum: {
48
- Plain: 'Type',
49
- Map: {
50
- hasher: 'StorageHasherV10',
51
- key: 'Type',
52
- value: 'Type',
53
- linked: 'bool'
54
- },
55
- DoubleMap: {
56
- hasher: 'StorageHasherV10',
57
- key1: 'Type',
58
- key2: 'Type',
59
- value: 'Type',
60
- key2Hasher: 'StorageHasherV10'
23
+ TYPES = {
24
+ ErrorMetadataV10: 'ErrorMetadataV9',
25
+ EventMetadataV10: 'EventMetadataV9',
26
+ FunctionArgumentMetadataV10: 'FunctionArgumentMetadataV9',
27
+ FunctionMetadataV10: 'FunctionMetadataV9',
28
+ MetadataV10: {
29
+ modules: 'Vec<ModuleMetadataV10>'
30
+ },
31
+ ModuleConstantMetadataV10: 'ModuleConstantMetadataV9',
32
+ ModuleMetadataV10: {
33
+ name: 'Text',
34
+ storage: 'Option<StorageMetadataV10>',
35
+ calls: 'Option<Vec<FunctionMetadataV10>>',
36
+ events: 'Option<Vec<EventMetadataV10>>',
37
+ constants: 'Vec<ModuleConstantMetadataV10>',
38
+ errors: 'Vec<ErrorMetadataV10>'
39
+ },
40
+ StorageEntryModifierV10: 'StorageEntryModifierV9',
41
+ StorageEntryMetadataV10: {
42
+ name: 'Text',
43
+ modifier: 'StorageEntryModifierV10',
44
+ type: 'StorageEntryTypeV10',
45
+ fallback: 'Bytes',
46
+ docs: 'Vec<Text>'
47
+ },
48
+ StorageEntryTypeV10: {
49
+ _enum: {
50
+ Plain: 'Type',
51
+ Map: {
52
+ hasher: 'StorageHasherV10',
53
+ key: 'Type',
54
+ value: 'Type',
55
+ linked: 'bool'
56
+ },
57
+ DoubleMap: {
58
+ hasher: 'StorageHasherV10',
59
+ key1: 'Type',
60
+ key2: 'Type',
61
+ value: 'Type',
62
+ key2Hasher: 'StorageHasherV10'
63
+ }
61
64
  }
65
+ },
66
+ StorageMetadataV10: {
67
+ prefix: 'Text',
68
+ items: 'Vec<StorageEntryMetadataV10>'
69
+ },
70
+ StorageHasherV10: {
71
+ _enum: %w[
72
+ Blake2_128
73
+ Blake2_256
74
+ Blake2_128Concat
75
+ Twox128
76
+ Twox256
77
+ Twox64Concat
78
+ ]
62
79
  }
63
- },
64
- StorageMetadataV10: {
65
- prefix: 'Text',
66
- items: 'Vec<StorageEntryMetadataV10>'
67
- },
68
- StorageHasherV10: {
69
- _enum: %w[
70
- Blake2_128
71
- Blake2_256
72
- Blake2_128Concat
73
- Twox128
74
- Twox256
75
- Twox64Concat
76
- ]
77
- }
78
- }.freeze
80
+ }.freeze
81
+ end
79
82
  end
80
83
  end
@@ -1,86 +1,89 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Metadata
4
- module MetadataV11
5
- class << self
6
- def get_module(module_name, metadata)
7
- metadata._get(:metadata)._get(:v11)._get(:modules).find do |m|
8
- m._get(:name) == module_name
3
+ module ScaleRb
4
+ module Metadata
5
+ module MetadataV11
6
+ class << self
7
+ def get_module(module_name, metadata)
8
+ metadata._get(:metadata)._get(:v11)._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
- ErrorMetadataV11: 'ErrorMetadataV10',
23
- EventMetadataV11: 'EventMetadataV10',
24
- ExtrinsicMetadataV11: {
25
- version: 'u8',
26
- signedExtensions: 'Vec<Text>'
27
- },
28
- FunctionArgumentMetadataV11: 'FunctionArgumentMetadataV10',
29
- FunctionMetadataV11: 'FunctionMetadataV10',
30
- MetadataV11: {
31
- modules: 'Vec<ModuleMetadataV11>',
32
- extrinsic: 'ExtrinsicMetadataV11'
33
- },
34
- ModuleConstantMetadataV11: 'ModuleConstantMetadataV10',
35
- ModuleMetadataV11: {
36
- name: 'Text',
37
- storage: 'Option<StorageMetadataV11>',
38
- calls: 'Option<Vec<FunctionMetadataV11>>',
39
- events: 'Option<Vec<EventMetadataV11>>',
40
- constants: 'Vec<ModuleConstantMetadataV11>',
41
- errors: 'Vec<ErrorMetadataV11>'
42
- },
43
- StorageEntryModifierV11: 'StorageEntryModifierV10',
44
- StorageEntryMetadataV11: {
45
- name: 'Text',
46
- modifier: 'StorageEntryModifierV11',
47
- type: 'StorageEntryTypeV11',
48
- fallback: 'Bytes',
49
- docs: 'Vec<Text>'
50
- },
51
- StorageEntryTypeV11: {
52
- _enum: {
53
- Plain: 'Type',
54
- Map: {
55
- hasher: 'StorageHasherV11',
56
- key: 'Type',
57
- value: 'Type',
58
- linked: 'bool'
59
- },
60
- DoubleMap: {
61
- hasher: 'StorageHasherV11',
62
- key1: 'Type',
63
- key2: 'Type',
64
- value: 'Type',
65
- key2Hasher: 'StorageHasherV11'
23
+ TYPES = {
24
+ ErrorMetadataV11: 'ErrorMetadataV10',
25
+ EventMetadataV11: 'EventMetadataV10',
26
+ ExtrinsicMetadataV11: {
27
+ version: 'u8',
28
+ signedExtensions: 'Vec<Text>'
29
+ },
30
+ FunctionArgumentMetadataV11: 'FunctionArgumentMetadataV10',
31
+ FunctionMetadataV11: 'FunctionMetadataV10',
32
+ MetadataV11: {
33
+ modules: 'Vec<ModuleMetadataV11>',
34
+ extrinsic: 'ExtrinsicMetadataV11'
35
+ },
36
+ ModuleConstantMetadataV11: 'ModuleConstantMetadataV10',
37
+ ModuleMetadataV11: {
38
+ name: 'Text',
39
+ storage: 'Option<StorageMetadataV11>',
40
+ calls: 'Option<Vec<FunctionMetadataV11>>',
41
+ events: 'Option<Vec<EventMetadataV11>>',
42
+ constants: 'Vec<ModuleConstantMetadataV11>',
43
+ errors: 'Vec<ErrorMetadataV11>'
44
+ },
45
+ StorageEntryModifierV11: 'StorageEntryModifierV10',
46
+ StorageEntryMetadataV11: {
47
+ name: 'Text',
48
+ modifier: 'StorageEntryModifierV11',
49
+ type: 'StorageEntryTypeV11',
50
+ fallback: 'Bytes',
51
+ docs: 'Vec<Text>'
52
+ },
53
+ StorageEntryTypeV11: {
54
+ _enum: {
55
+ Plain: 'Type',
56
+ Map: {
57
+ hasher: 'StorageHasherV11',
58
+ key: 'Type',
59
+ value: 'Type',
60
+ linked: 'bool'
61
+ },
62
+ DoubleMap: {
63
+ hasher: 'StorageHasherV11',
64
+ key1: 'Type',
65
+ key2: 'Type',
66
+ value: 'Type',
67
+ key2Hasher: 'StorageHasherV11'
68
+ }
66
69
  }
70
+ },
71
+ StorageMetadataV11: {
72
+ prefix: 'Text',
73
+ items: 'Vec<StorageEntryMetadataV11>'
74
+ },
75
+ StorageHasherV11: {
76
+ _enum: %w[
77
+ Blake2_128
78
+ Blake2_256
79
+ Blake2_128Concat
80
+ Twox128
81
+ Twox256
82
+ Twox64Concat
83
+ Identity
84
+ ]
67
85
  }
68
- },
69
- StorageMetadataV11: {
70
- prefix: 'Text',
71
- items: 'Vec<StorageEntryMetadataV11>'
72
- },
73
- StorageHasherV11: {
74
- _enum: %w[
75
- Blake2_128
76
- Blake2_256
77
- Blake2_128Concat
78
- Twox128
79
- Twox256
80
- Twox64Concat
81
- Identity
82
- ]
83
- }
84
- }.freeze
86
+ }.freeze
87
+ end
85
88
  end
86
89
  end
@@ -1,48 +1,51 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Metadata
4
- module MetadataV12
5
- class << self
6
- def get_module(module_name, metadata)
7
- metadata._get(:metadata)._get(:v12)._get(:modules).find do |m|
8
- m._get(:name) == module_name
3
+ module ScaleRb
4
+ module Metadata
5
+ module MetadataV12
6
+ class << self
7
+ def get_module(module_name, metadata)
8
+ metadata._get(:metadata)._get(:v12)._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
- ErrorMetadataV12: 'ErrorMetadataV11',
23
- EventMetadataV12: 'EventMetadataV11',
24
- ExtrinsicMetadataV12: 'ExtrinsicMetadataV11',
25
- FunctionArgumentMetadataV12: 'FunctionArgumentMetadataV11',
26
- FunctionMetadataV12: 'FunctionMetadataV11',
27
- MetadataV12: {
28
- modules: 'Vec<ModuleMetadataV12>',
29
- extrinsic: 'ExtrinsicMetadataV12'
30
- },
31
- ModuleConstantMetadataV12: 'ModuleConstantMetadataV11',
32
- ModuleMetadataV12: {
33
- name: 'Text',
34
- storage: 'Option<StorageMetadataV12>',
35
- calls: 'Option<Vec<FunctionMetadataV12>>',
36
- events: 'Option<Vec<EventMetadataV12>>',
37
- constants: 'Vec<ModuleConstantMetadataV12>',
38
- errors: 'Vec<ErrorMetadataV12>',
39
- index: 'u8'
40
- },
41
- StorageEntryModifierV12: 'StorageEntryModifierV11',
42
- StorageEntryMetadataV12: 'StorageEntryMetadataV11',
43
- StorageEntryTypeV12: 'StorageEntryTypeV11',
44
- StorageMetadataV12: 'StorageMetadataV11',
45
- StorageHasherV12: 'StorageHasherV11'
46
- }.freeze
23
+ TYPES = {
24
+ ErrorMetadataV12: 'ErrorMetadataV11',
25
+ EventMetadataV12: 'EventMetadataV11',
26
+ ExtrinsicMetadataV12: 'ExtrinsicMetadataV11',
27
+ FunctionArgumentMetadataV12: 'FunctionArgumentMetadataV11',
28
+ FunctionMetadataV12: 'FunctionMetadataV11',
29
+ MetadataV12: {
30
+ modules: 'Vec<ModuleMetadataV12>',
31
+ extrinsic: 'ExtrinsicMetadataV12'
32
+ },
33
+ ModuleConstantMetadataV12: 'ModuleConstantMetadataV11',
34
+ ModuleMetadataV12: {
35
+ name: 'Text',
36
+ storage: 'Option<StorageMetadataV12>',
37
+ calls: 'Option<Vec<FunctionMetadataV12>>',
38
+ events: 'Option<Vec<EventMetadataV12>>',
39
+ constants: 'Vec<ModuleConstantMetadataV12>',
40
+ errors: 'Vec<ErrorMetadataV12>',
41
+ index: 'u8'
42
+ },
43
+ StorageEntryModifierV12: 'StorageEntryModifierV11',
44
+ StorageEntryMetadataV12: 'StorageEntryMetadataV11',
45
+ StorageEntryTypeV12: 'StorageEntryTypeV11',
46
+ StorageMetadataV12: 'StorageMetadataV11',
47
+ StorageHasherV12: 'StorageHasherV11'
48
+ }.freeze
49
+ end
47
50
  end
48
51
  end