katapaty 0.3.5 → 0.4.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 +4 -4
- data/README.md +14 -2
- data/katapaty.gemspec +1 -0
- data/lib/katapaty/block.rb +20 -0
- data/lib/katapaty/configuration.rb +12 -2
- data/lib/katapaty/party.rb +47 -0
- data/lib/katapaty/version.rb +1 -1
- data/lib/katapaty.rb +12 -26
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1d70e989203628e501ff5a3c6acd00b7bf57f1d
|
4
|
+
data.tar.gz: ddab2560b850e41525ed215378cd8a0b8834d822
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1eb4e6984c1f002a75b821c344782734fa7ce4ed4a72e505e0a5a15deb1dcf83cb832a75016b07837d4771eaf576b0960a038a50bcc4844fd25e266f8e19b587
|
7
|
+
data.tar.gz: 2bb96d096d4971dbb978c350563b01e30f75b608402cefa474bd20b1b303f4352ee1aa35869b8db70176943d2266c0a7582064c61862a4e97a44839a59f091f4
|
data/README.md
CHANGED
@@ -23,17 +23,29 @@ Set your own counterparty node configuration in `config/initializers/katapaty.rb
|
|
23
23
|
```ruby
|
24
24
|
# This is testnet counterparty node of coindaddy, you can change your own server config
|
25
25
|
Katapaty.configure do |config|
|
26
|
+
# For counterparty APIs
|
26
27
|
config.username = 'rpc'
|
27
28
|
config.password = '1234'
|
28
29
|
config.host = 'public.coindaddy.io'
|
29
30
|
config.port = 14000
|
31
|
+
# For counterblock APIs
|
32
|
+
config.block_username = 'rpc'
|
33
|
+
config.block_password = '1234'
|
34
|
+
config.block_host = 'public.coindaddy.io'
|
35
|
+
config.block_port = 14100
|
30
36
|
end
|
31
37
|
```
|
32
38
|
|
33
|
-
|
34
39
|
## Usage Example
|
35
40
|
|
36
|
-
|
41
|
+
```ruby
|
42
|
+
Katapaty::Party.create_send(
|
43
|
+
source: "mypcUU2fYyJav7XUpPLtMVhuPupArLJtiM",
|
44
|
+
destination: "mjtwweXS2u5q1Ybypb271Wmehmj9g1w2th",
|
45
|
+
asset: "LONGDD",
|
46
|
+
quantity: 50000
|
47
|
+
)
|
48
|
+
```
|
37
49
|
|
38
50
|
Check methods here: https://counterparty.io/docs/api/#read-api-function-reference
|
39
51
|
|
data/katapaty.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.16"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "pry-rails"
|
26
27
|
|
27
28
|
spec.add_dependency "json", "~> 1.8"
|
28
29
|
spec.add_dependency "rest-client", "~> 1.8.0"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Counterblock APIs
|
3
|
+
#
|
4
|
+
module Katapaty
|
5
|
+
class Block
|
6
|
+
class << self
|
7
|
+
|
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' )
|
14
|
+
raise JsonResponseError.new response if response.has_key? 'code'
|
15
|
+
raise ResponseError.new response['error'] if response.has_key? 'error'
|
16
|
+
response['result']
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -3,10 +3,20 @@ module Katapaty
|
|
3
3
|
attr_accessor :username,
|
4
4
|
:password,
|
5
5
|
:host,
|
6
|
-
:port
|
6
|
+
:port,
|
7
|
+
:block_username,
|
8
|
+
:block_password,
|
9
|
+
:block_host,
|
10
|
+
:block_port
|
7
11
|
|
8
|
-
def
|
12
|
+
def counterparty_url
|
13
|
+
return 'http://rpc:1234@public.coindaddy.io:14000/api/' unless @host
|
9
14
|
"http://#{@username}:#{@password}@#{@host}:#{@port}/api/"
|
10
15
|
end
|
16
|
+
|
17
|
+
def counterblock_url
|
18
|
+
return 'http://rpc:1234@public.coindaddy.io:14100/api/' unless @block_host
|
19
|
+
"http://#{@block_username}:#{@block_password}@#{@block_host}:#{@block_port}/api/"
|
20
|
+
end
|
11
21
|
end
|
12
22
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#
|
2
|
+
# Counterparty APIs
|
3
|
+
#
|
4
|
+
|
5
|
+
module Katapaty
|
6
|
+
class Party
|
7
|
+
class << self
|
8
|
+
def get_running_info
|
9
|
+
request(__method__.to_s)
|
10
|
+
end
|
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
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_asset_info(assets)
|
20
|
+
request(__method__.to_s, { assets: assets })
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_blocks(block_indexes)
|
24
|
+
request(__method__.to_s, { block_indexes: block_indexes })
|
25
|
+
end
|
26
|
+
|
27
|
+
def getrawtransaction(tx_hash)
|
28
|
+
request(__method__.to_s, { tx_hash: tx_hash })
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_send(payload)
|
32
|
+
request(__method__.to_s, payload)
|
33
|
+
end
|
34
|
+
|
35
|
+
def request(method_name, payload={})
|
36
|
+
client = RestClient::Resource.new Katapaty.configuration.counterparty_url
|
37
|
+
request = { method: method_name, params: payload, jsonrpc: '2.0', id: '0' }.to_json
|
38
|
+
response = JSON.parse client.post(request,
|
39
|
+
accept: 'json',
|
40
|
+
content_type: 'json' )
|
41
|
+
raise JsonResponseError.new response if response.has_key? 'code'
|
42
|
+
raise ResponseError.new response['error'] if response.has_key? 'error'
|
43
|
+
response['result']
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/katapaty/version.rb
CHANGED
data/lib/katapaty.rb
CHANGED
@@ -7,37 +7,23 @@ require 'katapaty/version'
|
|
7
7
|
require 'katapaty/configuration'
|
8
8
|
require 'katapaty/errors'
|
9
9
|
require 'katapaty/tx_decode'
|
10
|
+
require 'katapaty/party'
|
11
|
+
require 'katapaty/block'
|
10
12
|
|
11
13
|
module Katapaty
|
14
|
+
extend self
|
12
15
|
|
13
|
-
|
16
|
+
attr_writer :configuration
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@configuration ||= Configuration.new
|
19
|
-
end
|
20
|
-
|
21
|
-
def reset
|
22
|
-
@configuration = Configuration.new
|
23
|
-
end
|
18
|
+
def configuration
|
19
|
+
@configuration ||= Configuration.new
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
def reset
|
23
|
+
@configuration = Configuration.new
|
24
|
+
end
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
client = RestClient::Resource.new @configuration.api_url
|
32
|
-
request = { method: name, params: args, jsonrpc: '2.0', id: '0' }.to_json
|
33
|
-
response = JSON.parse client.post(request,
|
34
|
-
user: @configuration.username,
|
35
|
-
password: @configuration.password,
|
36
|
-
accept: 'json',
|
37
|
-
content_type: 'json' )
|
38
|
-
raise JsonResponseError.new response if response.has_key? 'code'
|
39
|
-
raise ResponseError.new response['error'] if response.has_key? 'error'
|
40
|
-
response['result']
|
41
|
-
end
|
26
|
+
def configure
|
27
|
+
yield(configuration)
|
42
28
|
end
|
43
29
|
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: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- longhoang.wkm
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: json
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,8 +154,10 @@ files:
|
|
140
154
|
- bin/setup
|
141
155
|
- katapaty.gemspec
|
142
156
|
- lib/katapaty.rb
|
157
|
+
- lib/katapaty/block.rb
|
143
158
|
- lib/katapaty/configuration.rb
|
144
159
|
- lib/katapaty/errors.rb
|
160
|
+
- lib/katapaty/party.rb
|
145
161
|
- lib/katapaty/tx_decode.rb
|
146
162
|
- lib/katapaty/version.rb
|
147
163
|
homepage: https://github.com/longhoangwkm/katapaty
|