katapaty 1.0.2 → 1.1.0
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 -0
- data/lib/katapaty/block.rb +24 -8
- data/lib/katapaty/configuration.rb +12 -3
- data/lib/katapaty/party.rb +17 -8
- data/lib/katapaty/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c343bb08ed79a5ec9358724bdfb29d8c6050467179f36479cb0c5b94429d92d9
|
4
|
+
data.tar.gz: 2a7048fdd064e699d904b89a2e793c3181d068d8f75d185f8fec5ce2a26908bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4659f173babc0f1a74ae257c99ee27dac48af777fd9c23e95eaba3f5472a7dab8fd98282d793253ecc4c28f8f144f3b53d5614169ae3cd03ea0f0e9b6e2d1d7a
|
7
|
+
data.tar.gz: 901c1caf9c4906f0610f91d241f535d4dc50544ac6575190e04604db05cc591a0aeda78f9e730856ddf0015b5935630905e82b750b26ddc7338b34db7635f22c
|
data/README.md
CHANGED
data/lib/katapaty/block.rb
CHANGED
@@ -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,
|
9
|
-
client = RestClient::Resource.new Katapaty.configuration.
|
10
|
-
request = { method: method_name, params:
|
11
|
-
response = JSON.parse client.post(
|
12
|
-
|
13
|
-
|
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
|
-
|
21
|
-
request(name,
|
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
|
-
|
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
|
data/lib/katapaty/party.rb
CHANGED
@@ -9,11 +9,20 @@ module Katapaty
|
|
9
9
|
request('get_running_info')
|
10
10
|
end
|
11
11
|
|
12
|
-
def address_token_balance(address
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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.
|
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
|
-
|
52
|
-
|
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']
|
data/lib/katapaty/version.rb
CHANGED
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
|
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-
|
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: []
|