scale_rb 0.1.9 → 0.1.10

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: a4ecdacacab52152c1db21cd934b452fca391320112c7a8a1c5a8479b4df9946
4
- data.tar.gz: 637a12f9313b048bcd7e5c77dd34862225db553b0e42f620736aea5c78505a49
3
+ metadata.gz: 0c7019e91465191e14eb99ca5b57435245b9cb533cc0b5eb7e9ee944f8485a8c
4
+ data.tar.gz: 8d9eb533ffb3046536f915c39271049d46b20a1417989e6844c6b3ba927bd1e3
5
5
  SHA512:
6
- metadata.gz: 18c6f40b6f41b3fa59a08c93a44b348e94642fe510f695576b164d5b0ad70362bfa0ade33823c422b85b9db55f2f23995598c9990c2a4b7c6e6113cb17b73ba0
7
- data.tar.gz: bbb523afb3209dfd58827094cc4f1fce4d841fff5bba5b94538a736edac05803fb0dd3624dcedc5d2c068944614f7d43e053528574df402713f56b9ecb03c2ce
6
+ metadata.gz: ef65503ad4ccc4f26490c0ff9ed0715beb312ee50ca5ca6a1f4824a924a01cd833503bbd1f80e8c510eb26d12a6f400655a0fcc5bed12a505ef15cb1e686b69d
7
+ data.tar.gz: cf36689a9d7bf12c104f51e39483f3db58d073423d314692f07cfba1ce49e324032c57b4fbe122b207f85ac08af60bbdb44dc8e21fde0c558bbbd05bb255d40f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scale_rb (0.1.9)
4
+ scale_rb (0.1.10)
5
5
  base58
6
6
  blake2b_rs (~> 0.1.4)
7
7
  xxhash
@@ -4,24 +4,34 @@ require 'uri'
4
4
  require 'net/http'
5
5
  require 'json'
6
6
 
7
+ # TODO: method_name = cmd.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
7
8
  module ScaleRb
8
9
  module HttpClient
9
10
  extend RpcRequestBuilder
10
11
 
11
12
  class << self
12
13
  def request(url, body)
14
+ ScaleRb.logger.debug "url: #{url}"
15
+ ScaleRb.logger.debug "body: #{body}"
13
16
  uri = URI(url)
14
17
  req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
15
18
  req.body = body
16
19
  http = Net::HTTP.new(uri.host, uri.port)
17
20
  http.use_ssl = true if uri.instance_of? URI::HTTPS
18
21
  res = http.request(req)
19
- # puts res unless res.is_a?(Net::HTTPSuccess)
22
+
23
+ raise res.class.name unless res.is_a?(Net::HTTPSuccess)
20
24
 
21
25
  result = JSON.parse(res.body)
22
- raise result['error'] if result['error']
26
+ ScaleRb.logger.debug result
27
+ raise result['error']['message'] if result['error']
23
28
 
24
29
  result['result']
30
+ rescue StandardError => e
31
+ ScaleRb.logger.error e.message
32
+ ScaleRb.logger.error 'retry...'
33
+ sleep 2
34
+ request(url, body)
25
35
  end
26
36
 
27
37
  def json_rpc_call(url, method, *params)
@@ -34,7 +44,20 @@ module ScaleRb
34
44
  end
35
45
 
36
46
  def method_missing(method, *args)
37
- json_rpc_call(args[0], method, *args[1..])
47
+ ScaleRb.logger.debug "#{method}(#{args.join(', ')})"
48
+ # check if the first argument is a url
49
+ url_regex = %r{^https?://}
50
+ raise 'url format is not correct' unless args[0].match?(url_regex)
51
+
52
+ url = args[0]
53
+ raise NoMethodError, "undefined rpc method `#{method}'" unless rpc_methods(url).include?(method.to_s)
54
+
55
+ json_rpc_call(url, method, *args[1..])
56
+ end
57
+
58
+ def rpc_methods(url)
59
+ result = json_rpc_call(url, 'rpc_methods', [])
60
+ result['methods']
38
61
  end
39
62
 
40
63
  def get_metadata(url, at = nil)
@@ -157,4 +180,4 @@ module ScaleRb
157
180
  end
158
181
  end
159
182
  end
160
- end
183
+ end
@@ -1,3 +1,3 @@
1
1
  module ScaleRb
2
- VERSION = '0.1.9'
2
+ VERSION = '0.1.10'
3
3
  end
data/lib/scale_rb.rb CHANGED
@@ -32,16 +32,14 @@ require 'address'
32
32
 
33
33
  module ScaleRb
34
34
  class << self
35
- attr_writer :logger
36
-
37
- def logger
38
- @logger ||= Logger.new($stdout)
39
- @logger.level = Logger::INFO
40
- @logger
41
- end
35
+ attr_accessor :logger
42
36
 
43
37
  def debug(key, value)
44
38
  logger.debug "#{key.rjust(15)}: #{value}"
45
39
  end
46
40
  end
47
41
  end
42
+
43
+ logger = Logger.new($stdout)
44
+ logger.level = Logger::INFO
45
+ ScaleRb.logger = logger
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.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aki Wu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-06 00:00:00.000000000 Z
11
+ date: 2023-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: blake2b_rs