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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6c01e31f2e50407197c68df2d81da349d5471d52ddcb1b17c1a30fcd5706eae
4
- data.tar.gz: 5618f3aa22bcf94dc40a12bb15508cbe6dff74441879ffccdd8f2d6f626de992
3
+ metadata.gz: 201e89b117a429345fb44cc4e9da4c77b99284e8cbf42622c96548f76777ebde
4
+ data.tar.gz: 5f534ca2a026903a3bc74bad4bcf58c1d683bd2e7d24988a4710709733636dba
5
5
  SHA512:
6
- metadata.gz: c00a8b437a13ea3a795ac1dbdc4bbeda4442400cb0a8153ab0bc07e980f5c921091b54afffe28392646aa3fede9c7b8b96d1d74d1e4fb3a9e3cf5de0419c1bca
7
- data.tar.gz: c449932d536db154cd4b6e3bbb9163bb6083494d69066e52b3e3fb856bdcc44944e9d102835f1c702c024667a32ae8c1baa0719fc1d6e0815fc90dbbbf92b956
6
+ metadata.gz: '0039c3cff40a7d34da5099e1b27fd6091d30213fdcc4578ee4a091496ab5bbb6048bab1e881ea0657fd8a9f3e1db6a8be7d986dc0998caa2772273ee52028568'
7
+ data.tar.gz: ba948fe866b16470b02c03d726a445d8fc55a19b59d15f2a6f0d9cd48822fcf17f682dc18905047f9ba83c1627dc31d1d3169f026176b61ad19aeed75c5c05e7
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,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scale.rb (0.2.5)
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.2.2)
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.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)
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
 
@@ -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
@@ -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)
@@ -29,21 +29,28 @@ module Scale
29
29
 
30
30
  class TypeRegistry
31
31
  include Singleton
32
- attr_accessor :types, :versioning
33
- attr_accessor :spec_version, :metadata
34
- attr_accessor :custom_types
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 = nil, custom_types = nil)
37
- default_types, _ = load_chain_spec_types("default")
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
- spec_types, @versioning = load_chain_spec_types(spec_name)
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
- @custom_types = custom_types.stringify_keys if custom_types.nil? && custom_types.class.name == "Hash"
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 load_chain_spec_types(spec_name)
71
- file = File.join File.expand_path("../..", __FILE__), "lib", "type_registry", "#{spec_name}.json"
72
- json_string = File.open(file).read
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
- runtime_id = json["runtime_id"]
81
+ private
76
82
 
77
- [json["types"], json["versioning"]]
78
- end
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
- def type_traverse(type, types)
81
- if types.has_key?(type)
82
- type_traverse(types[type], types)
83
- else
84
- if type.class == ::String
85
- rename(type)
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"
@@ -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 = Scale::Types.get(arg[:type])
100
- arg_obj = type.decode(scale_bytes)
101
- {name: arg[:name], type: arg[:type], scale_type: type, value: arg_obj.value }
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