scale.rb 0.2.3 → 0.2.8
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 +10 -10
- 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 +7 -7
- data/lib/metadata/metadata_v12.rb +87 -0
- data/lib/metadata/metadata_v4.rb +6 -6
- data/lib/metadata/metadata_v5.rb +6 -6
- data/lib/metadata/metadata_v6.rb +1 -1
- data/lib/metadata/metadata_v7.rb +8 -8
- data/lib/metadata/metadata_v8.rb +1 -1
- data/lib/scale.rb +78 -77
- data/lib/scale/base.rb +55 -20
- data/lib/scale/block.rb +102 -19
- data/lib/scale/types.rb +25 -1
- data/lib/scale/version.rb +1 -1
- 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/scale.gemspec +1 -1
- data/scripts/block_events.rb +34 -0
- data/scripts/example.rb +4 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1efdbfb5ae89e2d4ff5abf3ca77717b3c95df5fbcd0e196066d813a03b80c7b
|
4
|
+
data.tar.gz: d8ce883df1522681efa389822fadd93da861685dbe5bc9e16206d2a97bd4a0de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff7098aca9829ed818bcfe59a9a9cbeed492aead969619ab9acb62c47b6f6fce85d5519dc30a2e4d4816658528d0c9c1db2f4ff1c653b15646d2c1a4929d0435
|
7
|
+
data.tar.gz: 1034c3b87ffcbf8516cc23c4bcb5f524c096f78e6343901a10864ac4c94832f569c935807a70181fcb43b2ddbabc268b41902a649b5e45868377d5fe55b695a5
|
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,32 +1,32 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
scale.rb (0.2.
|
4
|
+
scale.rb (0.2.8)
|
5
5
|
activesupport (>= 4.0.0)
|
6
6
|
json (~> 2.3.0)
|
7
|
-
substrate_common.rb (~> 0.1.
|
7
|
+
substrate_common.rb (~> 0.1.9)
|
8
8
|
thor (~> 0.19.0)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activesupport (6.0.
|
13
|
+
activesupport (6.0.3.4)
|
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)
|
@@ -44,7 +44,7 @@ GEM
|
|
44
44
|
diff-lcs (>= 1.2.0, < 2.0)
|
45
45
|
rspec-support (~> 3.9.0)
|
46
46
|
rspec-support (3.9.0)
|
47
|
-
substrate_common.rb (0.1.
|
47
|
+
substrate_common.rb (0.1.9)
|
48
48
|
base58
|
49
49
|
blake2b
|
50
50
|
xxhash
|
@@ -53,7 +53,7 @@ GEM
|
|
53
53
|
tzinfo (1.2.7)
|
54
54
|
thread_safe (~> 0.1)
|
55
55
|
xxhash (0.4.0)
|
56
|
-
zeitwerk (2.
|
56
|
+
zeitwerk (2.4.0)
|
57
57
|
|
58
58
|
PLATFORMS
|
59
59
|
ruby
|
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 MetadataV12]).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
@@ -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
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Scale
|
2
|
+
module Types
|
3
|
+
class MetadataV12
|
4
|
+
include SingleValue
|
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.type_of("Vec<MetadataV12Module>").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 = MetadataV12.new(value)
|
25
|
+
|
26
|
+
call_module_index = 0
|
27
|
+
event_module_index = 0
|
28
|
+
|
29
|
+
modules.map(&:value).each do |m|
|
30
|
+
if m[:calls]
|
31
|
+
m[:calls].each_with_index do |call, index|
|
32
|
+
call[:lookup] = "%02x%02x" % [call_module_index, index]
|
33
|
+
result.call_index[call[:lookup]] = [m, call]
|
34
|
+
end
|
35
|
+
call_module_index += 1
|
36
|
+
end
|
37
|
+
|
38
|
+
if m[:events]
|
39
|
+
m[:events].each_with_index do |event, index|
|
40
|
+
event[:lookup] = "%02x%02x" % [event_module_index, index]
|
41
|
+
result.event_index[event[:lookup]] = [m, event]
|
42
|
+
end
|
43
|
+
event_module_index += 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
result
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class MetadataV12Module
|
52
|
+
include SingleValue
|
53
|
+
def self.decode(scale_bytes)
|
54
|
+
name = String.decode(scale_bytes).value
|
55
|
+
|
56
|
+
result = {
|
57
|
+
name: name
|
58
|
+
}
|
59
|
+
|
60
|
+
has_storage = Bool.decode(scale_bytes).value
|
61
|
+
if has_storage
|
62
|
+
storage = MetadataV7ModuleStorage.decode(scale_bytes).value
|
63
|
+
result[:storage] = storage
|
64
|
+
result[:prefix] = storage[:prefix]
|
65
|
+
end
|
66
|
+
|
67
|
+
has_calls = Bool.decode(scale_bytes).value
|
68
|
+
if has_calls
|
69
|
+
calls = Scale::Types.type_of("Vec<MetadataModuleCall>").decode(scale_bytes).value
|
70
|
+
result[:calls] = calls.map(&:value)
|
71
|
+
end
|
72
|
+
|
73
|
+
has_events = Bool.decode(scale_bytes).value
|
74
|
+
if has_events
|
75
|
+
events = Scale::Types.type_of("Vec<MetadataModuleEvent>").decode(scale_bytes).value
|
76
|
+
result[:events] = events.map(&:value)
|
77
|
+
end
|
78
|
+
|
79
|
+
result[:constants] = Scale::Types.type_of("Vec<MetadataV7ModuleConstants>").decode(scale_bytes).value.map(&:value)
|
80
|
+
result[:errors] = Scale::Types.type_of("Vec<MetadataModuleError>").decode(scale_bytes).value.map(&:value)
|
81
|
+
|
82
|
+
result[:index] = U8.decode(scale_bytes).value
|
83
|
+
MetadataV12Module.new(result)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/metadata/metadata_v4.rb
CHANGED
@@ -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
|
}
|