scale.rb 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f61b15677d177f1c1ee76f1c77e8cc0ecabd1df98b50685eff13574bffeda29
4
- data.tar.gz: 6e4eb45f8fbc1d67330c80948c7cee056e2f62fd4281610a69d40d9406d0b26d
3
+ metadata.gz: a1efdbfb5ae89e2d4ff5abf3ca77717b3c95df5fbcd0e196066d813a03b80c7b
4
+ data.tar.gz: d8ce883df1522681efa389822fadd93da861685dbe5bc9e16206d2a97bd4a0de
5
5
  SHA512:
6
- metadata.gz: 4dca6ff3b87b3071a82453bb8e66d0cb33f00615a0844baace80d84ad02e8e4f1ce7c53f1d90ce193ab5b8957fb41d975dce3d67128813a47f01894e2daf99d5
7
- data.tar.gz: 8f783a33623ac5fb63d6384f4b58b17e97c90ee57815af8e7efd2556fc9a58bcc4955f171f9da6e1704431a3883cb4e967eadb010c4cb691806f72042e6b8004
6
+ metadata.gz: ff7098aca9829ed818bcfe59a9a9cbeed492aead969619ab9acb62c47b6f6fce85d5519dc30a2e4d4816658528d0c9c1db2f4ff1c653b15646d2c1a4929d0435
7
+ data.tar.gz: 1034c3b87ffcbf8516cc23c4bcb5f524c096f78e6343901a10864ac4c94832f569c935807a70181fcb43b2ddbabc268b41902a649b5e45868377d5fe55b695a5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scale.rb (0.2.7)
4
+ scale.rb (0.2.8)
5
5
  activesupport (>= 4.0.0)
6
6
  json (~> 2.3.0)
7
7
  substrate_common.rb (~> 0.1.9)
@@ -6,7 +6,7 @@ module Scale
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
- metadata_version = Scale::Types.type_of("Enum", %w[MetadataV0 MetadataV1 MetadataV2 MetadataV3 MetadataV4 MetadataV5 MetadataV6 MetadataV7 MetadataV8 MetadataV9 MetadataV10 MetadataV11]).decode(scale_bytes).value
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
10
10
  metadata = Metadata.new "Scale::Types::#{metadata_version}".constantize.decode(scale_bytes)
11
11
  metadata.version = metadata_version[9..].to_i
12
12
  else
@@ -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
@@ -23,6 +23,7 @@ require "metadata/metadata_v8"
23
23
  require "metadata/metadata_v9"
24
24
  require "metadata/metadata_v10"
25
25
  require "metadata/metadata_v11"
26
+ require "metadata/metadata_v12"
26
27
 
27
28
  module Scale
28
29
  class Error < StandardError; end
@@ -1,3 +1,3 @@
1
1
  module Scale
2
- VERSION = "0.2.7".freeze
2
+ VERSION = "0.2.8".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scale.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wu Minzhe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-11 00:00:00.000000000 Z
11
+ date: 2020-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: substrate_common.rb
@@ -165,6 +165,7 @@ files:
165
165
  - lib/metadata/metadata_v1.rb
166
166
  - lib/metadata/metadata_v10.rb
167
167
  - lib/metadata/metadata_v11.rb
168
+ - lib/metadata/metadata_v12.rb
168
169
  - lib/metadata/metadata_v2.rb
169
170
  - lib/metadata/metadata_v3.rb
170
171
  - lib/metadata/metadata_v4.rb