peatio-litecoin-jruby 2.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ad51c66078a49a41d057f0f2ce36523b1f6ccc84e3c48d2e716c567feebe0f8c
4
+ data.tar.gz: 52e8688ae6f10a699a51d5c26adb923d22cb1a9194d23dbbe3c403d0c0412ce5
5
+ SHA512:
6
+ metadata.gz: 532fb5739f80a6d55f0f8ad9fcda22be28649be73a5440c21ca0051c8bb073b54ffae3bfa86337cc8d4b151fb378bdc1eb7f1b38a343119a04e78f220560d20b
7
+ data.tar.gz: f7af707fb87f4b527bf56adb2dfd5c0ecadcf4264068e4c6c7bab7b0cf06c348f49e2c54f1d2ec64bb2f701ed1b2d39e33e28aa57e4c046eeb4c846b07e05ff1
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,8 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ - 2.6.2
8
+ before_install: gem install bundler -v 1.16.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in peatio-litecoin.gemspec
6
+ gemspec
@@ -0,0 +1,160 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ peatio-litecoin-jruby (2.5.4)
5
+ activesupport (~> 5.2.3)
6
+ better-faraday (~> 1.0.5)
7
+ faraday (~> 0.17)
8
+ memoist (~> 0.16.0)
9
+ net-http-persistent (~> 3.0.1)
10
+ peatio-jruby (>= 2.6.0)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ activemodel (5.2.4.4)
16
+ activesupport (= 5.2.4.4)
17
+ activerecord (5.2.4.4)
18
+ activemodel (= 5.2.4.4)
19
+ activesupport (= 5.2.4.4)
20
+ arel (>= 9.0)
21
+ activerecord-jdbc-adapter (50.0)
22
+ activerecord (>= 2.2)
23
+ activerecord-jdbcmysql-adapter (50.0)
24
+ activerecord-jdbc-adapter (~> 50.0)
25
+ jdbc-mysql (~> 5.1.36)
26
+ activesupport (5.2.4.4)
27
+ concurrent-ruby (~> 1.0, >= 1.0.2)
28
+ i18n (>= 0.7, < 2)
29
+ minitest (~> 5.1)
30
+ tzinfo (~> 1.1)
31
+ addressable (2.7.0)
32
+ public_suffix (>= 2.0.2, < 5.0)
33
+ amq-protocol (2.3.2)
34
+ amqp (1.8.0)
35
+ amq-protocol (>= 2.2.0)
36
+ eventmachine
37
+ arel (9.0.0)
38
+ better-faraday (1.0.8)
39
+ activesupport (>= 4.0, < 6.0)
40
+ faraday (~> 0.12)
41
+ bunny (2.17.0)
42
+ amq-protocol (~> 2.3, >= 2.3.1)
43
+ clamp (1.3.2)
44
+ concurrent-ruby (1.1.8)
45
+ connection_pool (2.2.3)
46
+ cookiejar (0.3.3)
47
+ crack (0.4.3)
48
+ safe_yaml (~> 1.0.0)
49
+ diff-lcs (1.3)
50
+ em-http-request (1.1.7)
51
+ addressable (>= 2.3.4)
52
+ cookiejar (!= 0.3.1)
53
+ em-socksify (>= 0.3)
54
+ eventmachine (>= 1.0.3)
55
+ http_parser.rb (>= 0.6.0)
56
+ em-socksify (0.3.2)
57
+ eventmachine (>= 1.0.0.beta.4)
58
+ em-synchrony (1.0.6)
59
+ eventmachine (>= 1.0.0.beta.1)
60
+ em-websocket (0.5.2)
61
+ eventmachine (>= 0.12.9)
62
+ http_parser.rb (~> 0.6.0)
63
+ eventmachine (1.2.7)
64
+ eventmachine (1.2.7-java)
65
+ faraday (0.17.3)
66
+ multipart-post (>= 1.2, < 3)
67
+ faraday_middleware (0.13.1)
68
+ faraday (>= 0.7.4, < 1.0)
69
+ faye (1.4.0)
70
+ cookiejar (>= 0.3.0)
71
+ em-http-request (>= 1.1.6)
72
+ eventmachine (>= 0.12.0)
73
+ faye-websocket (>= 0.11.0)
74
+ multi_json (>= 1.0.0)
75
+ rack (>= 1.0.0)
76
+ websocket-driver (>= 0.5.1)
77
+ faye-websocket (0.11.0)
78
+ eventmachine (>= 0.12.0)
79
+ websocket-driver (>= 0.5.1)
80
+ hashdiff (1.0.1)
81
+ http_parser.rb (0.6.0)
82
+ http_parser.rb (0.6.0-java)
83
+ i18n (1.8.7)
84
+ concurrent-ruby (~> 1.0)
85
+ jdbc-mysql (5.1.47)
86
+ jruby-rack (1.1.21)
87
+ jwt (2.2.2)
88
+ memoist (0.16.2)
89
+ minitest (5.14.3)
90
+ mocha (1.11.2)
91
+ multi_json (1.15.0)
92
+ multipart-post (2.1.1)
93
+ net-http-persistent (3.0.1)
94
+ connection_pool (~> 2.2)
95
+ peatio-jruby (2.6.2)
96
+ activemodel (> 5.2, <= 6.0.0)
97
+ activerecord-jdbc-adapter
98
+ activerecord-jdbcmysql-adapter
99
+ amqp
100
+ bunny
101
+ clamp
102
+ em-synchrony (~> 1.0)
103
+ em-websocket
104
+ eventmachine
105
+ faraday_middleware (~> 0.13.1)
106
+ faye (~> 1.2)
107
+ jdbc-mysql
108
+ jwt
109
+ prometheus-client
110
+ trinidad
111
+ prometheus-client (2.1.0)
112
+ public_suffix (4.0.4)
113
+ rack (2.2.3)
114
+ rake (13.0.1)
115
+ rspec (3.9.0)
116
+ rspec-core (~> 3.9.0)
117
+ rspec-expectations (~> 3.9.0)
118
+ rspec-mocks (~> 3.9.0)
119
+ rspec-core (3.9.1)
120
+ rspec-support (~> 3.9.1)
121
+ rspec-expectations (3.9.1)
122
+ diff-lcs (>= 1.2.0, < 2.0)
123
+ rspec-support (~> 3.9.0)
124
+ rspec-mocks (3.9.1)
125
+ diff-lcs (>= 1.2.0, < 2.0)
126
+ rspec-support (~> 3.9.0)
127
+ rspec-support (3.9.2)
128
+ safe_yaml (1.0.5)
129
+ thread_safe (0.3.6)
130
+ thread_safe (0.3.6-java)
131
+ trinidad (1.4.6)
132
+ jruby-rack (~> 1.1.13)
133
+ trinidad_jars (>= 1.3.0, < 1.5.0)
134
+ trinidad_jars (1.4.2)
135
+ tzinfo (1.2.9)
136
+ thread_safe (~> 0.1)
137
+ webmock (3.8.3)
138
+ addressable (>= 2.3.6)
139
+ crack (>= 0.3.2)
140
+ hashdiff (>= 0.4.0, < 2.0.0)
141
+ websocket-driver (0.7.3)
142
+ websocket-extensions (>= 0.1.0)
143
+ websocket-driver (0.7.3-java)
144
+ websocket-extensions (>= 0.1.0)
145
+ websocket-extensions (0.1.5)
146
+
147
+ PLATFORMS
148
+ java
149
+ ruby
150
+
151
+ DEPENDENCIES
152
+ bundler (~> 1.16)
153
+ mocha (~> 1.8)
154
+ peatio-litecoin-jruby!
155
+ rake (~> 13.0)
156
+ rspec (~> 3.0)
157
+ webmock (~> 3.5)
158
+
159
+ BUNDLED WITH
160
+ 1.17.3
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Yaroslav Savchuk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,67 @@
1
+ # Peatio::Litecoin
2
+
3
+ Peatio litecoin plugin for Rubykube stack
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'peatio-litecoin'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install peatio-litecoin
20
+
21
+ ## Usage
22
+
23
+ For Peatio Litecoin plugin integration you need to do the following steps:
24
+
25
+ ### Image Build.
26
+
27
+ 1. Add peatio-litecoin gem into your Gemfile.plugin
28
+ ```ruby
29
+ gem 'peatio-litecoin', '~> 0.2.0'
30
+ ```
31
+
32
+ 2. Run `bundle install` for updating Gemfile.lock
33
+
34
+ 3. Build custom Peatio [docker image with Litecoin plugin](https://github.com/rubykube/peatio/blob/master/docs/plugins.md#build)
35
+
36
+ 4. Push your image using `docker push`
37
+
38
+ 5. Update your deployment to use image with peatio-litecoin gem
39
+
40
+ ### Peatio Configuration.
41
+
42
+ 1. Create Litecoin Blockchain [config example](../config/blockchains.yml).
43
+ * No additional steps are needed
44
+
45
+ 2. Create Litecoin Currency [config example](../config/currencies.yml).
46
+ * No additional steps are needed
47
+
48
+ 3. Create Litecoin Wallets [config example](../config/wallets.yml)(deposit and hot wallets are required).
49
+ * No additional steps are needed
50
+
51
+
52
+ ## Development
53
+
54
+ Plugin development [example](https://github.com/rubykube/peatio/blob/master/docs/coins/development.md).
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rubykube/peatio-litecoin.
59
+
60
+ ## License
61
+
62
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
63
+
64
+ ## Consulting
65
+
66
+ You can contact Openware for finding certified vendors:
67
+ [Openware.com](https://www.openware.com)
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "peatio/litecoin"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ - key: ltc-testnet
2
+ name: Litecoin Testnet
3
+ client: litecoin # API client name.
4
+ server: http://user:password@127.0.0.1:18332 # Public Litecoin node endpoint.
5
+ height: 1087160 # Initial block number from which sync will be started.
6
+ min_confirmations: 6 # Minimal confirmations needed for withdraw and deposit confirmation.
7
+ explorer:
8
+ address: https://chain.so/address/LTCTEST/#{address}
9
+ transaction: https://chain.so/tx/LTCTEST/#{txid}
10
+ status: active
@@ -0,0 +1,18 @@
1
+ - id: ltc
2
+ name: Litecoin
3
+ blockchain_key: ltc-testnet
4
+ symbol: 'Ł'
5
+ type: coin
6
+ precision: 8
7
+ base_factor: 100_000_000
8
+ enabled: true
9
+ # Deposits with less amount are skipped during blockchain synchronization.
10
+ # We advise to set value 10 times bigger than the network fee to prevent losses.
11
+ min_deposit_amount: 0.0004488
12
+ min_collection_amount: 0.0004488
13
+ withdraw_limit_24h: 0.5
14
+ withdraw_limit_72h: 1.2
15
+ deposit_fee: 0
16
+ withdraw_fee: 0
17
+ position: 5
18
+ options: {}
@@ -0,0 +1,44 @@
1
+ - name: Litecoin Deposit Wallet
2
+ blockchain_key: ltc-testnet
3
+ currency_id: ltc
4
+ # Address where deposits will be collected to.
5
+ address: 'Qc2BM7gp8mKgJPPxLAadLAHteNQwhFwwuf' # IMPORTANT: Always wrap this value in quotes!
6
+ kind: deposit # Wallet kind (deposit, hot, warm, cold or fee).
7
+ nsig: 1 # Number of signatures required for performing withdraw.
8
+ max_balance: 0.0
9
+ status: active
10
+ gateway: litecoind # Gateway client name.
11
+ settings:
12
+ #
13
+ # Litecoind gateway client settings.
14
+ uri: http://user:password@127.0.0.1:19332
15
+
16
+ - name: Litecoin Hot Wallet
17
+ blockchain_key: ltc-testnet
18
+ currency_id: ltc
19
+ # Address where deposits will be collected to.
20
+ address: 'Qc2BM7gp8mKgJPPxLAadLAHteNQwhFwwuf' # IMPORTANT: Always wrap this value in quotes!
21
+ kind: hot # Wallet kind (deposit, hot, warm, cold or fee).
22
+ nsig: 1 # Number of signatures required for performing withdraw.
23
+ max_balance: 5.0
24
+ status: active
25
+ gateway: litecoind # Gateway client name.
26
+ settings:
27
+ #
28
+ # Litecoind gateway client settings.
29
+ uri: http://user:password@127.0.0.1:19332
30
+
31
+ - name: Litecoin Warm Wallet
32
+ blockchain_key: ltc-testnet
33
+ currency_id: ltc
34
+ # Address where deposits will be collected to.
35
+ address: 'Qc2BM7gp8mKgJPPxLAadLAHteNQwhFwwuf' # IMPORTANT: Always wrap this value in quotes!
36
+ kind: warm # Wallet kind (deposit, hot, warm, cold or fee).
37
+ nsig: 1 # Number of signatures required for performing withdraw.
38
+ max_balance: 50.0
39
+ status: active
40
+ gateway: litecoind # Gateway client name.
41
+ settings:
42
+ #
43
+ # Litecoind gateway client settings.
44
+ uri: http://user:password@127.0.0.1:19332
@@ -0,0 +1,29 @@
1
+ # Integration.
2
+
3
+ For Peatio Litecoin plugin integration you need to do the following steps:
4
+
5
+ ## Image Build.
6
+
7
+ 1. Add peatio-litecoin gem into your Gemfile.plugin
8
+ ```ruby
9
+ gem 'peatio-litecoin', '~> 0.1.0'
10
+ ```
11
+
12
+ 2. Run `bundle install` for updating Gemfile.lock
13
+
14
+ 3. Build custom Peatio [docker image with Litecoin plugin](https://github.com/rubykube/peatio/blob/master/docs/plugins.md#build)
15
+
16
+ 4. Push your image using `docker push`
17
+
18
+ 5. Update your deployment to use image with peatio-litecoin gem
19
+
20
+ ## Peatio Configuration.
21
+
22
+ 1. Create Litecoin Blockchain [config example](../config/blockchains.yml).
23
+ * No additional steps are needed
24
+
25
+ 2. Create Litecoin Currency [config example](../config/currencies.yml).
26
+ * No additional steps are needed
27
+
28
+ 3. Create Litecoin Wallets [config example](../config/wallets.yml)(deposit and hot wallets are required).
29
+ * No additional steps are needed
@@ -0,0 +1,29 @@
1
+ # JSON RPC
2
+
3
+ The next list of JSON RPC calls where used for plugin development.
4
+ For response examples see spec/resources:
5
+
6
+ * getbalance
7
+
8
+ `curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getbalance", "params": [] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332`
9
+ * getblock
10
+
11
+ `curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblock", "params": ["5a471d4fd13d8bc3351e4d3a618fa55993326014b925346d8e9272e271e97c4e", 2] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332`
12
+ * getblockcount
13
+
14
+ `curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockcount", "params": [] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332`
15
+ * getblockhash
16
+
17
+ `curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockhash", "params": [40500] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332 `
18
+ * getnewaddress
19
+
20
+ `curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getnewaddress", "params": [] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332 `
21
+ * listaddressgroupings
22
+
23
+ `curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listaddressgroupings", "params": [] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332`
24
+ * sendtoaddress
25
+
26
+ `curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "sendtoaddress", "params": ["QRnrwkUBQ2E4ZJ3bj8jvn4Nwx4nJ2U7wXF", 0.11] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332`
27
+ * methodnotfound
28
+
29
+ `curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "methodnotfound", "params": [] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332`
@@ -0,0 +1,6 @@
1
+ # Getting Litecoin in testnet.
2
+
3
+ You could use one of the next faucet:
4
+
5
+ * [thonguyen.net](https://faucet.thonguyen.net/ltc)
6
+ * [litecointools.com](http://testnet.litecointools.com/)
@@ -0,0 +1,18 @@
1
+ require "active_support/core_ext/object/blank"
2
+ require "active_support/core_ext/enumerable"
3
+ require "peatio"
4
+
5
+ module Peatio
6
+ module Litecoin
7
+ require "bigdecimal"
8
+ require "bigdecimal/util"
9
+
10
+ require "peatio/litecoin/blockchain"
11
+ require "peatio/litecoin/client"
12
+ require "peatio/litecoin/wallet"
13
+
14
+ require "peatio/litecoin/hooks"
15
+
16
+ require "peatio/litecoin/version"
17
+ end
18
+ end
@@ -0,0 +1,96 @@
1
+
2
+ module Peatio
3
+ module Litecoin
4
+ # TODO: Processing of unconfirmed transactions from mempool isn't supported now.
5
+ class Blockchain < Peatio::Blockchain::Abstract
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
13
+
14
+ def configure(settings = {})
15
+ # Clean client state during configure.
16
+ @client = nil
17
+ @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
18
+ end
19
+
20
+ def fetch_block!(block_number)
21
+ block_hash = client.json_rpc(:getblockhash, [block_number])
22
+
23
+ client.json_rpc(:getblock, [block_hash, 2])
24
+ .fetch('tx').each_with_object([]) do |tx, txs_array|
25
+ txs = build_transaction(tx).map do |ntx|
26
+ Peatio::Transaction.new(ntx.merge(block_number: block_number))
27
+ end
28
+ txs_array.append(*txs)
29
+ 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
33
+
34
+ def latest_block_number
35
+ client.json_rpc(:getblockcount)
36
+ rescue Client::Error => e
37
+ raise Peatio::Blockchain::ClientError, e
38
+ end
39
+
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 }
44
+
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
52
+ end
53
+
54
+ def transaction_sources(transaction)
55
+ transaction_hash = client.json_rpc(:getrawtransaction, [transaction.hash, 1])
56
+ transaction_hash['vin'].each_with_object([]) do |vin, source_addresses|
57
+ next if vin['txid'].blank?
58
+
59
+ vin_transaction = client.json_rpc(:getrawtransaction, [vin['txid'], 1])
60
+ source = vin_transaction['vout'].find { |hash| hash['n'] == vin['vout'] }
61
+ source_addresses << source['scriptPubKey']['addresses'][0]
62
+ end.compact.uniq
63
+ end
64
+
65
+ private
66
+
67
+ def build_transaction(tx_hash)
68
+ tx_hash.fetch('vout')
69
+ .select do |entry|
70
+ entry.fetch('value').to_d > 0 &&
71
+ entry['scriptPubKey'].has_key?('addresses')
72
+ end
73
+ .each_with_object([]) do |entry, formatted_txs|
74
+ no_currency_tx =
75
+ { hash: tx_hash['txid'], txout: entry['n'],
76
+ to_address: entry['scriptPubKey']['addresses'][0],
77
+ amount: entry.fetch('value').to_d,
78
+ status: 'success' }
79
+
80
+ # Build transaction for each currency belonging to blockchain.
81
+ settings_fetch(:currencies).pluck(:id).each do |currency_id|
82
+ formatted_txs << no_currency_tx.merge(currency_id: currency_id)
83
+ end
84
+ end
85
+ end
86
+
87
+ def client
88
+ @client ||= Client.new(settings_fetch(:server))
89
+ end
90
+
91
+ def settings_fetch(key)
92
+ @settings.fetch(key) { raise Peatio::Blockchain::MissingSettingError, key.to_s }
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,65 @@
1
+ require 'memoist'
2
+ require 'faraday'
3
+ require 'better-faraday'
4
+
5
+ module Peatio
6
+ module Litecoin
7
+ class Client
8
+ Error = Class.new(StandardError)
9
+ class ConnectionError < Error; end
10
+
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
20
+ end
21
+
22
+ extend Memoist
23
+
24
+ def initialize(endpoint)
25
+ @json_rpc_endpoint = URI.parse(endpoint)
26
+ end
27
+
28
+ def json_rpc(method, params = [])
29
+ response = post(method, params)
30
+
31
+ response.assert_2xx!
32
+ response = JSON.parse(response.body)
33
+ response['error'].tap { |e| raise ResponseError.new(e['code'], e['message']) if e }
34
+ response.fetch('result')
35
+ rescue => e
36
+ if e.is_a?(Error)
37
+ raise e
38
+ elsif e.is_a?(Faraday::Error)
39
+ raise ConnectionError, e
40
+ else
41
+ raise Error, e
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def post(method, params)
48
+ connection.post("/", {jsonrpc: "1.0", method: method, params: params}.to_json,
49
+ "Accept" => "application/json", "Content-Type" => "application/json")
50
+ end
51
+
52
+ def connection
53
+ @connection ||= Faraday.new(@json_rpc_endpoint) do |f|
54
+ f.adapter :net_http_persistent, pool_size: 5
55
+ end.tap do |connection|
56
+ unless @json_rpc_endpoint.user.blank?
57
+ connection.basic_auth(@json_rpc_endpoint.user,
58
+ @json_rpc_endpoint.password)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+
@@ -0,0 +1,42 @@
1
+ module Peatio
2
+ module Litecoin
3
+ module Hooks
4
+ BLOCKCHAIN_VERSION_REQUIREMENT = "~> 1.0.0"
5
+ WALLET_VERSION_REQUIREMENT = "~> 1.0.0"
6
+
7
+ class << self
8
+ def check_compatibility
9
+ unless Gem::Requirement.new(BLOCKCHAIN_VERSION_REQUIREMENT)
10
+ .satisfied_by?(Gem::Version.new(Peatio::Blockchain::VERSION))
11
+ [
12
+ "Litecoin blockchain version requiremnt was not suttisfied by Peatio::Blockchain.",
13
+ "Litecoin blockchain requires #{BLOCKCHAIN_VERSION_REQUIREMENT}.",
14
+ "Peatio::Blockchain version is #{Peatio::Blockchain::VERSION}"
15
+ ].join('\n').tap { |s| Kernel.abort s }
16
+ end
17
+
18
+ unless Gem::Requirement.new(WALLET_VERSION_REQUIREMENT)
19
+ .satisfied_by?(Gem::Version.new(Peatio::Wallet::VERSION))
20
+ [
21
+ "Litecoin wallet version requiremnt was not suttisfied by Peatio::Wallet.",
22
+ "Litecoin wallet requires #{WALLET_VERSION_REQUIREMENT}.",
23
+ "Peatio::Wallet version is #{Peatio::Wallet::VERSION}"
24
+ ].join('\n').tap { |s| Kernel.abort s }
25
+ end
26
+ end
27
+
28
+ def register
29
+ Peatio::Blockchain.registry[:litecoin] = Litecoin::Blockchain
30
+ Peatio::Wallet.registry[:litecoind] = Litecoin::Wallet
31
+ end
32
+ end
33
+
34
+ if defined?(Rails::Railtie)
35
+ require "peatio/litecoin/railtie"
36
+ else
37
+ check_compatibility
38
+ register
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,13 @@
1
+ module Peatio
2
+ module Litecoin
3
+ class Railtie < Rails::Railtie
4
+ config.before_initialize do
5
+ Hooks.check_compatibility
6
+ end
7
+
8
+ config.after_initialize do
9
+ Hooks.register
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Peatio
2
+ module Litecoin
3
+ VERSION = "2.5.4".freeze
4
+ end
5
+ end
@@ -0,0 +1,60 @@
1
+ module Peatio
2
+ module Litecoin
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 Litecoin::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 Litecoin::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 Litecoin::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
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "peatio/litecoin/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "peatio-litecoin-jruby"
8
+ spec.version = Peatio::Litecoin::VERSION
9
+ spec.authors = ["Yaroslav S."]
10
+ spec.email = ["ysavchuk@heliostech.fr"]
11
+
12
+ spec.summary = %q{Gem for extending Peatio plugable system with Litecoin implementation.}
13
+ spec.description = %q{Litecoin Peatio gem which implements Peatio::Blockchain::Abstract & Peatio::Wallet::Abstract.}
14
+ spec.homepage = "https://openware.com/"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "activesupport", "~> 5.2.3"
27
+ spec.add_dependency "better-faraday", "~> 1.0.5"
28
+ spec.add_dependency "faraday", "~> 0.17"
29
+ spec.add_dependency "memoist", "~> 0.16.0"
30
+ spec.add_dependency "peatio-jruby", ">= 2.6.0"
31
+ spec.add_dependency 'net-http-persistent', '~> 3.0.1'
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "mocha", "~> 1.8"
35
+ # spec.add_development_dependency "pry-byebug"
36
+ spec.add_development_dependency "rake", "~> 13.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_development_dependency "webmock", "~> 3.5"
39
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peatio-litecoin-jruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.5.4
5
+ platform: ruby
6
+ authors:
7
+ - Yaroslav S.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 5.2.3
19
+ name: activesupport
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.3
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.5
33
+ name: better-faraday
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.5
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.17'
47
+ name: faraday
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.17'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.16.0
61
+ name: memoist
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.16.0
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.6.0
75
+ name: peatio-jruby
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.6.0
83
+ - !ruby/object:Gem::Dependency
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 3.0.1
89
+ name: net-http-persistent
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.1
97
+ - !ruby/object:Gem::Dependency
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.16'
103
+ name: bundler
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.16'
111
+ - !ruby/object:Gem::Dependency
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '1.8'
117
+ name: mocha
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.8'
125
+ - !ruby/object:Gem::Dependency
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '13.0'
131
+ name: rake
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '13.0'
139
+ - !ruby/object:Gem::Dependency
140
+ requirement: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '3.0'
145
+ name: rspec
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3.0'
153
+ - !ruby/object:Gem::Dependency
154
+ requirement: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '3.5'
159
+ name: webmock
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.5'
167
+ description: Litecoin Peatio gem which implements Peatio::Blockchain::Abstract & Peatio::Wallet::Abstract.
168
+ email:
169
+ - ysavchuk@heliostech.fr
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".travis.yml"
177
+ - Gemfile
178
+ - Gemfile.lock
179
+ - LICENSE.txt
180
+ - README.md
181
+ - Rakefile
182
+ - bin/console
183
+ - bin/setup
184
+ - config/blockchains.yml
185
+ - config/currencies.yml
186
+ - config/wallets.yml
187
+ - docs/integration.md
188
+ - docs/json-rpc.md
189
+ - docs/testnet.md
190
+ - lib/peatio/litecoin.rb
191
+ - lib/peatio/litecoin/blockchain.rb
192
+ - lib/peatio/litecoin/client.rb
193
+ - lib/peatio/litecoin/hooks.rb
194
+ - lib/peatio/litecoin/railtie.rb
195
+ - lib/peatio/litecoin/version.rb
196
+ - lib/peatio/litecoin/wallet.rb
197
+ - peatio-litecoin.gemspec
198
+ homepage: https://openware.com/
199
+ licenses:
200
+ - MIT
201
+ metadata: {}
202
+ post_install_message:
203
+ rdoc_options: []
204
+ require_paths:
205
+ - lib
206
+ required_ruby_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ requirements: []
217
+ rubygems_version: 3.0.6
218
+ signing_key:
219
+ specification_version: 4
220
+ summary: Gem for extending Peatio plugable system with Litecoin implementation.
221
+ test_files: []