scale.rb 0.2.2 → 0.2.7

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: fbef01ecfbfc09507b09b752afc0793307e9f50612617f3ea980ff0d4e0b6c2c
4
- data.tar.gz: d5f7bb9770ea5aeceb06fc688ee19948a91692da4f88e5451c091d3694b509a4
3
+ metadata.gz: 0f61b15677d177f1c1ee76f1c77e8cc0ecabd1df98b50685eff13574bffeda29
4
+ data.tar.gz: 6e4eb45f8fbc1d67330c80948c7cee056e2f62fd4281610a69d40d9406d0b26d
5
5
  SHA512:
6
- metadata.gz: 04a161f198cae8f79f2233044f61f66d1346397a685b7fd8f029c22e1fba83d41b388e4bcebf292d5cb168f657a79253353d9f864e7002bcb8f4c351640b38f3
7
- data.tar.gz: 5f70fe07b0d1280ac2ffb710c71f7c16d70ae3f9a1b08562e3d34741059dc79eafe5086f5e19a542489eb0827ce28da54646cdcd6a6eb71693e27b955ce93e53
6
+ metadata.gz: 4dca6ff3b87b3071a82453bb8e66d0cb33f00615a0844baace80d84ad02e8e4f1ce7c53f1d90ce193ab5b8957fb41d975dce3d67128813a47f01894e2daf99d5
7
+ data.tar.gz: 8f783a33623ac5fb63d6384f4b58b17e97c90ee57815af8e7efd2556fc9a58bcc4955f171f9da6e1704431a3883cb4e967eadb010c4cb691806f72042e6b8004
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.2)
4
+ scale.rb (0.2.7)
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.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 only low level format tests, call
82
+ To run single test file:
83
83
 
84
- ```
85
- rspec spec/low_level_spec.rb
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
 
@@ -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 == 'meta'
9
- metadata_version = Scale::Types.type_of('Enum', [
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('Vec<MetadataModuleStorage>').decode(scale_bytes).value
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('Vec<MetadataModuleCall>').decode(scale_bytes).value
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('Vec<MetadataModuleEvent>').decode(scale_bytes).value
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('Enum', %w[Optional Default]).decode(scale_bytes).value
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: adjust(String.decode(scale_bytes).value),
81
- value: adjust(String.decode(scale_bytes).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: adjust(String.decode(scale_bytes).value)
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('Vec<String>').decode(scale_bytes).value.map(&:value)
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('Vec<MetadataModuleCallArgument>').decode(scale_bytes).value.map(&:value)
104
- result[:documentation] = Scale::Types.type_of('Vec<String>').decode(scale_bytes).value.map(&:value)
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] = adjust(String.decode(scale_bytes).value)
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('Vec<String>').decode(scale_bytes).value.map(&:value)
126
- result[:documentation] = Scale::Types.type_of('Vec<String>').decode(scale_bytes).value.map(&:value)
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
@@ -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
 
@@ -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" % [call_module_index, index]
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
- MapType: {
96
- key: adjust(Bytes.decode(scale_bytes).value),
97
- value: adjust(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: adjust(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
@@ -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" % [call_module_index, index]
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" % [call_module_index, index]
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" % [call_module_index, index]
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" % [call_module_index, index]
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" % [call_module_index, index]
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: adjust(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: adjust(String.decode(scale_bytes).value),
102
- value: adjust(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: adjust(String.decode(scale_bytes).value),
111
- key2: adjust(String.decode(scale_bytes).value),
112
- value: adjust(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
  }
@@ -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" % [call_module_index, index]
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: adjust(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: adjust(String.decode(scale_bytes).value),
102
- value: adjust(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: adjust(String.decode(scale_bytes).value),
111
- key2: adjust(String.decode(scale_bytes).value),
112
- value: adjust(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
  }