scale.rb 0.2.16 → 0.2.17

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: '06486e89da3732a84ca4f980e8b01e135521e51b4a26b0d67d5684e9abc5ad85'
4
- data.tar.gz: b23b2ba8bd7ca6b9746caa8019f73710a6c2cd4613576fb6d0ac4da433aeb0ea
3
+ metadata.gz: 2b7ae809d469d6fb67c8fdf00ad6debf41b6c5f219d7cdf021f408d3368b7367
4
+ data.tar.gz: 19c3ea53bcc3bfaeff46735b135bdf985cc9d79830e90e75e9afa279c48d1af9
5
5
  SHA512:
6
- metadata.gz: 9407464fea76e85c960219fd19eea5db480f207db7b6f24a96ddfb819c06ce822c1b3649c1a3064e2be697bb3305b0328e0dbb9d04fc8f69851673b3b6a54bbe
7
- data.tar.gz: 6c54d51a1af71fc24504eb77a1182248923386629ebc1e0a86002d8a3b299ef1deea19c388561430c4e7cb4102b3e7669726d5ec6fa9479f6a04c82feeac7863
6
+ metadata.gz: 58f4cfe9d7430aff3c263be9e420d9779166f92ed42d9dd2e926238d8e5909073ed2241800123bb084ec513bc8fe1502f235392787d84dd81877ae61d2a54509
7
+ data.tar.gz: 27421c1d163fc130194cfd44249cca443f440bf37faca104ca5fc9db7884554d8f5d14bd4378ba583ffa4555be91fe99f4fa2430953824a109ed87f5ec18863b
data/Gemfile.lock CHANGED
@@ -1,24 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scale.rb (0.2.16)
4
+ scale.rb (0.2.17)
5
+ base58
6
+ blake2b_rs (~> 0.1.2)
7
+ faye-websocket
5
8
  json (~> 2.3.0)
6
- kontena-websocket-client (~> 0.1.1)
7
- substrate_common.rb (~> 0.1.10)
8
- thor (~> 0.19.0)
9
+ xxhash
9
10
 
10
11
  GEM
11
12
  remote: https://rubygems.org/
12
13
  specs:
13
14
  base58 (0.2.3)
14
- blake2b (0.10.0)
15
+ blake2b_rs (0.1.2)
16
+ ffi (= 1.15.0)
17
+ thermite (~> 0)
15
18
  coderay (1.1.2)
16
19
  diff-lcs (1.3)
17
- ffi (1.12.2)
20
+ eventmachine (1.2.7)
21
+ faye-websocket (0.11.0)
22
+ eventmachine (>= 0.12.0)
23
+ websocket-driver (>= 0.5.1)
24
+ ffi (1.15.0)
18
25
  json (2.3.1)
19
- kontena-websocket-client (0.1.1)
20
- websocket-driver (~> 0.6.5)
21
26
  method_source (0.9.2)
27
+ minitar (0.9)
22
28
  pry (0.12.2)
23
29
  coderay (~> 1.1.0)
24
30
  method_source (~> 0.9.0)
@@ -36,12 +42,12 @@ GEM
36
42
  diff-lcs (>= 1.2.0, < 2.0)
37
43
  rspec-support (~> 3.9.0)
38
44
  rspec-support (3.9.0)
39
- substrate_common.rb (0.1.10)
40
- base58
41
- blake2b
42
- xxhash
43
- thor (0.19.4)
44
- websocket-driver (0.6.5)
45
+ thermite (0.13.0)
46
+ minitar (~> 0.5)
47
+ rake (>= 10)
48
+ tomlrb (~> 1.2)
49
+ tomlrb (1.3.0)
50
+ websocket-driver (0.7.3)
45
51
  websocket-extensions (>= 0.1.0)
46
52
  websocket-extensions (0.1.5)
47
53
  xxhash (0.4.0)
@@ -50,12 +56,12 @@ PLATFORMS
50
56
  ruby
51
57
 
52
58
  DEPENDENCIES
53
- bundler (~> 1.17)
54
- ffi (~> 1.12)
59
+ bundler
60
+ ffi (~> 1.15.0)
55
61
  pry
56
62
  rake (~> 13.0)
57
63
  rspec (~> 3.2)
58
64
  scale.rb!
59
65
 
60
66
  BUNDLED WITH
61
- 1.17.3
67
+ 2.2.13
data/README.md CHANGED
@@ -19,7 +19,7 @@ Because the feature of ruby 2.6 is used, the ruby version is required to be >= 2
19
19
  Add this line to your application's Gemfile:
20
20
 
21
21
  ```ruby
22
- gem 'scale.rb'
22
+ gem 'scale.rb', '0.2.16'
23
23
  ```
24
24
 
25
25
  And then execute:
data/lib/address.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'blake2b'
2
+ require 'base58'
3
+
data/lib/common.rb ADDED
@@ -0,0 +1,163 @@
1
+ require 'xxhash'
2
+ require 'blake2b'
3
+ require 'base58'
4
+
5
+ class Array
6
+ def bytes_to_hex
7
+ raise "Not a byte array" unless self.is_byte_array?
8
+ '0x' + self.map { |b| b.to_s(16).rjust(2, '0') }.join
9
+ end
10
+
11
+ def bytes_to_bin
12
+ raise "Not a byte array" unless self.is_byte_array?
13
+ '0b' + self.map { |b| b.to_s(2).rjust(8, '0') }.join
14
+ end
15
+
16
+ def bytes_to_bin
17
+ raise "Not a byte array" unless self.is_byte_array?
18
+ self.map { |b| b.to_s(2).rjust(8, '0') }
19
+ end
20
+
21
+ def bytes_to_utf8
22
+ raise "Not a byte array" unless self.is_byte_array?
23
+ self.pack('C*').force_encoding('utf-8')
24
+ end
25
+
26
+ def is_byte_array?
27
+ self.all? {|e| e >= 0 and e <= 255 }
28
+ end
29
+ end
30
+
31
+ class String
32
+ def constantize2
33
+ Object.const_get(self)
34
+ end
35
+
36
+ def hex_to_bytes
37
+ data = self.start_with?('0x') ? self[2..] : self
38
+ raise "Not valid hex string" if data.length % 2 != 0
39
+ data.scan(/../).map(&:hex)
40
+ end
41
+ end
42
+
43
+ module Crypto
44
+ def self.identity(bytes)
45
+ bytes.bytes_to_hex[2..]
46
+ end
47
+
48
+ def self.twox64(data)
49
+ result = XXhash.xxh64 data, 0
50
+ bytes = result.to_s(16).rjust(16, '0').hex_to_bytes.reverse
51
+ bytes.bytes_to_hex[2..]
52
+ end
53
+
54
+ def self.twox128(data)
55
+ bytes = []
56
+ 2.times do |i|
57
+ result = XXhash.xxh64 data, i
58
+ bytes = bytes + result.to_s(16).rjust(16, '0').hex_to_bytes.reverse
59
+ end
60
+ bytes.bytes_to_hex[2..]
61
+ end
62
+
63
+ def self.twox64_concat(bytes)
64
+ data = bytes.bytes_to_utf8
65
+ twox64(data) + bytes.bytes_to_hex[2..]
66
+ end
67
+
68
+ def self.blake2_128(bytes)
69
+ Blake2b.hex bytes, 16
70
+ end
71
+
72
+ def self.blake2_256(bytes)
73
+ Blake2b.hex bytes, 32
74
+ end
75
+
76
+ def self.blake2_128_concat(bytes)
77
+ blake2_128(bytes) + bytes.bytes_to_hex[2..]
78
+ end
79
+ end
80
+
81
+ class Address
82
+ SS58_PREFIX = 'SS58PRE'
83
+
84
+ TYPES = [
85
+ # Polkadot Live (SS58, AccountId)
86
+ 0, 1,
87
+ # Polkadot Canary (SS58, AccountId)
88
+ 2, 3,
89
+ # Kulupu (SS58, Reserved)
90
+ 16, 17,
91
+ # Darwinia Live
92
+ 18,
93
+ # Dothereum (SS58, AccountId)
94
+ 20, 21,
95
+ # Generic Substrate wildcard (SS58, AccountId)
96
+ 42, 43,
97
+
98
+ # Schnorr/Ristretto 25519 ("S/R 25519") key
99
+ 48,
100
+ # Edwards Ed25519 key
101
+ 49,
102
+ # ECDSA SECP256k1 key
103
+ 50,
104
+
105
+ # Reserved for future address format extensions.
106
+ *64..255
107
+ ]
108
+
109
+ class << self
110
+
111
+ def array_to_hex_string(arr)
112
+ body = arr.map { |i| i.to_s(16).rjust(2, '0') }.join
113
+ "0x#{body}"
114
+ end
115
+
116
+ def decode(address, addr_type = 42, ignore_checksum = true)
117
+ decoded = Base58.base58_to_binary(address, :bitcoin)
118
+ is_pubkey = decoded.size == 35
119
+
120
+ size = decoded.size - ( is_pubkey ? 2 : 1 )
121
+
122
+ prefix = decoded[0, 1].unpack("C*").first
123
+
124
+ raise "Invalid address type" unless TYPES.include?(addr_type)
125
+
126
+ hash_bytes = make_hash(decoded[0, size])
127
+ if is_pubkey
128
+ is_valid_checksum = decoded[-2].unpack("C*").first == hash_bytes[0] && decoded[-1].unpack("C*").first == hash_bytes[1]
129
+ else
130
+ is_valid_checksum = decoded[-1].unpack("C*").first == hash_bytes[0]
131
+ end
132
+
133
+ raise "Invalid decoded address checksum" unless is_valid_checksum && ignore_checksum
134
+
135
+ decoded[1...size].unpack("H*").first
136
+ end
137
+
138
+
139
+ def encode(pubkey, addr_type = 42)
140
+ pubkey = pubkey[2..-1] if pubkey =~ /^0x/i
141
+ key = [pubkey].pack("H*")
142
+
143
+ u8_array = key.bytes
144
+
145
+ u8_array.unshift(addr_type)
146
+
147
+ bytes = make_hash(u8_array.pack("C*"))
148
+
149
+ checksum = bytes[0, key.size == 32 ? 2 : 1]
150
+
151
+ u8_array.push(*checksum)
152
+
153
+ input = u8_array.pack("C*")
154
+
155
+ Base58.binary_to_base58(input, :bitcoin)
156
+ end
157
+
158
+ def make_hash(body)
159
+ Blake2b.bytes("#{SS58_PREFIX}#{body}", Blake2b::Key.none, 64)
160
+ end
161
+
162
+ end
163
+ end
data/lib/helper.rb CHANGED
@@ -64,7 +64,7 @@ class SubstrateClient::Helper
64
64
  param.encode().hex_to_bytes
65
65
  end
66
66
  param_hasher = "Twox128" if param_hasher.nil?
67
- storage_key += Crypto.send(param_hasher.underscore, param_key)
67
+ storage_key += Crypto.send(param_hasher.underscore2, param_key)
68
68
  end
69
69
 
70
70
  "0x#{storage_key}"
@@ -79,7 +79,7 @@ class SubstrateClient::Helper
79
79
  storage_key += params_key.hex_to_bytes.bytes_to_utf8
80
80
  end
81
81
 
82
- "0x#{Crypto.send( hasher.underscore, storage_key )}"
82
+ "0x#{Crypto.send( hasher.underscore2, storage_key )}"
83
83
  end
84
84
  end
85
85
 
@@ -108,15 +108,17 @@ class SubstrateClient::Helper
108
108
  def decode_block(block)
109
109
  block["block"]["header"]["number"] = block["block"]["header"]["number"].to_i(16)
110
110
 
111
+ block["block"]["extrinsics_decoded"] = []
111
112
  block["block"]["extrinsics"].each_with_index do |hex, i|
112
113
  scale_bytes = Scale::Bytes.new(hex)
113
- block["block"]["extrinsics"][i] = Scale::Types::Extrinsic.decode(scale_bytes).to_human
114
+ block["block"]["extrinsics_decoded"][i] = Scale::Types::Extrinsic.decode(scale_bytes).to_human
114
115
  end
115
116
 
117
+ block['block']['header']["digest"]["logs_decoded"] = []
116
118
  block['block']['header']["digest"]["logs"].each_with_index do |hex, i|
117
119
  scale_bytes = Scale::Bytes.new(hex)
118
120
  log = Scale::Types::LogDigest.decode(scale_bytes).to_human
119
- block['block']['header']["digest"]["logs"][i] = log
121
+ block['block']['header']["digest"]["logs_decoded"][i] = log
120
122
  end
121
123
 
122
124
  block
@@ -7,7 +7,7 @@ module Scale
7
7
  bytes = scale_bytes.get_next_bytes(4)
8
8
  if bytes.bytes_to_utf8 == "meta"
9
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
- metadata = Metadata.new "Scale::Types::#{metadata_version}".constantize.decode(scale_bytes)
10
+ metadata = Metadata.new "Scale::Types::#{metadata_version}".constantize2.decode(scale_bytes)
11
11
  metadata.version = metadata_version[9..].to_i
12
12
  else
13
13
  scale_bytes.reset_offset
data/lib/scale.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "scale/version"
2
2
 
3
- require "substrate_common"
3
+ require "common"
4
+
4
5
  require "json"
5
6
  require "singleton"
6
7
 
@@ -27,18 +28,17 @@ require "metadata/metadata_v12"
27
28
  require "substrate_client"
28
29
  require "logger"
29
30
  require "helper"
30
- require 'kontena-websocket-client'
31
31
 
32
32
  class String
33
33
  def upcase_first
34
34
  self.sub(/\S/, &:upcase)
35
35
  end
36
36
 
37
- def camelize
37
+ def camelize2
38
38
  self.split('_').collect(&:upcase_first).join
39
39
  end
40
40
 
41
- def underscore
41
+ def underscore2
42
42
  self.gsub(/::/, '/').
43
43
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
44
44
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
@@ -208,7 +208,7 @@ module Scale
208
208
  types.each do |name, body|
209
209
  if body.class == String
210
210
  target_type = "Scale::Types::#{body}"
211
- klass = Class.new(target_type.constantize) do
211
+ klass = Class.new(target_type.constantize2) do
212
212
  end
213
213
  elsif body.class == Hash
214
214
  if body["type"] == "struct"
@@ -277,7 +277,7 @@ module Scale
277
277
  include Scale::Types.type_of(type_str)
278
278
  inner_type inner_type_str
279
279
  end
280
- name = "#{type_str}<#{inner_type_str.camelize}>_#{klass.object_id}"
280
+ name = "#{type_str}<#{inner_type_str.camelize2}>_#{klass.object_id}"
281
281
  Scale::Types.const_set fix(name), klass
282
282
  else
283
283
  raise "#{type_str} not support inner type: #{type_string}"
@@ -299,7 +299,7 @@ module Scale
299
299
  include Scale::Types::Tuple
300
300
  inner_types *type_strs
301
301
  end
302
- name = "Tuple_Of_#{type_strs.map(&:camelize).join("_")}_#{klass.object_id}"
302
+ name = "Tuple_Of_#{type_strs.map(&:camelize2).join("_")}_#{klass.object_id}"
303
303
  Scale::Types.const_set fix(name), klass
304
304
  else
305
305
  if type_string == "Enum"
@@ -312,7 +312,7 @@ module Scale
312
312
  values(*values)
313
313
  end
314
314
  end
315
- name = values.class == ::Hash ? values.values.map(&:camelize).join("_") : values.map(&:camelize).join("_")
315
+ name = values.class == ::Hash ? values.values.map(&:camelize2).join("_") : values.map(&:camelize2).join("_")
316
316
  name = "Enum_Of_#{name}_#{klass.object_id}"
317
317
  Scale::Types.const_set fix(name), klass
318
318
  elsif type_string == "Struct"
@@ -320,19 +320,19 @@ module Scale
320
320
  include Scale::Types::Struct
321
321
  items values
322
322
  end
323
- name = "Struct_Of_#{values.values.map(&:camelize).join("_")}_#{klass.object_id}"
323
+ name = "Struct_Of_#{values.values.map(&:camelize2).join("_")}_#{klass.object_id}"
324
324
  Scale::Types.const_set fix(name), klass
325
325
  elsif type_string == "Set"
326
326
  klass = Class.new do
327
327
  include Scale::Types::Set
328
328
  items values, 1
329
329
  end
330
- name = "Set_Of_#{values.keys.map(&:camelize).join("_")}_#{klass.object_id}"
330
+ name = "Set_Of_#{values.keys.map(&:camelize2).join("_")}_#{klass.object_id}"
331
331
  Scale::Types.const_set fix(name), klass
332
332
  else
333
333
  type_name = (type_string.start_with?("Scale::Types::") ? type_string : "Scale::Types::#{type_string}")
334
334
  begin
335
- type_name.constantize
335
+ type_name.constantize2
336
336
  rescue NameError => e
337
337
  puts "#{type_string} is not defined"
338
338
  end
data/lib/scale/base.rb CHANGED
@@ -313,7 +313,7 @@ module Scale
313
313
 
314
314
  module ClassMethods
315
315
  def decode(scale_bytes)
316
- value = "Scale::Types::U#{self::BYTE_LENGTH * 8}".constantize.decode(scale_bytes).value
316
+ value = "Scale::Types::U#{self::BYTE_LENGTH * 8}".constantize2.decode(scale_bytes).value
317
317
  return new [] unless value || value <= 0
318
318
 
319
319
  result = self::ITEMS.select { |_, mask| value & mask > 0 }.keys
@@ -340,7 +340,7 @@ module Scale
340
340
 
341
341
  def encode
342
342
  value = self.class::ITEMS.select { |key, _| self.value.include?(key) }.values.sum
343
- "Scale::Types::U#{self.class::BYTE_LENGTH * 8}".constantize.new(value).encode
343
+ "Scale::Types::U#{self.class::BYTE_LENGTH * 8}".constantize2.new(value).encode
344
344
  end
345
345
  end
346
346
 
data/lib/scale/block.rb CHANGED
@@ -141,9 +141,13 @@ module Scale
141
141
  result[:extrinsic_idx] = U32.decode(scale_bytes).value
142
142
  end
143
143
 
144
- type = scale_bytes.get_next_bytes(2).bytes_to_hex[2..]
145
- event = metadata.event_index[type][1]
146
- # mod = metadata.event_index[type][0]
144
+ index = scale_bytes.get_next_bytes(2).bytes_to_hex[2..]
145
+ event = metadata.event_index[index][1]
146
+ the_module = metadata.event_index[index][0]
147
+
148
+ result[:event_index] = index
149
+ result[:event_metadata] = event
150
+ result[:module_metadata] = the_module
147
151
 
148
152
  result[:params] = []
149
153
  event[:args].each do |arg_type|
data/lib/scale/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Scale
2
- VERSION = "0.2.16".freeze
2
+ VERSION = "0.2.17".freeze
3
3
  end
@@ -1,20 +1,30 @@
1
+ require "faye/websocket"
2
+ require "eventmachine"
1
3
 
2
4
  def ws_request(url, payload)
3
5
  result = nil
4
- Kontena::Websocket::Client.connect(url, {}) do |client|
5
- client.send(payload.to_json)
6
6
 
7
- client.read do |message|
8
- result = JSON.parse message
9
- client.close(1000)
7
+ EM.run do
8
+ ws = Faye::WebSocket::Client.new(url)
9
+
10
+ ws.on :open do |event|
11
+ ws.send(payload.to_json)
12
+ end
13
+
14
+ ws.on :message do |event|
15
+ if event.data.include?("jsonrpc")
16
+ result = JSON.parse event.data
17
+ ws.close(3001, "data received")
18
+ EM.stop
19
+ end
20
+ end
21
+
22
+ ws.on :close do |event|
23
+ ws = nil
10
24
  end
11
25
  end
12
26
 
13
- return result
14
- rescue Kontena::Websocket::CloseError => e
15
- raise SubstrateClient::WebsocketError, e.reason
16
- rescue Kontena::Websocket::Error => e
17
- raise SubstrateClient::WebsocketError, e.reason
27
+ result
18
28
  end
19
29
 
20
30
  class SubstrateClient
@@ -122,7 +132,8 @@ class SubstrateClient
122
132
  events_data = state_getStorage storage_key, block_hash
123
133
 
124
134
  scale_bytes = Scale::Bytes.new(events_data)
125
- Scale::Types.get("Vec<EventRecord>").decode(scale_bytes).to_human
135
+ decoded = Scale::Types.get("Vec<EventRecord>").decode(scale_bytes).to_human
136
+ [events_data, decoded]
126
137
  end
127
138
 
128
139
  # Plain: client.get_storage("Sudo", "Key")
data/scale.gemspec CHANGED
@@ -33,14 +33,15 @@ Gem::Specification.new do |spec|
33
33
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
34
  spec.require_paths = ["lib"]
35
35
 
36
- spec.add_dependency "substrate_common.rb", "~> 0.1.10"
36
+ spec.add_dependency "blake2b_rs", "~> 0.1.2"
37
+ spec.add_dependency "xxhash"
38
+ spec.add_dependency "base58"
37
39
  spec.add_dependency "json", "~> 2.3.0"
38
- spec.add_dependency "thor", "~> 0.19.0"
39
- spec.add_dependency "kontena-websocket-client", "~> 0.1.1"
40
+ spec.add_dependency "faye-websocket"
40
41
 
41
- spec.add_development_dependency "bundler", "~> 1.17"
42
+ spec.add_development_dependency "bundler"
42
43
  spec.add_development_dependency "pry"
43
44
  spec.add_development_dependency "rake", "~> 13.0"
44
45
  spec.add_development_dependency "rspec", "~> 3.2"
45
- spec.add_development_dependency "ffi", "~> 1.12"
46
+ spec.add_development_dependency "ffi", "~> 1.15.0"
46
47
  end
metadata CHANGED
@@ -1,85 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scale.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.16
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wu Minzhe
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-23 00:00:00.000000000 Z
11
+ date: 2021-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: substrate_common.rb
14
+ name: blake2b_rs
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.10
19
+ version: 0.1.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.10
26
+ version: 0.1.2
27
27
  - !ruby/object:Gem::Dependency
28
- name: json
28
+ name: xxhash
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.3.0
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 2.3.0
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: thor
42
+ name: base58
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.19.0
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.19.0
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: kontena-websocket-client
56
+ name: json
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.1.1
61
+ version: 2.3.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.1.1
68
+ version: 2.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: faye-websocket
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: '1.17'
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: '1.17'
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: pry
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -128,19 +142,18 @@ dependencies:
128
142
  requirements:
129
143
  - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: '1.12'
145
+ version: 1.15.0
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
- version: '1.12'
152
+ version: 1.15.0
139
153
  description: Ruby implementation of the parity SCALE data format
140
154
  email:
141
155
  - wuminzhe@gmail.com
142
- executables:
143
- - scale
156
+ executables: []
144
157
  extensions: []
145
158
  extra_rdoc_files: []
146
159
  files:
@@ -157,8 +170,9 @@ files:
157
170
  - Rakefile
158
171
  - bin/console
159
172
  - bin/setup
160
- - exe/scale
161
173
  - grants_badge.png
174
+ - lib/address.rb
175
+ - lib/common.rb
162
176
  - lib/helper.rb
163
177
  - lib/metadata/metadata.rb
164
178
  - lib/metadata/metadata_v0.rb
@@ -204,7 +218,7 @@ licenses:
204
218
  metadata:
205
219
  allowed_push_host: https://rubygems.org
206
220
  homepage_uri: https://github.com/itering/scale.rb
207
- post_install_message:
221
+ post_install_message:
208
222
  rdoc_options: []
209
223
  require_paths:
210
224
  - lib
@@ -219,8 +233,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
233
  - !ruby/object:Gem::Version
220
234
  version: '0'
221
235
  requirements: []
222
- rubygems_version: 3.0.6
223
- signing_key:
236
+ rubygems_version: 3.1.4
237
+ signing_key:
224
238
  specification_version: 4
225
239
  summary: Ruby SCALE Codec Library
226
240
  test_files: []
data/exe/scale DELETED
@@ -1,89 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'scale'
4
- require 'thor'
5
-
6
- class ScaleCli < Thor
7
- desc "specs", "list all chain specs"
8
- def specs
9
- path = File.join File.expand_path('../..', __FILE__), "lib", "type_registry", "*.json"
10
- specs = Dir[path].map do |file|
11
- File.basename file, ".json"
12
- end
13
- puts specs.join(", ")
14
- end
15
-
16
- # exmaples:
17
- #
18
- # scale types darwinia
19
- # =>
20
- # ProposalCategory => Scale::Types::ProposalCategory
21
- # VoteStage => Scale::Types::VoteStage
22
- # TallyType => Scale::Types::TallyType
23
- # ...
24
- #
25
- # Count: 279
26
- desc "types SPEC_NAME SPEC_VERSION", "list all types implemented for chain"
27
- def types(spec_name = "default", spec_version = nil)
28
- Scale::TypeRegistry.instance.load(spec_name, spec_version)
29
- Scale::Types.list.each_pair do |type_name, type|
30
- puts "#{green(type_name)} => #{yellow(type.to_s)}"
31
- end
32
-
33
- puts "\nCount: #{Scale::Types.list.length}"
34
- end
35
-
36
- # exmaples:
37
- #
38
- # scale type Compact
39
- # => Scale::Types::Compact
40
- #
41
- # scale type SessionKeysPolkadot kusama
42
- # => nil
43
- #
44
- # scale type SessionKeysPolkadot kusama 1054
45
- # => Scale::Types::Struct_Of_AccountId_AccountId_AccountId_AccountId_AccountId_70247479160460
46
- #
47
- # scale type "UnappliedSlash<AccountId, BalanceOf>"
48
- # => Scale::Types::Struct_Of_AccountId_AccountId_Vec˂UnappliedSlashOther˃_Vec˂AccountId˃_Balance_70145184872260
49
- #
50
- desc "type TYPE_NAME SPEC_NAME SPEC_VERSION", "show type's ruby class"
51
- def type(type_name, spec_name = "default", spec_version = nil)
52
- Scale::TypeRegistry.instance.load(spec_name, spec_version)
53
- p Scale::Types.get(type_name)
54
- end
55
-
56
- # exmaples:
57
- #
58
- # scale decode Compact 0x0300000040
59
- # => #<Scale::Types::Compact:0x00007fc86b9d1198 @value=1073741824>
60
- desc "decode TYPE_NAME HEX SPEC_NAME SPEC_VERSION", "decode HEX string using TYPE_NAME"
61
- def decode(type_name, hex, spec_name = "default", spec_version = nil)
62
- Scale::TypeRegistry.instance.load(spec_name, spec_version)
63
- type = Scale::Types.get(type_name)
64
- scale_bytes = Scale::Bytes.new(hex)
65
- p type.decode(scale_bytes)
66
- end
67
-
68
- # exmaples:
69
- #
70
- # scale encode SessionIndex 2818
71
- # => #<Scale::Types::Compact:0x00007fc86b9d1198 @value=1073741824>
72
- desc "encode TYPE_NAME VALUE SPEC_NAME SPEC_VERSION", "encode value"
73
- def encode(type_name, value, spec_name = "default", spec_version = nil)
74
- Scale::TypeRegistry.instance.load(spec_name, spec_version)
75
- type = Scale::Types.get(type_name)
76
- p "0x" + type.new(value.to_i).encode
77
- end
78
-
79
- desc "check_read_proof ROOT PROOF STORAGE_KEY", "check read proof and output leaf's value"
80
- def check_read_proof(root, proof, storage_key)
81
- Scale::TypeRegistry.instance.load
82
- proof = proof.split(",").map(&:strip)
83
-
84
- value = Scale::Types::TrieNode::check(root, proof, storage_key)
85
- p value
86
- end
87
- end
88
-
89
- ScaleCli.start(ARGV)