katapaty 1.0.2 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1f67e4fc0286be7da99524e14b516103b233b88671b1e54a3f339fe7a7fee9e
4
- data.tar.gz: dfbb06845fcb3e88d7de9589cbe9ffc9d66c1da47081a9008c1fefc4e77826d4
3
+ metadata.gz: c343bb08ed79a5ec9358724bdfb29d8c6050467179f36479cb0c5b94429d92d9
4
+ data.tar.gz: 2a7048fdd064e699d904b89a2e793c3181d068d8f75d185f8fec5ce2a26908bc
5
5
  SHA512:
6
- metadata.gz: 7888cbbab491758e55df7ce155660d23102fb53140687a72bee16c4749627bdc36f902112cfb9d553e67779611816b51a0574303679c2c8c8f4930ddafe691eb
7
- data.tar.gz: 3fbf54e6bf1ccd946fd7bb742ea64c28e10846e7ed596f0d9531b65b6cd0b0a6dbd04e046b6d02b94bacd97475d2ebd38d3d3c93fd1e03fdd8abb9189294abba
6
+ metadata.gz: 4659f173babc0f1a74ae257c99ee27dac48af777fd9c23e95eaba3f5472a7dab8fd98282d793253ecc4c28f8f144f3b53d5614169ae3cd03ea0f0e9b6e2d1d7a
7
+ data.tar.gz: 901c1caf9c4906f0610f91d241f535d4dc50544ac6575190e04604db05cc591a0aeda78f9e730856ddf0015b5935630905e82b750b26ddc7338b34db7635f22c
data/README.md CHANGED
@@ -47,6 +47,8 @@ Katapaty::Party.create_send(
47
47
  asset: "LONGDD",
48
48
  quantity: 50000
49
49
  )
50
+
51
+ Katapaty::Block.proxy_to_cp(method: :get_running_info)
50
52
  ```
51
53
 
52
54
  Check methods here: https://counterparty.io/docs/api/#read-api-function-reference
@@ -1,24 +1,40 @@
1
1
  #
2
2
  # Counterblock APIs
3
3
  #
4
+ #
4
5
  module Katapaty
5
6
  class Block
6
7
  class << self
7
8
 
8
- def request(method_name, payload={})
9
- client = RestClient::Resource.new Katapaty.configuration.counterblock_url
10
- request = { method: method_name, params: payload, jsonrpc: '2.0', id: '0' }.to_json
11
- response = JSON.parse client.post(request,
12
- accept: 'json',
13
- content_type: 'json' )
9
+ def request(method_name, params={})
10
+ client = RestClient::Resource.new(Katapaty.configuration.counterblock_url, timeout: Katapaty.configuration.timeout)
11
+ request = { method: method_name, params: params, jsonrpc: '2.0', id: '0' }.to_json
12
+ response = JSON.parse client.post(
13
+ request,
14
+ accept: 'json',
15
+ content_type: 'json'
16
+ )
14
17
  raise JsonResponseError.new response if response.has_key? 'code'
15
18
  raise ResponseError.new response['error'] if response.has_key? 'error'
16
19
  response['result']
17
20
  end
18
21
 
19
22
  def method_missing(name, *args)
20
- args = args.nil? ? {} : args.first
21
- request(name, args)
23
+ params = args.nil? ? {} : args.first
24
+ request(name, params)
25
+ end
26
+
27
+ def proxy_to_cp(method:, params: {})
28
+ client = RestClient::Resource.new(Katapaty.configuration.counterblock_url, timeout: Katapaty.configuration.timeout)
29
+ request = { method: :proxy_to_counterpartyd, params: { method: method, params: params }, jsonrpc: '2.0', id: '0' }.to_json
30
+ response = JSON.parse client.post(
31
+ request,
32
+ accept: 'json',
33
+ content_type: 'json'
34
+ )
35
+ raise JsonResponseError.new response if response.has_key? 'code'
36
+ raise ResponseError.new response['error'] if response.has_key? 'error'
37
+ response['result']
22
38
  end
23
39
  end
24
40
  end
@@ -8,16 +8,25 @@ module Katapaty
8
8
  :block_password,
9
9
  :block_host,
10
10
  :block_port,
11
- :ssl
11
+ :ssl,
12
+ :timeout
13
+
14
+ DEFAULT_TIMEOUT_IN_SECONDS = 60
12
15
 
13
16
  def counterparty_url
14
17
  return 'http://rpc:1234@public.coindaddy.io:14000/api/' unless @host
15
- "#{protocol}://#{@username}:#{@password}@#{@host}:#{@port}/api/"
18
+ "#{protocol}://#{@username}:#{CGI.escape(@password)}@#{@host}:#{@port}/api/"
16
19
  end
17
20
 
18
21
  def counterblock_url
19
22
  return 'http://rpc:1234@public.coindaddy.io:14100/api/' unless @block_host
20
- "#{protocol}://#{@block_username}:#{@block_password}@#{@block_host}:#{@block_port}/api/"
23
+ authen = ''
24
+ authen = "#{@block_username}:#{CGI.escape(@block_password)}@" if @block_username
25
+ "#{protocol}://#{authen}#{@block_host}:#{@block_port}/api/"
26
+ end
27
+
28
+ def timeout
29
+ @timeout || DEFAULT_TIMEOUT_IN_SECONDS
21
30
  end
22
31
 
23
32
  private
@@ -9,11 +9,20 @@ module Katapaty
9
9
  request('get_running_info')
10
10
  end
11
11
 
12
- def address_token_balance(address, token_name)
13
- rs = request('get_balances', {"filters": [{ "field": 'address', "op": '==', "value": address },
14
- { "field": 'asset', "op": '==', "value": token_name }]})
15
- return 0 if rs.blank?
16
- rs.first['quantity'].to_i
12
+ def address_token_balance(address:, token:, proxy: false)
13
+ filters_params = {
14
+ "filters": [
15
+ { "field": 'address', "op": '==', "value": address },
16
+ { "field": 'asset', "op": '==', "value": token }
17
+ ]
18
+ }
19
+ if proxy
20
+ response = Katapaty::Block.proxy_to_cp(method: :get_balances, params: filters_params)
21
+ else
22
+ response = request('get_balances', filters_params)
23
+ end
24
+ return 0 if response.blank?
25
+ response.first['quantity'].to_i
17
26
  end
18
27
 
19
28
  def get_asset_info(assets)
@@ -45,11 +54,11 @@ module Katapaty
45
54
  end
46
55
 
47
56
  def request(method_name, payload={})
48
- client = RestClient::Resource.new Katapaty.configuration.counterparty_url
57
+ client = RestClient::Resource.new(Katapaty.configuration.counterparty_url, timeout: Katapaty.configuration.timeout)
49
58
  request = { method: method_name.to_s, params: payload, jsonrpc: '2.0', id: '0' }.to_json
50
59
  response = JSON.parse client.post(request,
51
- accept: 'json',
52
- content_type: 'json' )
60
+ accept: 'json',
61
+ content_type: 'json' )
53
62
  raise Katapaty::JsonResponseError.new response if response.has_key? 'code'
54
63
  raise Katapaty::ResponseError.new response['error'] if response.has_key? 'error'
55
64
  response['result']
@@ -1,3 +1,3 @@
1
1
  module Katapaty
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katapaty
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - longhoang.wkm
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-23 00:00:00.000000000 Z
11
+ date: 2020-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,7 +150,7 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
- description:
153
+ description:
154
154
  email:
155
155
  - longhoang@wakumo.vn
156
156
  executables: []
@@ -178,7 +178,7 @@ homepage: https://github.com/longhoangwkm/katapaty
178
178
  licenses:
179
179
  - MIT
180
180
  metadata: {}
181
- post_install_message:
181
+ post_install_message:
182
182
  rdoc_options: []
183
183
  require_paths:
184
184
  - lib
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  version: '0'
195
195
  requirements: []
196
196
  rubygems_version: 3.1.3
197
- signing_key:
197
+ signing_key:
198
198
  specification_version: 4
199
199
  summary: A ruby gem for communicating with a Counterparty (Bitcoin / XCP) API server
200
200
  test_files: []