scale.rb 0.2.5 → 0.2.10

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: b6c01e31f2e50407197c68df2d81da349d5471d52ddcb1b17c1a30fcd5706eae
4
- data.tar.gz: 5618f3aa22bcf94dc40a12bb15508cbe6dff74441879ffccdd8f2d6f626de992
3
+ metadata.gz: dba27c359003af9a2e6b3f23fd5baff9f971c3368909d104bbb3984cea64cea9
4
+ data.tar.gz: 60c1083aa471562ce96a309046ea8372a404ea240fae53a45f0a1776ff3901b7
5
5
  SHA512:
6
- metadata.gz: c00a8b437a13ea3a795ac1dbdc4bbeda4442400cb0a8153ab0bc07e980f5c921091b54afffe28392646aa3fede9c7b8b96d1d74d1e4fb3a9e3cf5de0419c1bca
7
- data.tar.gz: c449932d536db154cd4b6e3bbb9163bb6083494d69066e52b3e3fb856bdcc44944e9d102835f1c702c024667a32ae8c1baa0719fc1d6e0815fc90dbbbf92b956
6
+ metadata.gz: 55f235ae271e8c142b3a4e4a1e6b4dae0ee9c8cdc2a5c0774657c9d3d6ace9221de55714c5b2578eca48587e9f4da5b2e5d9ccaea6b9578c94c973659c4a8df0
7
+ data.tar.gz: 2be28d69e6524cf422c8aabf7bb89128c59551d60146407673fbef97263148292e6b447853f9c74ce459920827b1082646a36021df1492f078573fc4738b0714
data/.DS_Store CHANGED
Binary file
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.rakeTasks
10
+ /.idea
11
+ /target
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 echo "http://mirrors.ustc.edu.cn/alpine/v3.11/main/" > /etc/apk/repositories && \
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
- RUN gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/ && \
14
- gem install bundler:1.17.3 && \
15
- bundle config mirror.https://rubygems.org https://gems.ruby-china.com && \
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
 
@@ -1,32 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scale.rb (0.2.5)
4
+ scale.rb (0.2.10)
5
5
  activesupport (>= 4.0.0)
6
6
  json (~> 2.3.0)
7
- substrate_common.rb (~> 0.1.8)
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.2.2)
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.6)
22
+ concurrent-ruby (1.1.7)
23
23
  diff-lcs (1.3)
24
24
  ffi (1.12.2)
25
- i18n (1.8.2)
25
+ i18n (1.8.5)
26
26
  concurrent-ruby (~> 1.0)
27
- json (2.3.0)
27
+ json (2.3.1)
28
28
  method_source (0.9.2)
29
- minitest (5.14.0)
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.8)
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.3.0)
56
+ zeitwerk (2.4.1)
57
57
 
58
58
  PLATFORMS
59
59
  ruby
data/README.md CHANGED
@@ -10,7 +10,7 @@ This is a SCALE codec library implemented in ruby language for general use. It c
10
10
 
11
11
  This work is the prerequisite of our subsequent series of projects. We hope to familiarize and quickly access Polkadot and Substrate through ruby. We plan to develop the back end of our applications in ruby language, and then interact with nodes or synchronize data through this library.
12
12
 
13
- Please refer to the [official doc](https://substrate.dev/docs/en/overview/low-level-data-format) for more details about SCALE low-level data format.
13
+ Please refer to the [official doc](https://substrate.dev/docs/en/knowledgebase/advanced/codec) for more details about SCALE low-level data format.
14
14
 
15
15
  Because the feature of ruby 2.6 is used, the ruby version is required to be >= 2.6. it will be compatible with older ruby versions when released.
16
16
 
@@ -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
 
@@ -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
@@ -82,14 +82,14 @@ module Scale
82
82
  result[:type] = if is_key_value
83
83
  {
84
84
  Map: {
85
- key: rename(String.decode(scale_bytes).value),
86
- value: rename(String.decode(scale_bytes).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: rename(String.decode(scale_bytes).value)
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] = rename(String.decode(scale_bytes).value)
119
+ result[:type] = String.decode(scale_bytes).value
120
120
 
121
121
  MetadataModuleCallArgument.new(result)
122
122
  end
@@ -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<MetadataModuleCallArgument>").decode(scale_bytes).value.map(&:value)
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 MetadataModuleCallArgument
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
- MetadataModuleCallArgument.new({name: name, type: type})
150
+ MetadataV0ModuleCallArgument.new({name: name, type: type})
151
151
  end
152
152
  end
153
153
 
@@ -92,26 +92,26 @@ module Scale
92
92
 
93
93
  if is_key_value
94
94
  type = {
95
- MapType: {
96
- key: rename(Bytes.decode(scale_bytes).value),
97
- value: rename(Bytes.decode(scale_bytes).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
- PlainType: rename(Bytes.decode(scale_bytes).value)
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
- default: fallback,
114
- docs: docs
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
@@ -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: rename(String.decode(scale_bytes).value)
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: rename(String.decode(scale_bytes).value),
102
- value: rename(String.decode(scale_bytes).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: rename(String.decode(scale_bytes).value),
111
- key2: rename(String.decode(scale_bytes).value),
112
- value: rename(String.decode(scale_bytes).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
  }
@@ -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: rename(String.decode(scale_bytes).value)
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: rename(String.decode(scale_bytes).value),
102
- value: rename(String.decode(scale_bytes).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: rename(String.decode(scale_bytes).value),
111
- key2: rename(String.decode(scale_bytes).value),
112
- value: rename(String.decode(scale_bytes).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
  }
@@ -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
- docs: Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
95
+ documentation: Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
96
96
  }
97
97
  MetadataV6ModuleConstants.new result
98
98
  end
@@ -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: rename(String.decode(scale_bytes).value)
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: rename(String.decode(scale_bytes).value),
116
- value: rename(String.decode(scale_bytes).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: rename(String.decode(scale_bytes).value),
125
- key2: rename(String.decode(scale_bytes).value),
126
- value: rename(String.decode(scale_bytes).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[:docs] = Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
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
- docs: Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
146
+ documentation: Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
147
147
  }
148
148
  MetadataV7ModuleConstants.new result
149
149
  end
@@ -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
- docs: Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
91
+ documentation: Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
92
92
  }
93
93
 
94
94
  MetadataModuleError.new(result)