scale.rb 0.2.16 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Cargo.lock +8 -4
- data/Cargo.toml +2 -3
- data/Dockerfile +4 -1
- data/Gemfile.lock +43 -35
- data/README.md +44 -1
- data/Rakefile +6 -0
- data/exe/scale +39 -79
- data/lib/address.rb +3 -0
- data/lib/common.rb +163 -0
- data/lib/helper.rb +25 -8
- data/lib/metadata/metadata.rb +28 -18
- data/lib/metadata/metadata_v0.rb +24 -20
- data/lib/metadata/metadata_v1.rb +13 -9
- data/lib/metadata/metadata_v10.rb +2 -2
- data/lib/metadata/metadata_v11.rb +2 -2
- data/lib/metadata/metadata_v12.rb +9 -8
- data/lib/metadata/metadata_v13.rb +161 -0
- data/lib/metadata/metadata_v2.rb +2 -2
- data/lib/metadata/metadata_v3.rb +2 -2
- data/lib/metadata/metadata_v4.rb +21 -11
- data/lib/metadata/metadata_v5.rb +21 -11
- data/lib/metadata/metadata_v6.rb +9 -9
- data/lib/metadata/metadata_v7.rb +26 -15
- data/lib/metadata/metadata_v8.rb +9 -9
- data/lib/metadata/metadata_v9.rb +2 -2
- data/lib/scale.rb +41 -341
- data/lib/scale/base.rb +177 -95
- data/lib/scale/block.rb +17 -13
- data/lib/scale/trie.rb +1 -1
- data/lib/scale/types.rb +139 -40
- data/lib/scale/version.rb +1 -1
- data/lib/scale_bytes.rb +63 -0
- data/lib/substrate_client.rb +31 -17
- data/lib/type_builder.rb +279 -0
- data/lib/type_registry.rb +91 -0
- data/lib/type_registry/crab.json +676 -595
- data/lib/type_registry/darwinia.json +730 -554
- data/lib/type_registry/default.json +3 -2
- data/lib/type_registry/pangolin.json +771 -0
- data/scale.gemspec +7 -5
- data/scripts/mmr_root_to_sign.rb +10 -0
- data/src/lib.rs +80 -25
- metadata +59 -30
- data/lib/type_registry/edgeware.json +0 -124
- data/lib/type_registry/joystream.json +0 -49
- data/lib/type_registry/kulupu.json +0 -15
- data/lib/type_registry/plasm.json +0 -89
- data/lib/type_registry/robonomics.json +0 -39
- data/lib/type_registry/westend.json +0 -63
- data/src/storage_key.rs +0 -41
data/lib/helper.rb
CHANGED
@@ -18,16 +18,30 @@ class SubstrateClient::Helper
|
|
18
18
|
return_type = map[:value]
|
19
19
|
# TODO: decode to account id if param is address
|
20
20
|
# params[0] = decode(params[0]) if map[:key] == "AccountId"
|
21
|
+
|
21
22
|
type = Scale::Types.get(map[:key])
|
22
|
-
params[0]
|
23
|
+
if params[0].class != type
|
24
|
+
raise Scale::StorageInputTypeError.new("The type of first param is not equal to the type from metadata: #{map[:key]} => #{type}")
|
25
|
+
end
|
26
|
+
params[0] = params[0].encode
|
23
27
|
elsif map = storage_item[:type][:DoubleMap]
|
24
28
|
raise "Storage call of type \"DoubleMapType\" requires 2 parameters" if params.nil? || params.length != 2
|
25
29
|
|
26
30
|
hasher = map[:hasher]
|
27
31
|
hasher2 = map[:key2Hasher]
|
28
32
|
return_type = map[:value]
|
29
|
-
|
30
|
-
|
33
|
+
|
34
|
+
type1 = Scale::Types.get(map[:key1])
|
35
|
+
if params[0].class != type1
|
36
|
+
raise Scale::StorageInputTypeError.new("The type of 1st param is not equal to the type from metadata: #{map[:key1]} => #{type1.class.name}")
|
37
|
+
end
|
38
|
+
params[0] = params[0].encode
|
39
|
+
|
40
|
+
type2 = Scale::Types.get(map[:key2])
|
41
|
+
if params[1].class != type2
|
42
|
+
raise Scale::StorageInputTypeError.new("The type of 2nd param is not equal to the type from metadata: #{map[:key2]} => #{type2.class.name}")
|
43
|
+
end
|
44
|
+
params[1] = params[1].encode
|
31
45
|
else
|
32
46
|
raise NotImplementedError
|
33
47
|
end
|
@@ -41,7 +55,8 @@ class SubstrateClient::Helper
|
|
41
55
|
hasher2,
|
42
56
|
metadata.value.value[:metadata][:version]
|
43
57
|
)
|
44
|
-
[
|
58
|
+
storage_modifier = storage_item[:modifier]
|
59
|
+
[storage_key, return_type, storage_item]
|
45
60
|
end
|
46
61
|
|
47
62
|
def generate_storage_key(module_name, storage_name, params = nil, hasher = nil, hasher2 = nil, metadata_version = nil)
|
@@ -64,7 +79,7 @@ class SubstrateClient::Helper
|
|
64
79
|
param.encode().hex_to_bytes
|
65
80
|
end
|
66
81
|
param_hasher = "Twox128" if param_hasher.nil?
|
67
|
-
storage_key += Crypto.send(param_hasher.
|
82
|
+
storage_key += Crypto.send(param_hasher.underscore2, param_key)
|
68
83
|
end
|
69
84
|
|
70
85
|
"0x#{storage_key}"
|
@@ -79,7 +94,7 @@ class SubstrateClient::Helper
|
|
79
94
|
storage_key += params_key.hex_to_bytes.bytes_to_utf8
|
80
95
|
end
|
81
96
|
|
82
|
-
"0x#{Crypto.send( hasher.
|
97
|
+
"0x#{Crypto.send( hasher.underscore2, storage_key )}"
|
83
98
|
end
|
84
99
|
end
|
85
100
|
|
@@ -108,15 +123,17 @@ class SubstrateClient::Helper
|
|
108
123
|
def decode_block(block)
|
109
124
|
block["block"]["header"]["number"] = block["block"]["header"]["number"].to_i(16)
|
110
125
|
|
126
|
+
block["block"]["extrinsics_decoded"] = []
|
111
127
|
block["block"]["extrinsics"].each_with_index do |hex, i|
|
112
128
|
scale_bytes = Scale::Bytes.new(hex)
|
113
|
-
block["block"]["
|
129
|
+
block["block"]["extrinsics_decoded"][i] = Scale::Types::Extrinsic.decode(scale_bytes).to_human
|
114
130
|
end
|
115
131
|
|
132
|
+
block['block']['header']["digest"]["logs_decoded"] = []
|
116
133
|
block['block']['header']["digest"]["logs"].each_with_index do |hex, i|
|
117
134
|
scale_bytes = Scale::Bytes.new(hex)
|
118
135
|
log = Scale::Types::LogDigest.decode(scale_bytes).to_human
|
119
|
-
block['block']['header']["digest"]["
|
136
|
+
block['block']['header']["digest"]["logs_decoded"][i] = log
|
120
137
|
end
|
121
138
|
|
122
139
|
block
|
data/lib/metadata/metadata.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
module Scale
|
2
2
|
module Types
|
3
3
|
class Metadata
|
4
|
-
include
|
4
|
+
include Base
|
5
5
|
attr_accessor :version
|
6
6
|
def self.decode(scale_bytes)
|
7
7
|
bytes = scale_bytes.get_next_bytes(4)
|
8
8
|
if bytes.bytes_to_utf8 == "meta"
|
9
|
-
|
10
|
-
|
9
|
+
version_enum = {
|
10
|
+
"type" => "enum",
|
11
|
+
"value_list" => %w[MetadataV0 MetadataV1 MetadataV2 MetadataV3 MetadataV4 MetadataV5 MetadataV6 MetadataV7 MetadataV8 MetadataV9 MetadataV10 MetadataV11 MetadataV12 MetadataV13]
|
12
|
+
}
|
13
|
+
metadata_version = Scale::Types.get(version_enum).decode(scale_bytes).value
|
14
|
+
metadata = Metadata.new "Scale::Types::#{metadata_version}".constantize2.decode(scale_bytes)
|
11
15
|
metadata.version = metadata_version[9..].to_i
|
12
16
|
else
|
13
17
|
scale_bytes.reset_offset
|
@@ -48,7 +52,7 @@ module Scale
|
|
48
52
|
end
|
49
53
|
|
50
54
|
class MetadataModule
|
51
|
-
include
|
55
|
+
include Base
|
52
56
|
def self.decode(scale_bytes)
|
53
57
|
name = String.decode(scale_bytes).value
|
54
58
|
prefix = String.decode(scale_bytes).value
|
@@ -60,19 +64,19 @@ module Scale
|
|
60
64
|
|
61
65
|
has_storage = Bool.decode(scale_bytes).value
|
62
66
|
if has_storage
|
63
|
-
storages = Scale::Types.
|
67
|
+
storages = Scale::Types.get("Vec<MetadataModuleStorage>").decode(scale_bytes).value
|
64
68
|
result[:storage] = storages.map(&:value)
|
65
69
|
end
|
66
70
|
|
67
71
|
has_calls = Bool.decode(scale_bytes).value
|
68
72
|
if has_calls
|
69
|
-
calls = Scale::Types.
|
73
|
+
calls = Scale::Types.get("Vec<MetadataModuleCall>").decode(scale_bytes).value
|
70
74
|
result[:calls] = calls.map(&:value)
|
71
75
|
end
|
72
76
|
|
73
77
|
has_events = Bool.decode(scale_bytes).value
|
74
78
|
if has_events
|
75
|
-
events = Scale::Types.
|
79
|
+
events = Scale::Types.get("Vec<MetadataModuleEvent>").decode(scale_bytes).value
|
76
80
|
result[:events] = events.map(&:value)
|
77
81
|
end
|
78
82
|
|
@@ -85,11 +89,17 @@ module Scale
|
|
85
89
|
end
|
86
90
|
|
87
91
|
class MetadataModuleStorage
|
88
|
-
include
|
92
|
+
include Base
|
89
93
|
def self.decode(scale_bytes)
|
94
|
+
name = String.decode(scale_bytes).value
|
95
|
+
enum = {
|
96
|
+
"type" => "enum",
|
97
|
+
"value_list" => ["Optional", "Default"]
|
98
|
+
}
|
99
|
+
modifier = Scale::Types.get(enum).decode(scale_bytes).value
|
90
100
|
result = {
|
91
|
-
name:
|
92
|
-
modifier:
|
101
|
+
name: name,
|
102
|
+
modifier: modifier
|
93
103
|
}
|
94
104
|
|
95
105
|
is_key_value = Bool.decode(scale_bytes).value
|
@@ -108,25 +118,25 @@ module Scale
|
|
108
118
|
end
|
109
119
|
|
110
120
|
result[:fallback] = Hex.decode(scale_bytes).value
|
111
|
-
result[:documentation] = Scale::Types.
|
121
|
+
result[:documentation] = Scale::Types.get("Vec<String>").decode(scale_bytes).value.map(&:value)
|
112
122
|
|
113
123
|
MetadataModuleStorage.new(result)
|
114
124
|
end
|
115
125
|
end
|
116
126
|
|
117
127
|
class MetadataModuleCall
|
118
|
-
include
|
128
|
+
include Base
|
119
129
|
def self.decode(scale_bytes)
|
120
130
|
result = {}
|
121
131
|
result[:name] = String.decode(scale_bytes).value
|
122
|
-
result[:args] = Scale::Types.
|
123
|
-
result[:documentation] = Scale::Types.
|
132
|
+
result[:args] = Scale::Types.get("Vec<MetadataModuleCallArgument>").decode(scale_bytes).value.map(&:value)
|
133
|
+
result[:documentation] = Scale::Types.get("Vec<String>").decode(scale_bytes).value.map(&:value)
|
124
134
|
MetadataModuleCall.new(result)
|
125
135
|
end
|
126
136
|
end
|
127
137
|
|
128
138
|
class MetadataModuleCallArgument
|
129
|
-
include
|
139
|
+
include Base
|
130
140
|
def self.decode(scale_bytes)
|
131
141
|
result = {}
|
132
142
|
result[:name] = String.decode(scale_bytes).value
|
@@ -137,12 +147,12 @@ module Scale
|
|
137
147
|
end
|
138
148
|
|
139
149
|
class MetadataModuleEvent
|
140
|
-
include
|
150
|
+
include Base
|
141
151
|
def self.decode(scale_bytes)
|
142
152
|
result = {}
|
143
153
|
result[:name] = String.decode(scale_bytes).value
|
144
|
-
result[:args] = Scale::Types.
|
145
|
-
result[:documentation] = Scale::Types.
|
154
|
+
result[:args] = Scale::Types.get("Vec<String>").decode(scale_bytes).value.map(&:value)
|
155
|
+
result[:documentation] = Scale::Types.get("Vec<String>").decode(scale_bytes).value.map(&:value)
|
146
156
|
|
147
157
|
MetadataModuleEvent.new(result)
|
148
158
|
end
|
data/lib/metadata/metadata_v0.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Scale
|
2
2
|
module Types
|
3
3
|
class MetadataV0
|
4
|
-
include
|
4
|
+
include Base
|
5
5
|
attr_accessor :call_index, :event_index
|
6
6
|
|
7
7
|
def initialize(value)
|
@@ -26,12 +26,12 @@ module Scale
|
|
26
26
|
}
|
27
27
|
}
|
28
28
|
|
29
|
-
events_modules = Scale::Types.
|
30
|
-
modules = Scale::Types.
|
29
|
+
events_modules = Scale::Types.get("Vec<MetadataV0EventModule>").decode(scale_bytes).value.map(&:value)
|
30
|
+
modules = Scale::Types.get("Vec<MetadataV0Module>").decode(scale_bytes).value.map(&:value)
|
31
31
|
|
32
32
|
Bytes.decode(scale_bytes).value
|
33
33
|
|
34
|
-
sections = Scale::Types.
|
34
|
+
sections = Scale::Types.get("Vec<MetadataV0Section>").decode(scale_bytes).value.map(&:value)
|
35
35
|
|
36
36
|
value[:metadata][:outerEvent][:events] = events_modules
|
37
37
|
value[:metadata][:modules] = modules
|
@@ -65,11 +65,11 @@ module Scale
|
|
65
65
|
end
|
66
66
|
|
67
67
|
class MetadataV0EventModule
|
68
|
-
include
|
68
|
+
include Base
|
69
69
|
|
70
70
|
def self.decode(scale_bytes)
|
71
71
|
name = Bytes.decode(scale_bytes).value
|
72
|
-
events = Scale::Types.
|
72
|
+
events = Scale::Types.get('Vec<MetadataV0Event>').decode(scale_bytes).value.map(&:value)
|
73
73
|
MetadataV0EventModule.new([
|
74
74
|
name,
|
75
75
|
events
|
@@ -78,25 +78,25 @@ module Scale
|
|
78
78
|
end
|
79
79
|
|
80
80
|
class MetadataV0Event
|
81
|
-
include
|
81
|
+
include Base
|
82
82
|
|
83
83
|
def self.decode(scale_bytes)
|
84
84
|
name = Bytes.decode(scale_bytes).value
|
85
|
-
args = Scale::Types.
|
86
|
-
documentation = Scale::Types.
|
85
|
+
args = Scale::Types.get("Vec<Bytes>").decode(scale_bytes).value.map(&:value)
|
86
|
+
documentation = Scale::Types.get("Vec<Bytes>").decode(scale_bytes).value.map(&:value)
|
87
87
|
MetadataV0Event.new({name: name, args: args.map {|arg| arg }, documentation: documentation})
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
class MetadataV0Module
|
92
|
-
include
|
92
|
+
include Base
|
93
93
|
|
94
94
|
def self.decode(scale_bytes)
|
95
95
|
prefix = Bytes.decode(scale_bytes).value
|
96
96
|
name = Bytes.decode(scale_bytes).value
|
97
97
|
call_name = Bytes.decode(scale_bytes).value
|
98
98
|
|
99
|
-
functions = Scale::Types.
|
99
|
+
functions = Scale::Types.get("Vec<MetadataV0ModuleFunction>").decode(scale_bytes).value.map(&:value)
|
100
100
|
|
101
101
|
result = {
|
102
102
|
prefix: prefix,
|
@@ -112,7 +112,7 @@ module Scale
|
|
112
112
|
has_storage = Bool.decode(scale_bytes).value
|
113
113
|
if has_storage
|
114
114
|
storage_prefix = Bytes.decode(scale_bytes).value
|
115
|
-
storage = Scale::Types.
|
115
|
+
storage = Scale::Types.get("Vec<MetadataV0ModuleStorage>").decode(scale_bytes).value.map(&:value)
|
116
116
|
result[:storage] = {
|
117
117
|
prefix: storage_prefix,
|
118
118
|
functions: storage
|
@@ -124,13 +124,13 @@ module Scale
|
|
124
124
|
end
|
125
125
|
|
126
126
|
class MetadataV0ModuleFunction
|
127
|
-
include
|
127
|
+
include Base
|
128
128
|
|
129
129
|
def self.decode(scale_bytes)
|
130
130
|
id = U16.decode(scale_bytes).value
|
131
131
|
name = Bytes.decode(scale_bytes).value
|
132
|
-
args = Scale::Types.
|
133
|
-
documentation = Scale::Types.
|
132
|
+
args = Scale::Types.get("Vec<MetadataV0ModuleCallArgument>").decode(scale_bytes).value.map(&:value)
|
133
|
+
documentation = Scale::Types.get("Vec<Bytes>").decode(scale_bytes).value.map(&:value)
|
134
134
|
MetadataV0ModuleFunction.new({
|
135
135
|
id: id,
|
136
136
|
name: name,
|
@@ -141,7 +141,7 @@ module Scale
|
|
141
141
|
end
|
142
142
|
|
143
143
|
class MetadataV0ModuleCallArgument
|
144
|
-
include
|
144
|
+
include Base
|
145
145
|
|
146
146
|
def self.decode(scale_bytes)
|
147
147
|
name = Bytes.decode(scale_bytes).value
|
@@ -152,11 +152,15 @@ module Scale
|
|
152
152
|
end
|
153
153
|
|
154
154
|
class MetadataV0ModuleStorage
|
155
|
-
include
|
155
|
+
include Base
|
156
156
|
|
157
157
|
def self.decode(scale_bytes)
|
158
158
|
name = Bytes.decode(scale_bytes).value
|
159
|
-
|
159
|
+
enum = {
|
160
|
+
"type" => "enum",
|
161
|
+
"value_list" => ["Optional", "Default"]
|
162
|
+
}
|
163
|
+
modifier = Scale::Types.get(enum).decode(scale_bytes).value
|
160
164
|
|
161
165
|
is_key_value = Bool.decode(scale_bytes).value
|
162
166
|
|
@@ -174,7 +178,7 @@ module Scale
|
|
174
178
|
end
|
175
179
|
|
176
180
|
fallback = Hex.decode(scale_bytes).value
|
177
|
-
documentation = Scale::Types.
|
181
|
+
documentation = Scale::Types.get("Vec<Bytes>").decode(scale_bytes).value.map(&:value)
|
178
182
|
|
179
183
|
MetadataV0ModuleStorage.new({
|
180
184
|
name: name,
|
@@ -187,7 +191,7 @@ module Scale
|
|
187
191
|
end
|
188
192
|
|
189
193
|
class MetadataV0Section
|
190
|
-
include
|
194
|
+
include Base
|
191
195
|
|
192
196
|
def self.decode(scale_bytes)
|
193
197
|
name = Bytes.decode(scale_bytes).value
|
data/lib/metadata/metadata_v1.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Scale
|
2
2
|
module Types
|
3
3
|
class MetadataV1
|
4
|
-
include
|
4
|
+
include Base
|
5
5
|
attr_accessor :call_index, :event_index
|
6
6
|
|
7
7
|
def initialize(value)
|
@@ -11,7 +11,7 @@ module Scale
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.decode(scale_bytes)
|
14
|
-
modules = Scale::Types.
|
14
|
+
modules = Scale::Types.get("Vec<MetadataV1Module>").decode(scale_bytes).value
|
15
15
|
|
16
16
|
value = {
|
17
17
|
magicNumber: 1_635_018_093,
|
@@ -49,7 +49,7 @@ module Scale
|
|
49
49
|
end
|
50
50
|
|
51
51
|
class MetadataV1Module
|
52
|
-
include
|
52
|
+
include Base
|
53
53
|
def self.decode(scale_bytes)
|
54
54
|
name = String.decode(scale_bytes).value
|
55
55
|
prefix = String.decode(scale_bytes).value
|
@@ -61,19 +61,19 @@ module Scale
|
|
61
61
|
|
62
62
|
has_storage = Bool.decode(scale_bytes).value
|
63
63
|
if has_storage
|
64
|
-
storages = Scale::Types.
|
64
|
+
storages = Scale::Types.get("Vec<MetadataV1ModuleStorage>").decode(scale_bytes).value
|
65
65
|
result[:storage] = storages.map(&:value)
|
66
66
|
end
|
67
67
|
|
68
68
|
has_calls = Bool.decode(scale_bytes).value
|
69
69
|
if has_calls
|
70
|
-
calls = Scale::Types.
|
70
|
+
calls = Scale::Types.get("Vec<MetadataModuleCall>").decode(scale_bytes).value
|
71
71
|
result[:calls] = calls.map(&:value)
|
72
72
|
end
|
73
73
|
|
74
74
|
has_events = Bool.decode(scale_bytes).value
|
75
75
|
if has_events
|
76
|
-
events = Scale::Types.
|
76
|
+
events = Scale::Types.get("Vec<MetadataModuleEvent>").decode(scale_bytes).value
|
77
77
|
result[:events] = events.map(&:value)
|
78
78
|
end
|
79
79
|
|
@@ -82,11 +82,15 @@ module Scale
|
|
82
82
|
end
|
83
83
|
|
84
84
|
class MetadataV1ModuleStorage
|
85
|
-
include
|
85
|
+
include Base
|
86
86
|
|
87
87
|
def self.decode(scale_bytes)
|
88
88
|
name = Bytes.decode(scale_bytes).value
|
89
|
-
|
89
|
+
enum = {
|
90
|
+
"type" => "enum",
|
91
|
+
"value_list" => ["Optional", "Default"]
|
92
|
+
}
|
93
|
+
modifier = Scale::Types.get(enum).decode(scale_bytes).value
|
90
94
|
|
91
95
|
is_key_value = Bool.decode(scale_bytes).value
|
92
96
|
|
@@ -104,7 +108,7 @@ module Scale
|
|
104
108
|
end
|
105
109
|
|
106
110
|
fallback = Hex.decode(scale_bytes).value
|
107
|
-
docs = Scale::Types.
|
111
|
+
docs = Scale::Types.get("Vec<Bytes>").decode(scale_bytes).value.map(&:value)
|
108
112
|
|
109
113
|
MetadataV1ModuleStorage.new({
|
110
114
|
name: name,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Scale
|
2
2
|
module Types
|
3
3
|
class MetadataV10
|
4
|
-
include
|
4
|
+
include Base
|
5
5
|
attr_accessor :call_index, :event_index
|
6
6
|
|
7
7
|
def initialize(value)
|
@@ -11,7 +11,7 @@ module Scale
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.decode(scale_bytes)
|
14
|
-
modules = Scale::Types.
|
14
|
+
modules = Scale::Types.get("Vec<MetadataV8Module>").decode(scale_bytes).value
|
15
15
|
|
16
16
|
value = {
|
17
17
|
magicNumber: 1_635_018_093,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Scale
|
2
2
|
module Types
|
3
3
|
class MetadataV11
|
4
|
-
include
|
4
|
+
include Base
|
5
5
|
attr_accessor :call_index, :event_index
|
6
6
|
|
7
7
|
def initialize(value)
|
@@ -11,7 +11,7 @@ module Scale
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.decode(scale_bytes)
|
14
|
-
modules = Scale::Types.
|
14
|
+
modules = Scale::Types.get("Vec<MetadataV8Module>").decode(scale_bytes).value
|
15
15
|
|
16
16
|
value = {
|
17
17
|
magicNumber: 1_635_018_093,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Scale
|
2
2
|
module Types
|
3
3
|
class MetadataV12
|
4
|
-
include
|
4
|
+
include Base
|
5
5
|
attr_accessor :call_index, :event_index
|
6
6
|
|
7
7
|
def initialize(value)
|
@@ -11,7 +11,7 @@ module Scale
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.decode(scale_bytes)
|
14
|
-
modules = Scale::Types.
|
14
|
+
modules = Scale::Types.get("Vec<MetadataV12Module>").decode(scale_bytes).value
|
15
15
|
|
16
16
|
value = {
|
17
17
|
magicNumber: 1_635_018_093,
|
@@ -26,7 +26,8 @@ module Scale
|
|
26
26
|
call_module_index = 0
|
27
27
|
event_module_index = 0
|
28
28
|
|
29
|
-
modules.map(&:value).
|
29
|
+
modules.map(&:value).each do |m|
|
30
|
+
module_index = m[:index]
|
30
31
|
if m[:calls]
|
31
32
|
m[:calls].each_with_index do |call, index|
|
32
33
|
call[:lookup] = "%02x%02x" % [module_index, index]
|
@@ -47,7 +48,7 @@ module Scale
|
|
47
48
|
end
|
48
49
|
|
49
50
|
class MetadataV12Module
|
50
|
-
include
|
51
|
+
include Base
|
51
52
|
def self.decode(scale_bytes)
|
52
53
|
name = String.decode(scale_bytes).value
|
53
54
|
|
@@ -64,18 +65,18 @@ module Scale
|
|
64
65
|
|
65
66
|
has_calls = Bool.decode(scale_bytes).value
|
66
67
|
if has_calls
|
67
|
-
calls = Scale::Types.
|
68
|
+
calls = Scale::Types.get("Vec<MetadataModuleCall>").decode(scale_bytes).value
|
68
69
|
result[:calls] = calls.map(&:value)
|
69
70
|
end
|
70
71
|
|
71
72
|
has_events = Bool.decode(scale_bytes).value
|
72
73
|
if has_events
|
73
|
-
events = Scale::Types.
|
74
|
+
events = Scale::Types.get("Vec<MetadataModuleEvent>").decode(scale_bytes).value
|
74
75
|
result[:events] = events.map(&:value)
|
75
76
|
end
|
76
77
|
|
77
|
-
result[:constants] = Scale::Types.
|
78
|
-
result[:errors] = Scale::Types.
|
78
|
+
result[:constants] = Scale::Types.get("Vec<MetadataV7ModuleConstants>").decode(scale_bytes).value.map(&:value)
|
79
|
+
result[:errors] = Scale::Types.get("Vec<MetadataModuleError>").decode(scale_bytes).value.map(&:value)
|
79
80
|
|
80
81
|
result[:index] = U8.decode(scale_bytes).value
|
81
82
|
MetadataV12Module.new(result)
|