scale.rb 0.2.17 → 0.3.1
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 +23 -21
- data/README.md +44 -1
- data/Rakefile +6 -0
- data/exe/scale +49 -0
- data/lib/helper.rb +19 -4
- data/lib/metadata/metadata.rb +27 -17
- 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 +40 -339
- data/lib/scale/base.rb +175 -93
- data/lib/scale/block.rb +10 -10
- 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 +11 -8
- data/lib/type_builder.rb +280 -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 +1 -0
- data/scripts/mmr_root_to_sign.rb +10 -0
- data/src/lib.rs +80 -25
- metadata +25 -10
- 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/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)
|
@@ -0,0 +1,161 @@
|
|
1
|
+
module Scale
|
2
|
+
module Types
|
3
|
+
class MetadataV13
|
4
|
+
include Base
|
5
|
+
attr_accessor :call_index, :event_index
|
6
|
+
|
7
|
+
def initialize(value)
|
8
|
+
@call_index = {}
|
9
|
+
@event_index = {}
|
10
|
+
super(value)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.decode(scale_bytes)
|
14
|
+
modules = Scale::Types.get("Vec<MetadataV13Module>").decode(scale_bytes).value
|
15
|
+
|
16
|
+
value = {
|
17
|
+
magicNumber: 1_635_018_093,
|
18
|
+
metadata: {
|
19
|
+
version: 12,
|
20
|
+
modules: modules.map(&:value)
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
result = MetadataV13.new(value)
|
25
|
+
|
26
|
+
call_module_index = 0
|
27
|
+
event_module_index = 0
|
28
|
+
|
29
|
+
modules.map(&:value).each do |m|
|
30
|
+
module_index = m[:index]
|
31
|
+
if m[:calls]
|
32
|
+
m[:calls].each_with_index do |call, index|
|
33
|
+
call[:lookup] = "%02x%02x" % [module_index, index]
|
34
|
+
result.call_index[call[:lookup]] = [m, call]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
if m[:events]
|
39
|
+
m[:events].each_with_index do |event, index|
|
40
|
+
event[:lookup] = "%02x%02x" % [module_index, index]
|
41
|
+
result.event_index[event[:lookup]] = [m, event]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
result
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class MetadataV13ModuleStorage
|
51
|
+
include Base
|
52
|
+
def self.decode(scale_bytes)
|
53
|
+
prefix = String.decode(scale_bytes).value
|
54
|
+
items = Scale::Types.get("Vec<MetadataV13ModuleStorageEntry>").decode(scale_bytes).value.map(&:value)
|
55
|
+
result = {
|
56
|
+
prefix: prefix,
|
57
|
+
items: items
|
58
|
+
}
|
59
|
+
|
60
|
+
MetadataV13ModuleStorage.new(result)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class MetadataV13ModuleStorageEntry
|
65
|
+
include Base
|
66
|
+
def self.decode(scale_bytes)
|
67
|
+
name = String.decode(scale_bytes).value
|
68
|
+
modifier_enum = {
|
69
|
+
"type" => "enum",
|
70
|
+
"value_list" => ["Optional", "Default"]
|
71
|
+
}
|
72
|
+
modifier = Scale::Types.get(modifier_enum).decode(scale_bytes).value
|
73
|
+
result = {
|
74
|
+
name: name,
|
75
|
+
modifier: modifier
|
76
|
+
}
|
77
|
+
|
78
|
+
storage_function_type_enum = {
|
79
|
+
"type" => "enum",
|
80
|
+
"value_list" => %w[Plain Map DoubleMap NMap]
|
81
|
+
}
|
82
|
+
storage_function_type = Scale::Types.get(storage_function_type_enum).decode(scale_bytes).value
|
83
|
+
if storage_function_type == "Plain"
|
84
|
+
result[:type] = {
|
85
|
+
Plain: String.decode(scale_bytes).value
|
86
|
+
}
|
87
|
+
elsif storage_function_type == "Map"
|
88
|
+
result[:type] = {
|
89
|
+
Map: {
|
90
|
+
hasher: StorageHasher.decode(scale_bytes).value,
|
91
|
+
key: String.decode(scale_bytes).value,
|
92
|
+
value: String.decode(scale_bytes).value,
|
93
|
+
linked: Bool.decode(scale_bytes).value
|
94
|
+
}
|
95
|
+
}
|
96
|
+
elsif storage_function_type == "DoubleMap"
|
97
|
+
result[:type] = {
|
98
|
+
DoubleMap: {
|
99
|
+
hasher: StorageHasher.decode(scale_bytes).value,
|
100
|
+
key1: String.decode(scale_bytes).value,
|
101
|
+
key2: String.decode(scale_bytes).value,
|
102
|
+
value: String.decode(scale_bytes).value,
|
103
|
+
key2Hasher: StorageHasher.decode(scale_bytes).value
|
104
|
+
}
|
105
|
+
}
|
106
|
+
elsif storage_function_type == "NMap"
|
107
|
+
keys = Scale::Types.get("Vec<String>").decode(scale_bytes).value.map(&:value)
|
108
|
+
hashers = Scale::Types.get("Vec<StorageHasher>").decode(scale_bytes).value.map(&:value)
|
109
|
+
result[:type] = {
|
110
|
+
NMap: {
|
111
|
+
hashers: hashers,
|
112
|
+
keys: keys,
|
113
|
+
value: String.decode(scale_bytes).value,
|
114
|
+
}
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
result[:fallback] = Hex.decode(scale_bytes).value
|
119
|
+
result[:documentation] = Scale::Types.get("Vec<String>").decode(scale_bytes).value.map(&:value)
|
120
|
+
|
121
|
+
MetadataV13ModuleStorageEntry.new(result)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class MetadataV13Module
|
126
|
+
include Base
|
127
|
+
def self.decode(scale_bytes)
|
128
|
+
name = String.decode(scale_bytes).value
|
129
|
+
|
130
|
+
result = {
|
131
|
+
name: name
|
132
|
+
}
|
133
|
+
|
134
|
+
has_storage = Bool.decode(scale_bytes).value
|
135
|
+
if has_storage
|
136
|
+
storage = MetadataV13ModuleStorage.decode(scale_bytes).value
|
137
|
+
result[:storage] = storage
|
138
|
+
result[:prefix] = storage[:prefix]
|
139
|
+
end
|
140
|
+
|
141
|
+
has_calls = Bool.decode(scale_bytes).value
|
142
|
+
if has_calls
|
143
|
+
calls = Scale::Types.get("Vec<MetadataModuleCall>").decode(scale_bytes).value
|
144
|
+
result[:calls] = calls.map(&:value)
|
145
|
+
end
|
146
|
+
|
147
|
+
has_events = Bool.decode(scale_bytes).value
|
148
|
+
if has_events
|
149
|
+
events = Scale::Types.get("Vec<MetadataModuleEvent>").decode(scale_bytes).value
|
150
|
+
result[:events] = events.map(&:value)
|
151
|
+
end
|
152
|
+
|
153
|
+
result[:constants] = Scale::Types.get("Vec<MetadataV7ModuleConstants>").decode(scale_bytes).value.map(&:value)
|
154
|
+
result[:errors] = Scale::Types.get("Vec<MetadataModuleError>").decode(scale_bytes).value.map(&:value)
|
155
|
+
|
156
|
+
result[:index] = U8.decode(scale_bytes).value
|
157
|
+
MetadataV13Module.new(result)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|