scale_rb 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/examples/http_client_1.rb +0 -2
- data/examples/ws_client_1.rb +0 -2
- data/examples/ws_client_3.rb +1 -3
- data/examples/ws_client_4.rb +0 -2
- data/lib/client/http_client.rb +2 -4
- data/lib/client/ws_client.rb +5 -8
- data/lib/scale_rb/version.rb +1 -1
- data/lib/scale_rb.rb +2 -4
- data/scale_rb.gemspec +2 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51b2e982dba83d910e71a3165d0842a84ff8cf5645c03f4fddfd5fe7c972b369
|
4
|
+
data.tar.gz: 4a4be7435a1821bf40bcdf917a8d148616dae4857c2cbef3d130d7ec4c64bd85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bce634b3f620247fcf6dc9bc7737f2835b1e17a1f36f554bb63c83193ba3350377b309095031154d8025fced6d9badcbbda3afd0071101114360bab38872ae4
|
7
|
+
data.tar.gz: cd56d6ceff533df2d6b9a0c21347cb903f65a8dedb3f2b1b0f285a27649ba16f13e84eeb06249a93c7fc234f4c717b29443bb636a97b1a19c127fbc3c7e54633
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ It is still under heavy development. Use the latest version.
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'scale_rb', '~> 0.4.
|
10
|
+
gem 'scale_rb', '~> 0.4.2'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -25,6 +25,7 @@ git clone https://github.com/wuminzhe/scale_rb.git
|
|
25
25
|
cd scale_rb
|
26
26
|
bundle install
|
27
27
|
bundle exec ruby examples/http_client_1.rb
|
28
|
+
# CONSOLE_LEVEL=debug bundle exec ruby examples/http_client_1.rb
|
28
29
|
```
|
29
30
|
|
30
31
|
## Development
|
data/examples/http_client_1.rb
CHANGED
data/examples/ws_client_1.rb
CHANGED
data/examples/ws_client_3.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'scale_rb'
|
2
2
|
|
3
|
-
# ScaleRb.logger.level = Logger::DEBUG
|
4
|
-
|
5
3
|
# Unsubscribe after receiving 4 new heads
|
6
4
|
ScaleRb::WsClient.start('wss://polkadot-rpc.dwellir.com') do |client|
|
7
5
|
count = 0
|
@@ -15,7 +13,7 @@ ScaleRb::WsClient.start('wss://polkadot-rpc.dwellir.com') do |client|
|
|
15
13
|
puts "Received new head at height: #{block_number}, block hash: #{block_hash}"
|
16
14
|
else
|
17
15
|
unsub_result = client.chain_unsubscribeNewHead(subscription_id)
|
18
|
-
puts "Unsubscribe
|
16
|
+
puts "Unsubscribe #{subscription_id} #{unsub_result === true ? 'succeeded' : 'failed'}"
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
data/examples/ws_client_4.rb
CHANGED
@@ -14,8 +14,6 @@ def fetch_some_storages(client, block_number)
|
|
14
14
|
puts "Time taken: #{end_time - start_time} seconds"
|
15
15
|
end
|
16
16
|
|
17
|
-
ScaleRb.logger.level = Logger::DEBUG
|
18
|
-
|
19
17
|
ScaleRb::WsClient.start('wss://polkadot-rpc.dwellir.com') do |client|
|
20
18
|
fetch_some_storages(client, 21711742)
|
21
19
|
end
|
data/lib/client/http_client.rb
CHANGED
@@ -31,7 +31,7 @@ module ScaleRb
|
|
31
31
|
|
32
32
|
request = Net::HTTP::Post.new(@uri, 'Content-Type' => 'application/json')
|
33
33
|
request.body = { jsonrpc: '2.0', method: method, params: params, id: Time.now.to_i }.to_json
|
34
|
-
ScaleRb.logger.debug "
|
34
|
+
ScaleRb.logger.debug "—→ #{request.body}"
|
35
35
|
|
36
36
|
# https://docs.ruby-lang.org/en/master/Net/HTTPResponse.html
|
37
37
|
response = http.request(request)
|
@@ -39,7 +39,7 @@ module ScaleRb
|
|
39
39
|
|
40
40
|
# parse response, make key symbol
|
41
41
|
body = JSON.parse(response.body, symbolize_names: true)
|
42
|
-
ScaleRb.logger.debug "
|
42
|
+
ScaleRb.logger.debug "←— #{body}"
|
43
43
|
raise body[:error] if body[:error]
|
44
44
|
|
45
45
|
body[:result]
|
@@ -50,8 +50,6 @@ module ScaleRb
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def method_missing(method, *args)
|
53
|
-
# ScaleRb.logger.debug "#{method}(#{args.join(', ')})"
|
54
|
-
|
55
53
|
request(method.to_s, args)
|
56
54
|
end
|
57
55
|
end
|
data/lib/client/ws_client.rb
CHANGED
@@ -22,7 +22,7 @@ module ScaleRb
|
|
22
22
|
data = parse_message(message)
|
23
23
|
next if data.nil?
|
24
24
|
|
25
|
-
ScaleRb.logger.debug "
|
25
|
+
ScaleRb.logger.debug "←— #{data}"
|
26
26
|
Async do
|
27
27
|
client.handle_response(data)
|
28
28
|
end
|
@@ -45,7 +45,7 @@ module ScaleRb
|
|
45
45
|
def parse_message(message)
|
46
46
|
message.parse
|
47
47
|
rescue StandardError => e
|
48
|
-
|
48
|
+
Console::Event::Failure.for(e).emit(self, "Parse message failed!")
|
49
49
|
nil
|
50
50
|
end
|
51
51
|
end
|
@@ -71,7 +71,6 @@ module ScaleRb
|
|
71
71
|
|
72
72
|
def method_missing(method, *args)
|
73
73
|
method = method.to_s
|
74
|
-
# ScaleRb.logger.debug "#{method}(#{args.join(', ')})"
|
75
74
|
|
76
75
|
# why not check 'rpc_methods', because there is no @supported_methods when initializing
|
77
76
|
if method != 'rpc_methods' && !@supported_methods.include?(method)
|
@@ -117,16 +116,14 @@ module ScaleRb
|
|
117
116
|
ScaleRb.logger.info "Received an unknown response: #{response}"
|
118
117
|
end
|
119
118
|
rescue StandardError => e
|
120
|
-
|
121
|
-
ScaleRb.logger.debug e.backtrace.join("\n")
|
119
|
+
Console::Event::Failure.for(e).emit(self, "Handle response failed!")
|
122
120
|
end
|
123
121
|
|
124
122
|
def read_message
|
125
123
|
loop do
|
126
124
|
return @connection.read
|
127
125
|
rescue StandardError => e
|
128
|
-
|
129
|
-
ScaleRb.logger.debug e.backtrace.join("\n")
|
126
|
+
Console::Event::Failure.for(e).emit(self, "Read message from connection failed!")
|
130
127
|
sleep 1
|
131
128
|
retry
|
132
129
|
end
|
@@ -142,7 +139,7 @@ module ScaleRb
|
|
142
139
|
})
|
143
140
|
|
144
141
|
request = { jsonrpc: '2.0', id: @request_id, method: method, params: params }
|
145
|
-
ScaleRb.logger.debug "
|
142
|
+
ScaleRb.logger.debug "—→ #{request}"
|
146
143
|
@connection.write(request.to_json)
|
147
144
|
|
148
145
|
@request_id += 1
|
data/lib/scale_rb/version.rb
CHANGED
data/lib/scale_rb.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'scale_rb/version'
|
4
|
-
require '
|
4
|
+
require 'console'
|
5
5
|
|
6
6
|
# scale codec
|
7
7
|
require 'monkey_patching'
|
@@ -39,6 +39,4 @@ module ScaleRb
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
logger =
|
43
|
-
logger.level = Logger::INFO
|
44
|
-
ScaleRb.logger = logger
|
42
|
+
ScaleRb.logger = Console
|
data/scale_rb.gemspec
CHANGED
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.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aki Wu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base58
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.26.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: console
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: This gem includes a ruby implementation of SCALE Codec, a general Substrate
|
98
112
|
Http JSONRPC Client, and, a general Substrate Websocket JSON-RPC Client.
|
99
113
|
email:
|