peatio-nexbit 0.1.2 → 0.1.3

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: 977d1c1c61e069772cf34646ac239be1e317de6cd5601b47440facede9249fe2
4
- data.tar.gz: 2931f46f272cc4ddb87d539b2e35a23e14de766769eea95bde50be9e1a115eb4
3
+ metadata.gz: ff46d7b79a5e6df6ebab164f67cdb0f871feec60429524c1a436e8511290fa61
4
+ data.tar.gz: 90f29909ff30698347514c0d6125cab42e50dbad7b2ae4cba8543bc69baa97b7
5
5
  SHA512:
6
- metadata.gz: a1c9f47c3ce88afbe9d44a5b5b3f1bf6bfc616ec7f61d19a370aaa3b929eeb20b96b746717013a095498b73e3d946822c8395e195c9dd026b5ab0320c37a4d4e
7
- data.tar.gz: 1a731bfbeec4ea456b4b85dba46f2951c57e961f2cc3e2e96f9eaefe5274d237583c59e6176054037eef4707e35aa94b944234cab7b379951e845c8adf570079
6
+ metadata.gz: 437eef825cf2086705eafe6e732bf973c9fc81847ac7790c006feb1af73d7df4f512711ca2d642830da550b429cd6d65906e9a63843bcebbf29f9f4748f47d9e
7
+ data.tar.gz: 150936d3f69fe8f9cd9e39845a4b4f8154383cca9f311d586a260d65ba0a5e4788d168a88f2e00f0da6255c5bfc747317a30c47f04f4455303e7db4a98e800d9
@@ -1,85 +1,82 @@
1
+ module Nexbit
2
+ # TODO: Processing of unconfirmed transactions from mempool isn't supported now.
3
+ class Blockchain < Peatio::Blockchain::Abstract
1
4
 
2
- module Peatio
3
- module Nexbit
4
- # TODO: Processing of unconfirmed transactions from mempool isn't supported now.
5
- class Blockchain < Peatio::Blockchain::Abstract
5
+ DEFAULT_FEATURES = {case_sensitive: true, cash_addr_format: false}.freeze
6
6
 
7
- DEFAULT_FEATURES = {case_sensitive: true, cash_addr_format: false}.freeze
8
-
9
- def initialize(custom_features = {})
10
- @features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES)
11
- @settings = {}
12
- end
7
+ def initialize(custom_features = {})
8
+ @features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES)
9
+ @settings = {}
10
+ end
13
11
 
14
- def configure(settings = {})
15
- # Clean client state during configure.
16
- @client = nil
17
- @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
18
- end
12
+ def configure(settings = {})
13
+ # Clean client state during configure.
14
+ @client = nil
15
+ @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
16
+ end
19
17
 
20
- def fetch_block!(block_number)
21
- block_hash = client.json_rpc(:getblockhash, [block_number])
18
+ def fetch_block!(block_number)
19
+ block_hash = client.json_rpc(:getblockhash, [block_number])
22
20
 
23
- client.json_rpc(:getblock, [block_hash, 2])
24
- .fetch('tx').each_with_object([]) do |tx, txs_array|
21
+ client.json_rpc(:getblock, [block_hash, 2])
22
+ .fetch('tx').each_with_object([]) do |tx, txs_array|
25
23
  txs = build_transaction(tx).map do |ntx|
26
24
  Peatio::Transaction.new(ntx.merge(block_number: block_number))
27
25
  end
28
26
  txs_array.append(*txs)
29
27
  end.yield_self { |txs_array| Peatio::Block.new(block_number, txs_array) }
30
- rescue Client::Error => e
31
- raise Peatio::Blockchain::ClientError, e
32
- end
28
+ rescue Nexbit::Client::Error => e
29
+ raise Peatio::Blockchain::ClientError, e
30
+ end
33
31
 
34
- def latest_block_number
35
- client.json_rpc(:getblockcount)
36
- rescue Client::Error => e
37
- raise Peatio::Blockchain::ClientError, e
38
- end
32
+ def latest_block_number
33
+ client.json_rpc(:getblockcount)
34
+ rescue Nexbit::Client::Error => e
35
+ raise Peatio::Blockchain::ClientError, e
36
+ end
39
37
 
40
- def load_balance_of_address!(address, _currency_id)
41
- address_with_balance = client.json_rpc(:listaddressgroupings)
42
- .flatten(1)
43
- .find { |addr| addr[0] == address }
38
+ def load_balance_of_address!(address, _currency_id)
39
+ address_with_balance = client.json_rpc(:listaddressgroupings)
40
+ .flatten(1)
41
+ .find { |addr| addr[0] == address }
44
42
 
45
- if address_with_balance.blank?
46
- raise Peatio::Blockchain::UnavailableAddressBalanceError, address
47
- end
48
-
49
- address_with_balance[1].to_d
50
- rescue Client::Error => e
51
- raise Peatio::Blockchain::ClientError, e
43
+ if address_with_balance.blank?
44
+ raise Peatio::Blockchain::UnavailableAddressBalanceError, address
52
45
  end
53
46
 
54
- private
47
+ address_with_balance[1].to_d
48
+ rescue Nexbit::Client::Error => e
49
+ raise Peatio::Blockchain::ClientError, e
50
+ end
51
+
52
+ private
55
53
 
56
- def build_transaction(tx_hash)
57
- tx_hash.fetch('vout')
58
- .select do |entry|
54
+ def build_transaction(tx_hash)
55
+ tx_hash.fetch('vout')
56
+ .select do |entry|
59
57
  entry.fetch('value').to_d > 0 &&
60
- entry['scriptPubKey'].has_key?('addresses')
58
+ entry['scriptPubKey'].has_key?('addresses')
61
59
  end
62
- .each_with_object([]) do |entry, formatted_txs|
60
+ .each_with_object([]) do |entry, formatted_txs|
63
61
  no_currency_tx =
64
62
  { hash: tx_hash['txid'], txout: entry['n'],
65
63
  to_address: entry['scriptPubKey']['addresses'][0],
66
64
  amount: entry.fetch('value').to_d,
67
65
  status: 'success' }
68
66
 
69
- # Build transaction for each currency belonging to blockchain.
70
- settings_fetch(:currencies).pluck(:id).each do |currency_id|
71
- formatted_txs << no_currency_tx.merge(currency_id: currency_id)
72
- end
67
+ # Build transaction for each currency belonging to blockchain.
68
+ settings_fetch(:currencies).pluck(:id).each do |currency_id|
69
+ formatted_txs << no_currency_tx.merge(currency_id: currency_id)
70
+ end
73
71
  end
74
- end
72
+ end
75
73
 
76
- def client
77
- @client ||= Client.new(settings_fetch(:server))
78
- end
74
+ def client
75
+ @client ||= Nexbit::Client.new(settings_fetch(:server))
76
+ end
79
77
 
80
- def settings_fetch(key)
81
- @settings.fetch(key) { raise Peatio::Blockchain::MissingSettingError, key.to_s }
82
- end
78
+ def settings_fetch(key)
79
+ @settings.fetch(key) { raise Peatio::Blockchain::MissingSettingError, key.to_s }
83
80
  end
84
81
  end
85
82
  end
@@ -1,61 +1,48 @@
1
- require 'memoist'
2
- require 'faraday'
3
- require 'better-faraday'
1
+ module Nexbit
2
+ class Client
3
+ Error = Class.new(StandardError)
4
4
 
5
- module Peatio
6
- module Nexbit
7
- class Client
8
- Error = Class.new(StandardError)
9
- class ConnectionError < Error; end
5
+ class ConnectionError < Error; end
10
6
 
11
- class ResponseError < Error
12
- def initialize(code, msg)
13
- @code = code
14
- @msg = msg
15
- end
16
-
17
- def message
18
- "#{@msg} (#{@code})"
19
- end
7
+ class ResponseError < Error
8
+ def initialize(code, msg)
9
+ super "#{msg} (#{code})"
20
10
  end
11
+ end
21
12
 
22
- extend Memoist
13
+ extend Memoist
23
14
 
24
- def initialize(endpoint)
25
- @json_rpc_endpoint = URI.parse(endpoint)
26
- end
15
+ def initialize(endpoint, idle_timeout: 5)
16
+ @json_rpc_endpoint = URI.parse(endpoint)
17
+ @idle_timeout = idle_timeout
18
+ end
27
19
 
28
- def json_rpc(method, params = [])
29
- response = connection.post \
30
- '/',
31
- { jsonrpc: '1.0', method: method, params: params }.to_json,
32
- { 'Accept' => 'application/json',
33
- 'Content-Type' => 'application/json' }
34
- response.assert_2xx!
35
- response = JSON.parse(response.body)
36
- response['error'].tap { |e| raise ResponseError.new(e['code'], e['message']) if e }
37
- response.fetch('result')
38
- rescue => e
39
- if e.is_a?(Error)
40
- raise e
41
- elsif e.is_a?(Faraday::Error)
42
- raise ConnectionError, e
43
- else
44
- raise Error, e
45
- end
46
- end
20
+ def json_rpc(method, params = [])
21
+ response = connection.post \
22
+ '/',
23
+ {jsonrpc: '1.0', method: method, params: params}.to_json,
24
+ {'Accept' => 'application/json',
25
+ 'Content-Type' => 'application/json'}
26
+ response.assert_success!
27
+ response = JSON.parse(response.body)
28
+ response['error'].tap { |error| raise ResponseError.new(error['code'], error['message']) if error }
29
+ response.fetch('result')
30
+ rescue Faraday::Error => e
31
+ raise ConnectionError, e
32
+ rescue StandardError => e
33
+ raise Error, e
34
+ end
47
35
 
48
- private
36
+ private
49
37
 
50
- def connection
51
- Faraday.new(@json_rpc_endpoint).tap do |connection|
52
- unless @json_rpc_endpoint.user.blank?
53
- connection.basic_auth(@json_rpc_endpoint.user,
54
- @json_rpc_endpoint.password)
55
- end
38
+ def connection
39
+ @connection ||= Faraday.new(@json_rpc_endpoint) do |f|
40
+ f.adapter :net_http_persistent, pool_size: 5, idle_timeout: @idle_timeout
41
+ end.tap do |connection|
42
+ unless @json_rpc_endpoint.user.blank?
43
+ connection.basic_auth(@json_rpc_endpoint.user, @json_rpc_endpoint.password)
56
44
  end
57
45
  end
58
- memoize :connection
59
46
  end
60
47
  end
61
48
  end
@@ -1,5 +1,5 @@
1
1
  module Peatio
2
2
  module Nexbit
3
- VERSION = "0.1.2".freeze
3
+ VERSION = "0.1.3".freeze
4
4
  end
5
5
  end
@@ -1,60 +1,58 @@
1
- module Peatio
2
- module Nexbit
3
- class Wallet < Peatio::Wallet::Abstract
4
-
5
- def initialize(settings = {})
6
- @settings = settings
7
- end
8
-
9
- def configure(settings = {})
10
- # Clean client state during configure.
11
- @client = nil
12
-
13
- @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
14
-
15
- @wallet = @settings.fetch(:wallet) do
16
- raise Peatio::Wallet::MissingSettingError, :wallet
17
- end.slice(:uri, :address)
18
-
19
- @currency = @settings.fetch(:currency) do
20
- raise Peatio::Wallet::MissingSettingError, :currency
21
- end.slice(:id, :base_factor, :options)
22
- end
23
-
24
- def create_address!(_options = {})
25
- { address: client.json_rpc(:getnewaddress) }
26
- rescue Nexbit::Client::Error => e
27
- raise Peatio::Wallet::ClientError, e
28
- end
29
-
30
- def create_transaction!(transaction, options = {})
31
- txid = client.json_rpc(:sendtoaddress,
32
- [
33
- transaction.to_address,
34
- transaction.amount,
35
- '',
36
- '',
37
- options[:subtract_fee].to_s == 'true' # subtract fee from transaction amount.
38
- ])
39
- transaction.hash = txid
40
- transaction
41
- rescue Nexbit::Client::Error => e
42
- raise Peatio::Wallet::ClientError, e
43
- end
44
-
45
- def load_balance!
46
- client.json_rpc(:getbalance).to_d
47
-
48
- rescue Nexbit::Client::Error => e
49
- raise Peatio::Wallet::ClientError, e
50
- end
51
-
52
- private
53
-
54
- def client
55
- uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
56
- @client ||= Client.new(uri)
57
- end
1
+ module Nexbit
2
+ class Wallet < Peatio::Wallet::Abstract
3
+
4
+ def initialize(settings = {})
5
+ @settings = settings
6
+ end
7
+
8
+ def configure(settings = {})
9
+ # Clean client state during configure.
10
+ @client = nil
11
+
12
+ @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
13
+
14
+ @wallet = @settings.fetch(:wallet) do
15
+ raise Peatio::Wallet::MissingSettingError, :wallet
16
+ end.slice(:uri, :address)
17
+
18
+ @currency = @settings.fetch(:currency) do
19
+ raise Peatio::Wallet::MissingSettingError, :currency
20
+ end.slice(:id, :base_factor, :options)
21
+ end
22
+
23
+ def create_address!(_options = {})
24
+ { address: client.json_rpc(:getnewaddress) }
25
+ rescue Nexbit::Client::Error => e
26
+ raise Peatio::Wallet::ClientError, e
27
+ end
28
+
29
+ def create_transaction!(transaction, options = {})
30
+ txid = client.json_rpc(:sendtoaddress,
31
+ [
32
+ transaction.to_address,
33
+ transaction.amount,
34
+ '',
35
+ '',
36
+ options[:subtract_fee].to_s == 'true' # subtract fee from transaction amount.
37
+ ])
38
+ transaction.hash = txid
39
+ transaction
40
+ rescue Nexbit::Client::Error => e
41
+ raise Peatio::Wallet::ClientError, e
42
+ end
43
+
44
+ def load_balance!
45
+ client.json_rpc(:getbalance).to_d
46
+
47
+ rescue Nexbit::Client::Error => e
48
+ raise Peatio::Wallet::ClientError, e
49
+ end
50
+
51
+ private
52
+
53
+ def client
54
+ uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
55
+ @client ||= Client.new(uri, idle_timeout: 1)
58
56
  end
59
57
  end
60
58
  end
@@ -16,6 +16,17 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  # Specify which files should be added to the gem when it is released.
18
18
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ if spec.respond_to?(:metadata)
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/ndexnetwork/peatio-ndex"
23
+ spec.metadata["changelog_uri"] = "https://github.com/ndexnetwork/peatio-ndex/blob/master/CHANGELOG.md"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
30
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
31
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
32
  end
@@ -27,9 +38,9 @@ Gem::Specification.new do |spec|
27
38
  spec.add_dependency "better-faraday", "~> 1.0.5"
28
39
  spec.add_dependency "faraday", "~> 0.15.4"
29
40
  spec.add_dependency "memoist", "~> 0.16.0"
30
- spec.add_dependency "peatio", "~> 0.6.1"
41
+ spec.add_dependency "peatio", "~> 0.6.3"
31
42
 
32
- spec.add_development_dependency "bundler", "~> 1.16"
43
+ spec.add_development_dependency "bundler", "~> 1.17"
33
44
  spec.add_development_dependency "mocha", "~> 1.8"
34
45
  spec.add_development_dependency "pry-byebug"
35
46
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peatio-nexbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - BitBD
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-11 00:00:00.000000000 Z
11
+ date: 2020-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -72,28 +72,28 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.6.1
75
+ version: 0.6.3
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.6.1
82
+ version: 0.6.3
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.16'
89
+ version: '1.17'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.16'
96
+ version: '1.17'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: mocha
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -198,7 +198,10 @@ files:
198
198
  homepage: https://nexbit.io/
199
199
  licenses:
200
200
  - MIT
201
- metadata: {}
201
+ metadata:
202
+ homepage_uri: https://nexbit.io/
203
+ source_code_uri: https://github.com/ndexnetwork/peatio-ndex
204
+ changelog_uri: https://github.com/ndexnetwork/peatio-ndex/blob/master/CHANGELOG.md
202
205
  post_install_message:
203
206
  rdoc_options: []
204
207
  require_paths: