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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15825760ac8babb0cfa263f8cdaf72c8cdad02cc24c5c7816d1ff6febf6db8de
4
- data.tar.gz: a93953348decaf1fb7f220a9e0929e84e7ba4ee3ae7c53562c2064cea6a4d892
3
+ metadata.gz: 51b2e982dba83d910e71a3165d0842a84ff8cf5645c03f4fddfd5fe7c972b369
4
+ data.tar.gz: 4a4be7435a1821bf40bcdf917a8d148616dae4857c2cbef3d130d7ec4c64bd85
5
5
  SHA512:
6
- metadata.gz: 6abb7a322f18aa546886081a03775824b02a988389572ab58c4ecbf58fa130c1391fb46d5ef8355e61752d0add3690085758f9b7a2e27ab4080ba57630eb5406
7
- data.tar.gz: '0377164249cb083560b6f8b5eb70f510413b4c620d7a51675da23d23cb4038c33e8e54040135b4a70ff9faeba0b1afba001408172e46cbc19f72c636e3a6a256'
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.0'
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
@@ -1,8 +1,6 @@
1
1
 
2
2
  require 'scale_rb'
3
3
 
4
- ScaleRb.logger.level = Logger::DEBUG
5
-
6
4
  client = ScaleRb::HttpClient.new('https://polkadot-rpc.dwellir.com')
7
5
  block_hash = client.chain_getBlockHash(21585684)
8
6
  runtime_version = client.state_getRuntimeVersion(block_hash)
@@ -1,7 +1,5 @@
1
1
  require 'scale_rb'
2
2
 
3
- ScaleRb.logger.level = Logger::DEBUG
4
-
5
3
  ScaleRb::WsClient.start('wss://polkadot-rpc.dwellir.com') do |client|
6
4
  block_hash = client.chain_getBlockHash(21585684)
7
5
  runtime_version = client.state_getRuntimeVersion(block_hash)
@@ -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 result: #{unsub_result}"
16
+ puts "Unsubscribe #{subscription_id} #{unsub_result === true ? 'succeeded' : 'failed'}"
19
17
  end
20
18
  end
21
19
 
@@ -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
@@ -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 "Request: #{request.body}"
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 "Response: #{body}"
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
@@ -22,7 +22,7 @@ module ScaleRb
22
22
  data = parse_message(message)
23
23
  next if data.nil?
24
24
 
25
- ScaleRb.logger.debug "Response: #{data}"
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
- ScaleRb.logger.error "Error while parsing message: #{e.inspect}, message: #{message}"
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
- ScaleRb.logger.error "Error while handling response: #{e.inspect}"
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
- ScaleRb.logger.error "Error while read message from connection: #{e.inspect}"
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 "Request: #{request}"
142
+ ScaleRb.logger.debug "—→ #{request}"
146
143
  @connection.write(request.to_json)
147
144
 
148
145
  @request_id += 1
@@ -1,3 +1,3 @@
1
1
  module ScaleRb
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
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 'logger'
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 = Logger.new($stdout)
43
- logger.level = Logger::INFO
44
- ScaleRb.logger = logger
42
+ ScaleRb.logger = Console
data/scale_rb.gemspec CHANGED
@@ -38,4 +38,6 @@ Gem::Specification.new do |spec|
38
38
  spec.add_dependency 'async'
39
39
  spec.add_dependency 'async-http', '~> 0.69.0'
40
40
  spec.add_dependency 'async-websocket', '~> 0.26.2'
41
+ # for logger
42
+ spec.add_dependency 'console'
41
43
  end
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.1
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-05 00:00:00.000000000 Z
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: