scale.rb 0.2.5 → 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 +2 -2
- data/lib/metadata/metadata.rb +4 -4
- data/lib/metadata/metadata_v0.rb +3 -3
- data/lib/metadata/metadata_v1.rb +7 -7
- 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 +36 -22
- data/lib/scale/block.rb +22 -3
- data/lib/scale/version.rb +1 -1
- data/lib/type_registry/default.json +3615 -342
- data/lib/type_registry/kulupu.json +10 -1
- data/lib/type_registry/kusama.json +119 -18
- data/lib/type_registry/polkadot.json +85 -0
- data/lib/type_registry/westend.json +47 -3
- metadata +4 -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
@@ -93,11 +93,11 @@ rspec spec/types_ffi_spec.rb
|
|
93
93
|
|
94
94
|
1. update to latest image
|
95
95
|
|
96
|
-
`docker pull itering/scale`
|
96
|
+
`docker pull itering/scale:latest`
|
97
97
|
|
98
98
|
2. Run image:
|
99
99
|
|
100
|
-
`docker run -it itering/scale`
|
100
|
+
`docker run -it itering/scale:latest`
|
101
101
|
|
102
102
|
This will enter the container with a linux shell opened.
|
103
103
|
|
data/lib/metadata/metadata.rb
CHANGED
@@ -82,14 +82,14 @@ module Scale
|
|
82
82
|
result[:type] = if is_key_value
|
83
83
|
{
|
84
84
|
Map: {
|
85
|
-
key:
|
86
|
-
value:
|
85
|
+
key: String.decode(scale_bytes).value,
|
86
|
+
value: String.decode(scale_bytes).value,
|
87
87
|
linked: Bool.decode(scale_bytes).value
|
88
88
|
}
|
89
89
|
}
|
90
90
|
else
|
91
91
|
{
|
92
|
-
Plain:
|
92
|
+
Plain: String.decode(scale_bytes).value
|
93
93
|
}
|
94
94
|
end
|
95
95
|
|
@@ -116,7 +116,7 @@ module Scale
|
|
116
116
|
def self.decode(scale_bytes)
|
117
117
|
result = {}
|
118
118
|
result[:name] = String.decode(scale_bytes).value
|
119
|
-
result[:type] =
|
119
|
+
result[:type] = String.decode(scale_bytes).value
|
120
120
|
|
121
121
|
MetadataModuleCallArgument.new(result)
|
122
122
|
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
|
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
|
}
|
data/lib/metadata/metadata_v5.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
|
}
|
data/lib/metadata/metadata_v6.rb
CHANGED
@@ -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
|
data/lib/metadata/metadata_v7.rb
CHANGED
@@ -106,14 +106,14 @@ module Scale
|
|
106
106
|
storage_function_type = Scale::Types.type_of("Enum", %w[Plain Map DoubleMap]).decode(scale_bytes).value
|
107
107
|
if storage_function_type == "Plain"
|
108
108
|
result[:type] = {
|
109
|
-
Plain:
|
109
|
+
Plain: String.decode(scale_bytes).value
|
110
110
|
}
|
111
111
|
elsif storage_function_type == "Map"
|
112
112
|
result[:type] = {
|
113
113
|
Map: {
|
114
114
|
hasher: StorageHasher.decode(scale_bytes).value,
|
115
|
-
key:
|
116
|
-
value:
|
115
|
+
key: String.decode(scale_bytes).value,
|
116
|
+
value: String.decode(scale_bytes).value,
|
117
117
|
linked: Bool.decode(scale_bytes).value
|
118
118
|
}
|
119
119
|
}
|
@@ -121,16 +121,16 @@ module Scale
|
|
121
121
|
result[:type] = {
|
122
122
|
DoubleMap: {
|
123
123
|
hasher: StorageHasher.decode(scale_bytes).value,
|
124
|
-
key1:
|
125
|
-
key2:
|
126
|
-
value:
|
124
|
+
key1: String.decode(scale_bytes).value,
|
125
|
+
key2: String.decode(scale_bytes).value,
|
126
|
+
value: String.decode(scale_bytes).value,
|
127
127
|
key2Hasher: StorageHasher.decode(scale_bytes).value
|
128
128
|
}
|
129
129
|
}
|
130
130
|
end
|
131
131
|
|
132
132
|
result[:fallback] = Hex.decode(scale_bytes).value
|
133
|
-
result[:
|
133
|
+
result[:documentation] = Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
|
134
134
|
|
135
135
|
MetadataV7ModuleStorageEntry.new(result)
|
136
136
|
end
|
@@ -143,7 +143,7 @@ module Scale
|
|
143
143
|
name: String.decode(scale_bytes).value,
|
144
144
|
type: String.decode(scale_bytes).value, # convert
|
145
145
|
value: Hex.decode(scale_bytes).value,
|
146
|
-
|
146
|
+
documentation: Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
|
147
147
|
}
|
148
148
|
MetadataV7ModuleConstants.new result
|
149
149
|
end
|
data/lib/metadata/metadata_v8.rb
CHANGED
@@ -88,7 +88,7 @@ module Scale
|
|
88
88
|
def self.decode(scale_bytes)
|
89
89
|
result = {
|
90
90
|
name: String.decode(scale_bytes).value,
|
91
|
-
|
91
|
+
documentation: Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
|
92
92
|
}
|
93
93
|
|
94
94
|
MetadataModuleError.new(result)
|
data/lib/scale.rb
CHANGED
@@ -29,21 +29,28 @@ module Scale
|
|
29
29
|
|
30
30
|
class TypeRegistry
|
31
31
|
include Singleton
|
32
|
-
|
33
|
-
attr_accessor :spec_version
|
34
|
-
attr_accessor :
|
32
|
+
attr_reader :spec_name, :types, :versioning, :custom_types
|
33
|
+
attr_accessor :spec_version
|
34
|
+
attr_accessor :metadata
|
35
35
|
|
36
|
-
def load(spec_name
|
37
|
-
|
36
|
+
def load(spec_name: nil, custom_types: nil)
|
37
|
+
@spec_name = nil
|
38
|
+
@types = nil
|
39
|
+
@versioning = nil
|
40
|
+
@custom_types = nil
|
41
|
+
|
42
|
+
default_types, _, _ = load_chain_spec_types("default")
|
38
43
|
|
39
44
|
if spec_name.nil? || spec_name == "default"
|
45
|
+
@spec_name = "default"
|
40
46
|
@types = default_types
|
41
47
|
else
|
42
|
-
|
48
|
+
@spec_name = spec_name
|
49
|
+
spec_types, @versioning, @spec_version = load_chain_spec_types(spec_name)
|
43
50
|
@types = default_types.merge(spec_types)
|
44
51
|
end
|
45
52
|
|
46
|
-
|
53
|
+
self.custom_types = custom_types
|
47
54
|
true
|
48
55
|
end
|
49
56
|
|
@@ -67,27 +74,33 @@ module Scale
|
|
67
74
|
Scale::Types.constantize(type)
|
68
75
|
end
|
69
76
|
|
70
|
-
def
|
71
|
-
|
72
|
-
|
73
|
-
json = JSON.parse(json_string)
|
77
|
+
def custom_types=(custom_types)
|
78
|
+
@custom_types = custom_types.stringify_keys if (not custom_types.nil?) && custom_types.class.name == "Hash"
|
79
|
+
end
|
74
80
|
|
75
|
-
|
81
|
+
private
|
76
82
|
|
77
|
-
|
78
|
-
|
83
|
+
def load_chain_spec_types(spec_name)
|
84
|
+
file = File.join File.expand_path("../..", __FILE__), "lib", "type_registry", "#{spec_name}.json"
|
85
|
+
json_string = File.open(file).read
|
86
|
+
json = JSON.parse(json_string)
|
79
87
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
88
|
+
runtime_id = json["runtime_id"]
|
89
|
+
|
90
|
+
[json["types"], json["versioning"], runtime_id]
|
91
|
+
end
|
92
|
+
|
93
|
+
def type_traverse(type, types)
|
94
|
+
if types.has_key?(type)
|
95
|
+
type_traverse(types[type], types)
|
86
96
|
else
|
87
|
-
type
|
97
|
+
if type.class == ::String
|
98
|
+
rename(type)
|
99
|
+
else
|
100
|
+
type
|
101
|
+
end
|
88
102
|
end
|
89
103
|
end
|
90
|
-
end
|
91
104
|
end
|
92
105
|
|
93
106
|
# TODO: == implement
|
@@ -323,6 +336,7 @@ def rename(type)
|
|
323
336
|
return "Compact" if type == "<Balance as HasCompact>::Type"
|
324
337
|
return "Compact" if type == "<BlockNumber as HasCompact>::Type"
|
325
338
|
return "Compact" if type == "Compact<Balance>"
|
339
|
+
return "Compact" if type == "Compact<BlockNumber>"
|
326
340
|
return "CompactMoment" if type == "<Moment as HasCompact>::Type"
|
327
341
|
return "CompactMoment" if type == "Compact<Moment>"
|
328
342
|
return "InherentOfflineReport" if type == "<InherentOfflineReport as InherentOfflineReport>::Inherent"
|
data/lib/scale/block.rb
CHANGED
@@ -96,9 +96,10 @@ module Scale
|
|
96
96
|
# decode params
|
97
97
|
result[:params_raw] = scale_bytes.get_remaining_bytes.bytes_to_hex
|
98
98
|
result[:params] = call[:args].map do |arg|
|
99
|
-
type =
|
100
|
-
|
101
|
-
|
99
|
+
type = arg[:type]
|
100
|
+
scale_type = Scale::Types.get(type)
|
101
|
+
obj = scale_type.decode(scale_bytes)
|
102
|
+
{name: arg[:name], type: type, scale_type: scale_type, value: obj.value }
|
102
103
|
end
|
103
104
|
end
|
104
105
|
|
@@ -123,6 +124,24 @@ module Scale
|
|
123
124
|
end
|
124
125
|
end
|
125
126
|
|
127
|
+
class Phase
|
128
|
+
include Enum
|
129
|
+
items isApplyExtrinsic: "Bool", asApplyExtrinsic: "U32", isFinalization: "Bool", isInitialization: "Bool"
|
130
|
+
end
|
131
|
+
|
132
|
+
class EventRecords
|
133
|
+
include SingleValue
|
134
|
+
|
135
|
+
def self.decode(scale_bytes)
|
136
|
+
|
137
|
+
length = Compact.decode(scale_bytes).value
|
138
|
+
|
139
|
+
length.times do |i|
|
140
|
+
ev = EventRecord.decode(scale_bytes)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
126
145
|
class EventRecord
|
127
146
|
include SingleValue
|
128
147
|
|