scale.rb 0.2.1 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.dockerignore +11 -0
- data/Dockerfile +9 -6
- data/Gemfile.lock +7 -7
- data/README.md +8 -5
- data/lib/metadata/metadata.rb +33 -28
- data/lib/metadata/metadata_v0.rb +3 -3
- data/lib/metadata/metadata_v1.rb +8 -8
- data/lib/metadata/metadata_v10.rb +1 -1
- data/lib/metadata/metadata_v11.rb +1 -1
- data/lib/metadata/metadata_v2.rb +1 -1
- data/lib/metadata/metadata_v3.rb +1 -1
- data/lib/metadata/metadata_v4.rb +7 -7
- data/lib/metadata/metadata_v5.rb +7 -7
- data/lib/metadata/metadata_v6.rb +2 -2
- data/lib/metadata/metadata_v7.rb +9 -9
- data/lib/metadata/metadata_v8.rb +2 -2
- data/lib/metadata/metadata_v9.rb +1 -1
- data/lib/scale.rb +77 -77
- data/lib/scale/base.rb +55 -20
- data/lib/scale/block.rb +120 -7
- data/lib/scale/types.rb +25 -1
- data/lib/scale/version.rb +1 -1
- data/lib/type_registry/certifybook-chain.json +10 -0
- data/lib/type_registry/darwinia.json +7 -0
- data/lib/type_registry/default.json +3713 -290
- data/lib/type_registry/kulupu.json +11 -2
- data/lib/type_registry/kusama.json +160 -18
- data/lib/type_registry/polkadot.json +85 -0
- data/lib/type_registry/westend.json +48 -3
- data/scripts/block_events.rb +34 -0
- data/scripts/example.rb +4 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 201e89b117a429345fb44cc4e9da4c77b99284e8cbf42622c96548f76777ebde
|
4
|
+
data.tar.gz: 5f534ca2a026903a3bc74bad4bcf58c1d683bd2e7d24988a4710709733636dba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0039c3cff40a7d34da5099e1b27fd6091d30213fdcc4578ee4a091496ab5bbb6048bab1e881ea0657fd8a9f3e1db6a8be7d986dc0998caa2772273ee52028568'
|
7
|
+
data.tar.gz: ba948fe866b16470b02c03d726a445d8fc55a19b59d15f2a6f0d9cd48822fcf17f682dc18905047f9ba83c1627dc31d1d3169f026176b61ad19aeed75c5c05e7
|
data/.DS_Store
CHANGED
Binary file
|
data/.dockerignore
ADDED
data/Dockerfile
CHANGED
@@ -2,17 +2,20 @@ FROM ruby:2.6-alpine3.11
|
|
2
2
|
|
3
3
|
ENV BUILD_PACKAGES curl-dev build-base
|
4
4
|
|
5
|
-
RUN
|
6
|
-
apk update && \
|
5
|
+
RUN apk update && \
|
7
6
|
apk upgrade && \
|
8
|
-
apk add git $BUILD_PACKAGES
|
7
|
+
apk add git curl $BUILD_PACKAGES
|
9
8
|
|
10
9
|
WORKDIR /usr/src/app
|
11
10
|
|
12
11
|
COPY . .
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
|
13
|
+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
|
14
|
+
source $HOME/.cargo/env && \
|
15
|
+
export RUSTFLAGS='-C target-feature=-crt-static' && \
|
16
|
+
make
|
17
|
+
|
18
|
+
RUN gem install bundler:1.17.3 && \
|
16
19
|
bundle install && \
|
17
20
|
rake install:local
|
18
21
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
scale.rb (0.2.
|
4
|
+
scale.rb (0.2.6)
|
5
5
|
activesupport (>= 4.0.0)
|
6
6
|
json (~> 2.3.0)
|
7
7
|
substrate_common.rb (~> 0.1.8)
|
@@ -10,23 +10,23 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activesupport (6.0.
|
13
|
+
activesupport (6.0.3.1)
|
14
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
15
|
i18n (>= 0.7, < 2)
|
16
16
|
minitest (~> 5.1)
|
17
17
|
tzinfo (~> 1.1)
|
18
|
-
zeitwerk (~> 2.2)
|
18
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
19
19
|
base58 (0.2.3)
|
20
20
|
blake2b (0.10.0)
|
21
21
|
coderay (1.1.2)
|
22
|
-
concurrent-ruby (1.1.
|
22
|
+
concurrent-ruby (1.1.7)
|
23
23
|
diff-lcs (1.3)
|
24
24
|
ffi (1.12.2)
|
25
|
-
i18n (1.8.
|
25
|
+
i18n (1.8.5)
|
26
26
|
concurrent-ruby (~> 1.0)
|
27
|
-
json (2.3.
|
27
|
+
json (2.3.1)
|
28
28
|
method_source (0.9.2)
|
29
|
-
minitest (5.14.
|
29
|
+
minitest (5.14.2)
|
30
30
|
pry (0.12.2)
|
31
31
|
coderay (~> 1.1.0)
|
32
32
|
method_source (~> 0.9.0)
|
data/README.md
CHANGED
@@ -79,10 +79,13 @@ examples in `exec/scale`
|
|
79
79
|
rspec
|
80
80
|
```
|
81
81
|
|
82
|
-
To run
|
82
|
+
To run single test file:
|
83
83
|
|
84
|
-
```
|
85
|
-
rspec spec/
|
84
|
+
```bash
|
85
|
+
rspec spec/types_spec.rb
|
86
|
+
rspec spec/extrinsic_spec.rb
|
87
|
+
rspec spec/metadata_spec.rb
|
88
|
+
rspec spec/types_ffi_spec.rb
|
86
89
|
```
|
87
90
|
|
88
91
|
|
@@ -90,11 +93,11 @@ rspec spec/low_level_spec.rb
|
|
90
93
|
|
91
94
|
1. update to latest image
|
92
95
|
|
93
|
-
`docker pull itering/scale`
|
96
|
+
`docker pull itering/scale:latest`
|
94
97
|
|
95
98
|
2. Run image:
|
96
99
|
|
97
|
-
`docker run -it itering/scale`
|
100
|
+
`docker run -it itering/scale:latest`
|
98
101
|
|
99
102
|
This will enter the container with a linux shell opened.
|
100
103
|
|
data/lib/metadata/metadata.rb
CHANGED
@@ -5,21 +5,8 @@ module Scale
|
|
5
5
|
attr_accessor :version
|
6
6
|
def self.decode(scale_bytes)
|
7
7
|
bytes = scale_bytes.get_next_bytes(4)
|
8
|
-
if bytes.bytes_to_utf8 ==
|
9
|
-
metadata_version = Scale::Types.type_of(
|
10
|
-
'MetadataV0',
|
11
|
-
'MetadataV1',
|
12
|
-
'MetadataV2',
|
13
|
-
'MetadataV3',
|
14
|
-
'MetadataV4',
|
15
|
-
'MetadataV5',
|
16
|
-
'MetadataV6',
|
17
|
-
'MetadataV7',
|
18
|
-
'MetadataV8',
|
19
|
-
'MetadataV9',
|
20
|
-
'MetadataV10',
|
21
|
-
'MetadataV11'
|
22
|
-
]).decode(scale_bytes).value
|
8
|
+
if bytes.bytes_to_utf8 == "meta"
|
9
|
+
metadata_version = Scale::Types.type_of("Enum", %w[MetadataV0 MetadataV1 MetadataV2 MetadataV3 MetadataV4 MetadataV5 MetadataV6 MetadataV7 MetadataV8 MetadataV9 MetadataV10 MetadataV11]).decode(scale_bytes).value
|
23
10
|
metadata = Metadata.new "Scale::Types::#{metadata_version}".constantize.decode(scale_bytes)
|
24
11
|
metadata.version = metadata_version[9..].to_i
|
25
12
|
else
|
@@ -30,6 +17,24 @@ module Scale
|
|
30
17
|
end
|
31
18
|
metadata
|
32
19
|
end
|
20
|
+
|
21
|
+
def get_module(module_name)
|
22
|
+
modules = self.value.value[:metadata][:modules]
|
23
|
+
modules.each do |m|
|
24
|
+
if m[:name].downcase == module_name.downcase
|
25
|
+
return m
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_module_call(module_name, call_name)
|
31
|
+
the_module = get_module(module_name)
|
32
|
+
the_module[:calls].each do |call|
|
33
|
+
if call[:name].downcase == call_name.downcase
|
34
|
+
return call
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
33
38
|
end
|
34
39
|
|
35
40
|
class MetadataModule
|
@@ -45,19 +50,19 @@ module Scale
|
|
45
50
|
|
46
51
|
has_storage = Bool.decode(scale_bytes).value
|
47
52
|
if has_storage
|
48
|
-
storages = Scale::Types.type_of(
|
53
|
+
storages = Scale::Types.type_of("Vec<MetadataModuleStorage>").decode(scale_bytes).value
|
49
54
|
result[:storage] = storages.map(&:value)
|
50
55
|
end
|
51
56
|
|
52
57
|
has_calls = Bool.decode(scale_bytes).value
|
53
58
|
if has_calls
|
54
|
-
calls = Scale::Types.type_of(
|
59
|
+
calls = Scale::Types.type_of("Vec<MetadataModuleCall>").decode(scale_bytes).value
|
55
60
|
result[:calls] = calls.map(&:value)
|
56
61
|
end
|
57
62
|
|
58
63
|
has_events = Bool.decode(scale_bytes).value
|
59
64
|
if has_events
|
60
|
-
events = Scale::Types.type_of(
|
65
|
+
events = Scale::Types.type_of("Vec<MetadataModuleEvent>").decode(scale_bytes).value
|
61
66
|
result[:events] = events.map(&:value)
|
62
67
|
end
|
63
68
|
|
@@ -70,26 +75,26 @@ module Scale
|
|
70
75
|
def self.decode(scale_bytes)
|
71
76
|
result = {
|
72
77
|
name: String.decode(scale_bytes).value,
|
73
|
-
modifier: Scale::Types.type_of(
|
78
|
+
modifier: Scale::Types.type_of("Enum", %w[Optional Default]).decode(scale_bytes).value
|
74
79
|
}
|
75
80
|
|
76
81
|
is_key_value = Bool.decode(scale_bytes).value
|
77
82
|
result[:type] = if is_key_value
|
78
83
|
{
|
79
84
|
Map: {
|
80
|
-
key:
|
81
|
-
value:
|
85
|
+
key: String.decode(scale_bytes).value,
|
86
|
+
value: String.decode(scale_bytes).value,
|
82
87
|
linked: Bool.decode(scale_bytes).value
|
83
88
|
}
|
84
89
|
}
|
85
90
|
else
|
86
91
|
{
|
87
|
-
Plain:
|
92
|
+
Plain: String.decode(scale_bytes).value
|
88
93
|
}
|
89
94
|
end
|
90
95
|
|
91
96
|
result[:fallback] = Hex.decode(scale_bytes).value
|
92
|
-
result[:documentation] = Scale::Types.type_of(
|
97
|
+
result[:documentation] = Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
|
93
98
|
|
94
99
|
MetadataModuleStorage.new(result)
|
95
100
|
end
|
@@ -100,8 +105,8 @@ module Scale
|
|
100
105
|
def self.decode(scale_bytes)
|
101
106
|
result = {}
|
102
107
|
result[:name] = String.decode(scale_bytes).value
|
103
|
-
result[:args] = Scale::Types.type_of(
|
104
|
-
result[:documentation] = Scale::Types.type_of(
|
108
|
+
result[:args] = Scale::Types.type_of("Vec<MetadataModuleCallArgument>").decode(scale_bytes).value.map(&:value)
|
109
|
+
result[:documentation] = Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
|
105
110
|
MetadataModuleCall.new(result)
|
106
111
|
end
|
107
112
|
end
|
@@ -111,7 +116,7 @@ module Scale
|
|
111
116
|
def self.decode(scale_bytes)
|
112
117
|
result = {}
|
113
118
|
result[:name] = String.decode(scale_bytes).value
|
114
|
-
result[:type] =
|
119
|
+
result[:type] = String.decode(scale_bytes).value
|
115
120
|
|
116
121
|
MetadataModuleCallArgument.new(result)
|
117
122
|
end
|
@@ -122,8 +127,8 @@ module Scale
|
|
122
127
|
def self.decode(scale_bytes)
|
123
128
|
result = {}
|
124
129
|
result[:name] = String.decode(scale_bytes).value
|
125
|
-
result[:args] = Scale::Types.type_of(
|
126
|
-
result[:documentation] = Scale::Types.type_of(
|
130
|
+
result[:args] = Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
|
131
|
+
result[:documentation] = Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
|
127
132
|
|
128
133
|
MetadataModuleEvent.new(result)
|
129
134
|
end
|
data/lib/metadata/metadata_v0.rb
CHANGED
@@ -129,7 +129,7 @@ module Scale
|
|
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.type_of("Vec<
|
132
|
+
args = Scale::Types.type_of("Vec<MetadataV0ModuleCallArgument>").decode(scale_bytes).value.map(&:value)
|
133
133
|
documentation = Scale::Types.type_of("Vec<Bytes>").decode(scale_bytes).value.map(&:value)
|
134
134
|
MetadataV0ModuleFunction.new({
|
135
135
|
id: id,
|
@@ -140,14 +140,14 @@ module Scale
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
-
class
|
143
|
+
class MetadataV0ModuleCallArgument
|
144
144
|
include SingleValue
|
145
145
|
|
146
146
|
def self.decode(scale_bytes)
|
147
147
|
name = Bytes.decode(scale_bytes).value
|
148
148
|
type = Bytes.decode(scale_bytes).value
|
149
149
|
|
150
|
-
|
150
|
+
MetadataV0ModuleCallArgument.new({name: name, type: type})
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
data/lib/metadata/metadata_v1.rb
CHANGED
@@ -37,7 +37,7 @@ module Scale
|
|
37
37
|
|
38
38
|
if m[:events]
|
39
39
|
m[:events].each_with_index do |event, index|
|
40
|
-
event[:lookup] = "%02x%02x" % [
|
40
|
+
event[:lookup] = "%02x%02x" % [event_module_index, index]
|
41
41
|
result.event_index[event[:lookup]] = [m, event]
|
42
42
|
end
|
43
43
|
event_module_index += 1
|
@@ -92,26 +92,26 @@ module Scale
|
|
92
92
|
|
93
93
|
if is_key_value
|
94
94
|
type = {
|
95
|
-
|
96
|
-
key:
|
97
|
-
value:
|
95
|
+
Map: {
|
96
|
+
key: Bytes.decode(scale_bytes).value,
|
97
|
+
value: Bytes.decode(scale_bytes).value
|
98
98
|
}
|
99
99
|
}
|
100
100
|
else
|
101
101
|
type = {
|
102
|
-
|
102
|
+
Plain: Bytes.decode(scale_bytes).value
|
103
103
|
}
|
104
104
|
end
|
105
105
|
|
106
106
|
fallback = Hex.decode(scale_bytes).value
|
107
|
-
docs = Scale::Types.type_of("Vec<Bytes>").decode(scale_bytes).value
|
107
|
+
docs = Scale::Types.type_of("Vec<Bytes>").decode(scale_bytes).value.map(&:value)
|
108
108
|
|
109
109
|
MetadataV1ModuleStorage.new({
|
110
110
|
name: name,
|
111
111
|
modifier: modifier,
|
112
112
|
type: type,
|
113
|
-
|
114
|
-
|
113
|
+
fallback: fallback,
|
114
|
+
documentation: docs
|
115
115
|
})
|
116
116
|
end
|
117
117
|
end
|
@@ -37,7 +37,7 @@ module Scale
|
|
37
37
|
|
38
38
|
if m[:events]
|
39
39
|
m[:events].each_with_index do |event, index|
|
40
|
-
event[:lookup] = "%02x%02x" % [
|
40
|
+
event[:lookup] = "%02x%02x" % [event_module_index, index]
|
41
41
|
result.event_index[event[:lookup]] = [m, event]
|
42
42
|
end
|
43
43
|
event_module_index += 1
|
@@ -37,7 +37,7 @@ module Scale
|
|
37
37
|
|
38
38
|
if m[:events]
|
39
39
|
m[:events].each_with_index do |event, index|
|
40
|
-
event[:lookup] = "%02x%02x" % [
|
40
|
+
event[:lookup] = "%02x%02x" % [event_module_index, index]
|
41
41
|
result.event_index[event[:lookup]] = [m, event]
|
42
42
|
end
|
43
43
|
event_module_index += 1
|
data/lib/metadata/metadata_v2.rb
CHANGED
@@ -37,7 +37,7 @@ module Scale
|
|
37
37
|
|
38
38
|
if m[:events]
|
39
39
|
m[:events].each_with_index do |event, index|
|
40
|
-
event[:lookup] = "%02x%02x" % [
|
40
|
+
event[:lookup] = "%02x%02x" % [event_module_index, index]
|
41
41
|
result.event_index[event[:lookup]] = [m, event]
|
42
42
|
end
|
43
43
|
event_module_index += 1
|
data/lib/metadata/metadata_v3.rb
CHANGED
@@ -37,7 +37,7 @@ module Scale
|
|
37
37
|
|
38
38
|
if m[:events]
|
39
39
|
m[:events].each_with_index do |event, index|
|
40
|
-
event[:lookup] = "%02x%02x" % [
|
40
|
+
event[:lookup] = "%02x%02x" % [event_module_index, index]
|
41
41
|
result.event_index[event[:lookup]] = [m, event]
|
42
42
|
end
|
43
43
|
event_module_index += 1
|
data/lib/metadata/metadata_v4.rb
CHANGED
@@ -37,7 +37,7 @@ module Scale
|
|
37
37
|
|
38
38
|
if m[:events]
|
39
39
|
m[:events].each_with_index do |event, index|
|
40
|
-
event[:lookup] = "%02x%02x" % [
|
40
|
+
event[:lookup] = "%02x%02x" % [event_module_index, index]
|
41
41
|
result.event_index[event[:lookup]] = [m, event]
|
42
42
|
end
|
43
43
|
event_module_index += 1
|
@@ -92,14 +92,14 @@ module Scale
|
|
92
92
|
storage_function_type = Scale::Types.type_of("Enum", %w[Plain Map DoubleMap]).decode(scale_bytes).value
|
93
93
|
if storage_function_type == "Plain"
|
94
94
|
result[:type] = {
|
95
|
-
Plain:
|
95
|
+
Plain: String.decode(scale_bytes).value
|
96
96
|
}
|
97
97
|
elsif storage_function_type == "Map"
|
98
98
|
result[:type] = {
|
99
99
|
Map: {
|
100
100
|
hasher: StorageHasher.decode(scale_bytes).value,
|
101
|
-
key:
|
102
|
-
value:
|
101
|
+
key: String.decode(scale_bytes).value,
|
102
|
+
value: String.decode(scale_bytes).value,
|
103
103
|
linked: Bool.decode(scale_bytes).value
|
104
104
|
}
|
105
105
|
}
|
@@ -107,9 +107,9 @@ module Scale
|
|
107
107
|
result[:type] = {
|
108
108
|
DoubleMap: {
|
109
109
|
hasher: StorageHasher.decode(scale_bytes).value,
|
110
|
-
key1:
|
111
|
-
key2:
|
112
|
-
value:
|
110
|
+
key1: String.decode(scale_bytes).value,
|
111
|
+
key2: String.decode(scale_bytes).value,
|
112
|
+
value: String.decode(scale_bytes).value,
|
113
113
|
key2Hasher: StorageHasher.decode(scale_bytes).value
|
114
114
|
}
|
115
115
|
}
|
data/lib/metadata/metadata_v5.rb
CHANGED
@@ -37,7 +37,7 @@ module Scale
|
|
37
37
|
|
38
38
|
if m[:events]
|
39
39
|
m[:events].each_with_index do |event, index|
|
40
|
-
event[:lookup] = "%02x%02x" % [
|
40
|
+
event[:lookup] = "%02x%02x" % [event_module_index, index]
|
41
41
|
result.event_index[event[:lookup]] = [m, event]
|
42
42
|
end
|
43
43
|
event_module_index += 1
|
@@ -92,14 +92,14 @@ module Scale
|
|
92
92
|
storage_function_type = Scale::Types.type_of("Enum", %w[Plain Map DoubleMap]).decode(scale_bytes).value
|
93
93
|
if storage_function_type == "Plain"
|
94
94
|
result[:type] = {
|
95
|
-
Plain:
|
95
|
+
Plain: String.decode(scale_bytes).value
|
96
96
|
}
|
97
97
|
elsif storage_function_type == "Map"
|
98
98
|
result[:type] = {
|
99
99
|
Map: {
|
100
100
|
hasher: StorageHasher.decode(scale_bytes).value,
|
101
|
-
key:
|
102
|
-
value:
|
101
|
+
key: String.decode(scale_bytes).value,
|
102
|
+
value: String.decode(scale_bytes).value,
|
103
103
|
linked: Bool.decode(scale_bytes).value
|
104
104
|
}
|
105
105
|
}
|
@@ -107,9 +107,9 @@ module Scale
|
|
107
107
|
result[:type] = {
|
108
108
|
DoubleMap: {
|
109
109
|
hasher: StorageHasher.decode(scale_bytes).value,
|
110
|
-
key1:
|
111
|
-
key2:
|
112
|
-
value:
|
110
|
+
key1: String.decode(scale_bytes).value,
|
111
|
+
key2: String.decode(scale_bytes).value,
|
112
|
+
value: String.decode(scale_bytes).value,
|
113
113
|
key2Hasher: StorageHasher.decode(scale_bytes).value
|
114
114
|
}
|
115
115
|
}
|
data/lib/metadata/metadata_v6.rb
CHANGED
@@ -37,7 +37,7 @@ module Scale
|
|
37
37
|
|
38
38
|
if m[:events]
|
39
39
|
m[:events].each_with_index do |event, index|
|
40
|
-
event[:lookup] = "%02x%02x" % [
|
40
|
+
event[:lookup] = "%02x%02x" % [event_module_index, index]
|
41
41
|
result.event_index[event[:lookup]] = [m, event]
|
42
42
|
end
|
43
43
|
event_module_index += 1
|
@@ -92,7 +92,7 @@ module Scale
|
|
92
92
|
name: String.decode(scale_bytes).value,
|
93
93
|
type: String.decode(scale_bytes).value, # convert
|
94
94
|
value: Hex.decode(scale_bytes).value,
|
95
|
-
|
95
|
+
documentation: Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
|
96
96
|
}
|
97
97
|
MetadataV6ModuleConstants.new result
|
98
98
|
end
|