scale_rb 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +0 -0
- data/.rubocop.yml +0 -0
- data/.travis.yml +0 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +1 -0
- data/LICENSE.txt +0 -0
- data/README.md +1 -1
- data/Rakefile +0 -0
- data/examples/http_client_1.rb +0 -0
- data/examples/ws_client_3.rb +2 -2
- data/examples/ws_client_error_handling.rb +9 -0
- data/lib/address.rb +0 -0
- data/lib/client/ws_client.rb +54 -27
- data/lib/codec.rb +0 -0
- data/lib/hasher.rb +0 -0
- data/lib/metadata/metadata.rb +0 -0
- data/lib/metadata/metadata_v10.rb +0 -0
- data/lib/metadata/metadata_v11.rb +0 -0
- data/lib/metadata/metadata_v12.rb +0 -0
- data/lib/metadata/metadata_v13.rb +0 -0
- data/lib/metadata/metadata_v14.rb +0 -0
- data/lib/metadata/metadata_v9.rb +0 -0
- data/lib/monkey_patching.rb +0 -0
- data/lib/portable_codec.rb +0 -0
- data/lib/registry.rb +0 -0
- data/lib/scale_rb/version.rb +1 -1
- data/lib/scale_rb.rb +0 -0
- data/scale_rb.gemspec +0 -0
- data/tea.yaml +0 -0
- metadata +7 -7
- data/Gemfile.lock +0 -97
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 946dbb730e56172125e2524d66c41650fb08a3b799576000b5254467080ec771
|
4
|
+
data.tar.gz: cae0b7ce708380ceeefa2bdd412abc30adbc5de5153b68bec12625497cf89e03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d9b11df5acc3538b9fd7af4aabd1db74f9fb0f08ab7bc2620299d2145beee2805eeee12b1948e33a9198b0141b4b6c57187bb99f984743dbfb1c7e62e9b0ca7
|
7
|
+
data.tar.gz: df6d923402362b259384fe585a83ee490dc3e5bc5154d41b886a74ee1ab19d3e1fa0e92c0a3f8c2b5ffb976f12138418728b0c046ac23470bb1954b12a65a048
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
File without changes
|
data/.rubocop.yml
CHANGED
File without changes
|
data/.travis.yml
CHANGED
File without changes
|
data/CODE_OF_CONDUCT.md
CHANGED
File without changes
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
data/Rakefile
CHANGED
File without changes
|
data/examples/http_client_1.rb
CHANGED
File without changes
|
data/examples/ws_client_3.rb
CHANGED
@@ -2,12 +2,12 @@ require 'scale_rb'
|
|
2
2
|
|
3
3
|
# ScaleRb.logger.level = Logger::DEBUG
|
4
4
|
|
5
|
-
# Unsubscribe after receiving
|
5
|
+
# Unsubscribe after receiving 4 new heads
|
6
6
|
ScaleRb::WsClient.start('wss://polkadot-rpc.dwellir.com') do |client|
|
7
7
|
count = 0
|
8
8
|
|
9
9
|
subscription_id = client.chain_subscribeNewHead do |head|
|
10
|
-
count
|
10
|
+
count += 1
|
11
11
|
|
12
12
|
if count < 5
|
13
13
|
block_number = head[:number].to_i(16)
|
data/lib/address.rb
CHANGED
File without changes
|
data/lib/client/ws_client.rb
CHANGED
@@ -1,42 +1,55 @@
|
|
1
1
|
require 'async'
|
2
2
|
require 'async/websocket/client'
|
3
3
|
require 'async/http/endpoint'
|
4
|
-
require 'async/queue'
|
5
|
-
require 'json'
|
6
4
|
|
7
5
|
require_relative 'client_ext'
|
8
6
|
|
9
7
|
module ScaleRb
|
10
8
|
class WsClient
|
11
|
-
def self.start(url)
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
class << self
|
11
|
+
# @param [string] url
|
12
|
+
def start(url)
|
13
|
+
Sync do
|
14
|
+
endpoint = Async::HTTP::Endpoint.parse(url, alpn_protocols: Async::HTTP::Protocol::HTTP11.names)
|
15
|
+
|
16
|
+
Async::WebSocket::Client.connect(endpoint) do |connection|
|
17
|
+
client = WsClient.new(connection)
|
18
|
+
|
19
|
+
# `recv_task` does not raise errors (subclass of StandardError), so it will not be stopped by any errors.
|
20
|
+
recv_task = Async do
|
21
|
+
while (message = client.read_message)
|
22
|
+
data = parse_message(message)
|
23
|
+
next if data.nil?
|
24
|
+
|
25
|
+
ScaleRb.logger.debug "Received response: #{data}"
|
26
|
+
Async do
|
27
|
+
client.handle_response(data)
|
28
|
+
end
|
26
29
|
end
|
27
30
|
end
|
28
|
-
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
+
client.supported_methods = client.rpc_methods()[:methods]
|
33
|
+
yield client
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
recv_task.wait
|
36
|
+
ensure
|
37
|
+
recv_task&.stop
|
38
|
+
end
|
36
39
|
end
|
37
|
-
end # Sync
|
38
40
|
|
39
|
-
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def parse_message(message)
|
46
|
+
message.parse
|
47
|
+
rescue StandardError => e
|
48
|
+
ScaleRb.logger.error "Error while parsing message: #{e.inspect}, message: #{message}"
|
49
|
+
nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
40
53
|
end
|
41
54
|
end
|
42
55
|
|
@@ -68,7 +81,7 @@ module ScaleRb
|
|
68
81
|
if method.include?('unsubscribe')
|
69
82
|
unsubscribe(method, args[0])
|
70
83
|
elsif method.include?('subscribe')
|
71
|
-
raise
|
84
|
+
raise 'A subscribe method needs a block' unless block_given?
|
72
85
|
|
73
86
|
subscribe(method, args) do |notification|
|
74
87
|
yield notification[:params][:result]
|
@@ -101,7 +114,21 @@ module ScaleRb
|
|
101
114
|
elsif response.key?(:method)
|
102
115
|
@subscription_handler.handle(response)
|
103
116
|
else
|
104
|
-
|
117
|
+
ScaleRb.logger.info "Received an unknown response: #{response}"
|
118
|
+
end
|
119
|
+
rescue StandardError => e
|
120
|
+
ScaleRb.logger.error "Error while handling response: #{e.inspect}"
|
121
|
+
ScaleRb.logger.debug e.backtrace.join("\n")
|
122
|
+
end
|
123
|
+
|
124
|
+
def read_message
|
125
|
+
loop do
|
126
|
+
return @connection.read
|
127
|
+
rescue StandardError => e
|
128
|
+
ScaleRb.logger.error "Error while read message from connection: #{e.inspect}"
|
129
|
+
ScaleRb.logger.debug e.backtrace.join("\n")
|
130
|
+
sleep 1
|
131
|
+
retry
|
105
132
|
end
|
106
133
|
end
|
107
134
|
|
@@ -140,7 +167,7 @@ module ScaleRb
|
|
140
167
|
callback.call(response)
|
141
168
|
@callbacks.delete(id)
|
142
169
|
else
|
143
|
-
ScaleRb.logger.
|
170
|
+
ScaleRb.logger.info "Received a message with unknown id: #{response}"
|
144
171
|
end
|
145
172
|
end
|
146
173
|
end
|
data/lib/codec.rb
CHANGED
File without changes
|
data/lib/hasher.rb
CHANGED
File without changes
|
data/lib/metadata/metadata.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/metadata/metadata_v9.rb
CHANGED
File without changes
|
data/lib/monkey_patching.rb
CHANGED
File without changes
|
data/lib/portable_codec.rb
CHANGED
File without changes
|
data/lib/registry.rb
CHANGED
File without changes
|
data/lib/scale_rb/version.rb
CHANGED
data/lib/scale_rb.rb
CHANGED
File without changes
|
data/scale_rb.gemspec
CHANGED
File without changes
|
data/tea.yaml
CHANGED
File without changes
|
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.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aki Wu
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base58
|
@@ -109,7 +109,6 @@ files:
|
|
109
109
|
- ".travis.yml"
|
110
110
|
- CODE_OF_CONDUCT.md
|
111
111
|
- Gemfile
|
112
|
-
- Gemfile.lock
|
113
112
|
- LICENSE.txt
|
114
113
|
- README.md
|
115
114
|
- Rakefile
|
@@ -121,6 +120,7 @@ files:
|
|
121
120
|
- examples/ws_client_2.rb
|
122
121
|
- examples/ws_client_3.rb
|
123
122
|
- examples/ws_client_4.rb
|
123
|
+
- examples/ws_client_error_handling.rb
|
124
124
|
- exe/metadata
|
125
125
|
- lib/address.rb
|
126
126
|
- lib/client/client_ext.rb
|
@@ -149,7 +149,7 @@ licenses:
|
|
149
149
|
metadata:
|
150
150
|
bug_tracker_uri: https://github.com/wuminzhe/scale_rb/issues/
|
151
151
|
source_code_uri: https://github.com/wuminzhe/scale_rb.git
|
152
|
-
post_install_message:
|
152
|
+
post_install_message:
|
153
153
|
rdoc_options: []
|
154
154
|
require_paths:
|
155
155
|
- lib
|
@@ -164,8 +164,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
164
|
- !ruby/object:Gem::Version
|
165
165
|
version: '0'
|
166
166
|
requirements: []
|
167
|
-
rubygems_version: 3.
|
168
|
-
signing_key:
|
167
|
+
rubygems_version: 3.3.7
|
168
|
+
signing_key:
|
169
169
|
specification_version: 4
|
170
170
|
summary: A Ruby SCALE Codec Library, and, Substrate RPC Client
|
171
171
|
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
scale_rb (0.3.3)
|
5
|
-
async
|
6
|
-
async-http (~> 0.69.0)
|
7
|
-
async-websocket (~> 0.26.2)
|
8
|
-
base58
|
9
|
-
blake2b_rs (~> 0.1.4)
|
10
|
-
xxhash
|
11
|
-
|
12
|
-
GEM
|
13
|
-
remote: https://rubygems.org/
|
14
|
-
specs:
|
15
|
-
async (2.14.2)
|
16
|
-
console (~> 1.25, >= 1.25.2)
|
17
|
-
fiber-annotation
|
18
|
-
io-event (~> 1.6, >= 1.6.5)
|
19
|
-
async-http (0.69.0)
|
20
|
-
async (>= 2.10.2)
|
21
|
-
async-pool (~> 0.7)
|
22
|
-
io-endpoint (~> 0.11)
|
23
|
-
io-stream (~> 0.4)
|
24
|
-
protocol-http (~> 0.26)
|
25
|
-
protocol-http1 (~> 0.19)
|
26
|
-
protocol-http2 (~> 0.18)
|
27
|
-
traces (>= 0.10)
|
28
|
-
async-pool (0.7.0)
|
29
|
-
async (>= 1.25)
|
30
|
-
async-websocket (0.26.2)
|
31
|
-
async-http (~> 0.54)
|
32
|
-
protocol-rack (~> 0.5)
|
33
|
-
protocol-websocket (~> 0.14)
|
34
|
-
base58 (0.2.3)
|
35
|
-
blake2b_rs (0.1.4)
|
36
|
-
ffi (~> 1.0)
|
37
|
-
thermite (~> 0)
|
38
|
-
console (1.27.0)
|
39
|
-
fiber-annotation
|
40
|
-
fiber-local (~> 1.1)
|
41
|
-
json
|
42
|
-
diff-lcs (1.5.0)
|
43
|
-
ffi (1.17.0)
|
44
|
-
fiber-annotation (0.2.0)
|
45
|
-
fiber-local (1.1.0)
|
46
|
-
fiber-storage
|
47
|
-
fiber-storage (0.1.2)
|
48
|
-
io-endpoint (0.13.0)
|
49
|
-
io-event (1.6.5)
|
50
|
-
io-stream (0.4.0)
|
51
|
-
json (2.7.2)
|
52
|
-
minitar (0.9)
|
53
|
-
protocol-hpack (1.5.0)
|
54
|
-
protocol-http (0.28.1)
|
55
|
-
protocol-http1 (0.19.1)
|
56
|
-
protocol-http (~> 0.22)
|
57
|
-
protocol-http2 (0.18.0)
|
58
|
-
protocol-hpack (~> 1.4)
|
59
|
-
protocol-http (~> 0.18)
|
60
|
-
protocol-rack (0.6.0)
|
61
|
-
protocol-http (~> 0.23)
|
62
|
-
rack (>= 1.0)
|
63
|
-
protocol-websocket (0.15.0)
|
64
|
-
protocol-http (~> 0.2)
|
65
|
-
rack (3.1.7)
|
66
|
-
rake (12.3.3)
|
67
|
-
rspec (3.11.0)
|
68
|
-
rspec-core (~> 3.11.0)
|
69
|
-
rspec-expectations (~> 3.11.0)
|
70
|
-
rspec-mocks (~> 3.11.0)
|
71
|
-
rspec-core (3.11.0)
|
72
|
-
rspec-support (~> 3.11.0)
|
73
|
-
rspec-expectations (3.11.0)
|
74
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
75
|
-
rspec-support (~> 3.11.0)
|
76
|
-
rspec-mocks (3.11.1)
|
77
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
78
|
-
rspec-support (~> 3.11.0)
|
79
|
-
rspec-support (3.11.0)
|
80
|
-
thermite (0.13.0)
|
81
|
-
minitar (~> 0.5)
|
82
|
-
rake (>= 10)
|
83
|
-
tomlrb (~> 1.2)
|
84
|
-
tomlrb (1.3.0)
|
85
|
-
traces (0.11.1)
|
86
|
-
xxhash (0.5.0)
|
87
|
-
|
88
|
-
PLATFORMS
|
89
|
-
ruby
|
90
|
-
|
91
|
-
DEPENDENCIES
|
92
|
-
rake (~> 12.0)
|
93
|
-
rspec (~> 3.0)
|
94
|
-
scale_rb!
|
95
|
-
|
96
|
-
BUNDLED WITH
|
97
|
-
2.1.4
|