peatio-thought 2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1add76b96637690473fdf4854d17c6b2d32f2c6f6687f9388969ba52d10c68b4
4
+ data.tar.gz: 7879b55634d80b26f28dbed9d0a5afd44e1f73b939b423da2f53b1f2288d9c24
5
+ SHA512:
6
+ metadata.gz: 9c1ae5f26117fe38958458570c23e11fb2ea75b8268f22f7dd4da2af90f5ebbf389e34a8b8fcffd5a96e4690f34cf5ab2248539f04bfbd2d71e3de6aa2835685
7
+ data.tar.gz: f6f01b1940b719f450bfd634cf4dbcc87f777872c38c006f23b599cf371f3f4480b3ca450560d2d1c50706eca23da1803edbc77d662235956d0a9e8c5be5ecf3
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in peatio-thought.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,145 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ peatio-thought (2.4.0)
5
+ activesupport (~> 5.2.3)
6
+ better-faraday (~> 1.0.5)
7
+ faraday (~> 0.15.4)
8
+ memoist (~> 0.16.0)
9
+ net-http-persistent (~> 3.0.1)
10
+ peatio (>= 0.6.3)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ activemodel (5.2.3)
16
+ activesupport (= 5.2.3)
17
+ activesupport (5.2.3)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (>= 0.7, < 2)
20
+ minitest (~> 5.1)
21
+ tzinfo (~> 1.1)
22
+ addressable (2.7.0)
23
+ public_suffix (>= 2.0.2, < 5.0)
24
+ amq-protocol (2.3.0)
25
+ amqp (1.8.0)
26
+ amq-protocol (>= 2.2.0)
27
+ eventmachine
28
+ ast (2.4.0)
29
+ better-faraday (1.0.8)
30
+ activesupport (>= 4.0, < 6.0)
31
+ faraday (~> 0.12)
32
+ bunny (2.14.3)
33
+ amq-protocol (~> 2.3, >= 2.3.0)
34
+ byebug (11.0.1)
35
+ clamp (1.3.1)
36
+ coderay (1.1.2)
37
+ concurrent-ruby (1.1.5)
38
+ connection_pool (2.2.2)
39
+ crack (0.4.3)
40
+ safe_yaml (~> 1.0.0)
41
+ diff-lcs (1.3)
42
+ docile (1.3.2)
43
+ em-websocket (0.5.1)
44
+ eventmachine (>= 0.12.9)
45
+ http_parser.rb (~> 0.6.0)
46
+ eventmachine (1.2.7)
47
+ faraday (0.15.4)
48
+ multipart-post (>= 1.2, < 3)
49
+ hashdiff (1.0.0)
50
+ http_parser.rb (0.6.0)
51
+ i18n (1.7.0)
52
+ concurrent-ruby (~> 1.0)
53
+ irb (1.0.0)
54
+ jaro_winkler (1.5.4)
55
+ json (2.2.0)
56
+ jwt (2.2.1)
57
+ memoist (0.16.1)
58
+ metaclass (0.0.4)
59
+ method_source (0.9.2)
60
+ minitest (5.13.0)
61
+ mocha (1.9.0)
62
+ metaclass (~> 0.0.1)
63
+ multipart-post (2.1.1)
64
+ mysql2 (0.5.2)
65
+ net-http-persistent (3.0.1)
66
+ connection_pool (~> 2.2)
67
+ parallel (1.19.0)
68
+ parser (2.6.5.0)
69
+ ast (~> 2.4.0)
70
+ peatio (0.6.3)
71
+ activemodel (> 5.2, <= 6.0.0)
72
+ amqp
73
+ bunny
74
+ clamp
75
+ em-websocket
76
+ eventmachine
77
+ jwt
78
+ mysql2
79
+ pry (0.12.2)
80
+ coderay (~> 1.1.0)
81
+ method_source (~> 0.9.0)
82
+ pry-byebug (3.7.0)
83
+ byebug (~> 11.0)
84
+ pry (~> 0.10)
85
+ public_suffix (4.0.1)
86
+ rainbow (3.0.0)
87
+ rake (10.5.0)
88
+ rspec (3.9.0)
89
+ rspec-core (~> 3.9.0)
90
+ rspec-expectations (~> 3.9.0)
91
+ rspec-mocks (~> 3.9.0)
92
+ rspec-core (3.9.0)
93
+ rspec-support (~> 3.9.0)
94
+ rspec-expectations (3.9.0)
95
+ diff-lcs (>= 1.2.0, < 2.0)
96
+ rspec-support (~> 3.9.0)
97
+ rspec-mocks (3.9.0)
98
+ diff-lcs (>= 1.2.0, < 2.0)
99
+ rspec-support (~> 3.9.0)
100
+ rspec-support (3.9.0)
101
+ rubocop (0.76.0)
102
+ jaro_winkler (~> 1.5.1)
103
+ parallel (~> 1.10)
104
+ parser (>= 2.6)
105
+ rainbow (>= 2.2.2, < 4.0)
106
+ ruby-progressbar (~> 1.7)
107
+ unicode-display_width (>= 1.4.0, < 1.7)
108
+ rubocop-github (0.13.0)
109
+ rubocop (~> 0.70)
110
+ rubocop-performance (~> 1.3.0)
111
+ rubocop-performance (1.3.0)
112
+ rubocop (>= 0.68.0)
113
+ ruby-progressbar (1.10.1)
114
+ safe_yaml (1.0.5)
115
+ simplecov (0.17.1)
116
+ docile (~> 1.1)
117
+ json (>= 1.8, < 3)
118
+ simplecov-html (~> 0.10.0)
119
+ simplecov-html (0.10.2)
120
+ thread_safe (0.3.6)
121
+ tzinfo (1.2.5)
122
+ thread_safe (~> 0.1)
123
+ unicode-display_width (1.6.0)
124
+ webmock (3.7.6)
125
+ addressable (>= 2.3.6)
126
+ crack (>= 0.3.2)
127
+ hashdiff (>= 0.4.0, < 2.0.0)
128
+
129
+ PLATFORMS
130
+ ruby
131
+
132
+ DEPENDENCIES
133
+ bundler (~> 1.17)
134
+ irb
135
+ mocha (~> 1.8)
136
+ peatio-thought!
137
+ pry-byebug
138
+ rake (~> 10.0)
139
+ rspec (~> 3.0)
140
+ rubocop-github
141
+ simplecov
142
+ webmock (~> 3.5)
143
+
144
+ BUNDLED WITH
145
+ 1.17.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Dinesh Chohda
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.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Peatio::Thought
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/peatio/thought`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'peatio-thought'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install peatio-thought
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/peatio-thought.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "peatio/thought"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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: tht-testnet
2
+ name: Thought Testnet
3
+ client: thought # API client name.
4
+ server: http://user:password@127.0.0.1:11617 # Public Thought 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://ext.thought.live/address/THTTEST/#{address}
9
+ transaction: https://ext.thought.live/tx/THTTEST/#{txid}
10
+ status: active
@@ -0,0 +1,18 @@
1
+ - id: tht
2
+ name: Thought
3
+ blockchain_key: tht-testnet
4
+ symbol: 'T'
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: Thought Deposit Wallet
2
+ blockchain_key: tht-testnet
3
+ currency_id: tht
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: thoughtd # Gateway client name.
11
+ settings:
12
+ #
13
+ # Thoughtd gateway client settings.
14
+ uri: http://user:password@127.0.0.1:10617
15
+
16
+ - name: Thought Hot Wallet
17
+ blockchain_key: tht-testnet
18
+ currency_id: tht
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: thoughtd # Gateway client name.
26
+ settings:
27
+ #
28
+ # Thoughtd gateway client settings.
29
+ uri: http://user:password@127.0.0.1:10617
30
+
31
+ - name: Thought Warm Wallet
32
+ blockchain_key: tht-testnet
33
+ currency_id: tht
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: thoughtd # Gateway client name.
41
+ settings:
42
+ #
43
+ # Thoughtd gateway client settings.
44
+ uri: http://user:password@127.0.0.1:10617
@@ -0,0 +1,29 @@
1
+ # Integration.
2
+
3
+ For Peatio Thought plugin integration you need to do the following steps:
4
+
5
+ ## Image Build.
6
+
7
+ 1. Add peatio-thought gem into your Gemfile.plugin
8
+ ```ruby
9
+ gem 'peatio-thought', '~> 0.1.0'
10
+ ```
11
+
12
+ 2. Run `bundle install` for updating Gemfile.lock
13
+
14
+ 3. Build custom Peatio [docker image with Thought 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-thought gem
19
+
20
+ ## Peatio Configuration.
21
+
22
+ 1. Create Thought Blockchain [config example](../config/blockchains.yml).
23
+ * No additional steps are needed
24
+
25
+ 2. Create Thought Currency [config example](../config/currencies.yml).
26
+ * No additional steps are needed
27
+
28
+ 3. Create Thought Wallets [config example](../config/wallets.yml)(deposit and hot wallets are required).
29
+ * No additional steps are needed
data/docs/json-rpc.md ADDED
@@ -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:10617`
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:10617`
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:10617`
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:10617 `
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:10617 `
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:10617`
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:10617`
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:10617`
data/docs/testnet.md ADDED
@@ -0,0 +1,6 @@
1
+ # Getting Thought in testnet.
2
+
3
+ You could use one of the next faucet:
4
+
5
+ * [thonguyen.net](https://faucet.thonguyen.net/tht)
6
+ * [thoughttools.com](http://testnet.thoughttools.com/)
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/object/blank"
4
+ require "active_support/core_ext/enumerable"
5
+ require "peatio"
6
+
7
+ module Peatio
8
+ module Thought
9
+ require "bigdecimal"
10
+ require "bigdecimal/util"
11
+
12
+ require "peatio/thought/blockchain"
13
+ require "peatio/thought/client"
14
+ require "peatio/thought/wallet"
15
+
16
+ require "peatio/thought/hooks"
17
+
18
+ require "peatio/thought/version"
19
+ end
20
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio
4
+ module Thought
5
+ # TODO: Processing of unconfirmed transactions from mempool isn't supported now.
6
+ class Blockchain < Peatio::Blockchain::Abstract
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
+ block_txs = 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
30
+
31
+ Peatio::Block.new(block_number, block_txs)
32
+ rescue Client::Error => e
33
+ raise Peatio::Blockchain::ClientError, e
34
+ end
35
+
36
+ def latest_block_number
37
+ client.json_rpc(:getblockcount)
38
+ rescue Client::Error => e
39
+ raise Peatio::Blockchain::ClientError, e
40
+ end
41
+
42
+ def load_balance_of_address!(address, _currency_id)
43
+ address_with_balance = client.json_rpc(:listaddressgroupings)
44
+ .flatten(1)
45
+ .find {|addr| addr[0] == address }
46
+
47
+ raise Peatio::Blockchain::UnavailableAddressBalanceError, address if address_with_balance.blank?
48
+
49
+ address_with_balance[1].to_d
50
+ rescue Client::Error => e
51
+ raise Peatio::Blockchain::ClientError, e
52
+ end
53
+
54
+ private
55
+
56
+ def filter_vout(tx_hash)
57
+ tx_hash.fetch("vout").select do |entry|
58
+ entry.fetch("value").to_d.positive? && entry["scriptPubKey"].has_key?("addresses")
59
+ end
60
+ end
61
+
62
+ def build_transaction(tx_hash)
63
+ filter_vout(tx_hash).each_with_object([]) do |entry, formatted_txs|
64
+ no_currency_tx = {hash: tx_hash["txid"], txout: entry["n"],
65
+ to_address: entry["scriptPubKey"]["addresses"][0],
66
+ amount: entry.fetch("value").to_d,
67
+ status: "success"}
68
+
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
73
+ end
74
+ end
75
+
76
+ def client
77
+ @client ||= Client.new(settings_fetch(:server))
78
+ end
79
+
80
+ def settings_fetch(key)
81
+ @settings.fetch(key) { raise Peatio::Blockchain::MissingSettingError, key.to_s }
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "memoist"
4
+ require "faraday"
5
+ require "better-faraday"
6
+
7
+ module Peatio
8
+ module Thought
9
+ class Client
10
+ Error = Class.new(StandardError)
11
+ class ConnectionError < Error; end
12
+
13
+ class ResponseError < Error
14
+ def initialize(code, msg)
15
+ @code = code
16
+ @msg = msg
17
+ end
18
+
19
+ def message
20
+ "#{@msg} (#{@code})"
21
+ end
22
+ end
23
+
24
+ extend Memoist
25
+
26
+ def initialize(endpoint)
27
+ @json_rpc_endpoint = URI.parse(endpoint)
28
+ end
29
+
30
+ def json_rpc(method, params=[])
31
+ response = post(method, params)
32
+
33
+ response.assert_2xx!
34
+ response = JSON.parse(response.body)
35
+
36
+ response["error"].tap do |e|
37
+ raise ResponseError.new(e["code"], e["message"]) if e
38
+ end
39
+
40
+ response.fetch("result")
41
+ rescue StandardError => e
42
+ case e
43
+ when Faraday::Error
44
+ raise ConnectionError, e
45
+ when Error
46
+ raise e
47
+ else
48
+ raise Error, e
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def post(method, params)
55
+ connection.post("/", {jsonrpc: "1.0", method: method, params: params}.to_json,
56
+ "Accept" => "application/json", "Content-Type" => "application/json")
57
+ end
58
+
59
+ def connection
60
+ @connection ||= Faraday.new(@json_rpc_endpoint) do |f|
61
+ f.adapter :net_http_persistent, pool_size: 5
62
+ end.tap do |connection|
63
+ unless @json_rpc_endpoint.user.blank?
64
+ connection.basic_auth(@json_rpc_endpoint.user,
65
+ @json_rpc_endpoint.password)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio
4
+ module Thought
5
+ module Hooks
6
+ BLOCKCHAIN_VERSION_REQUIREMENT = "~> 1.0.0"
7
+ WALLET_VERSION_REQUIREMENT = "~> 1.0.0"
8
+
9
+ class << self
10
+ def check_compatibility
11
+ unless Gem::Requirement.new(BLOCKCHAIN_VERSION_REQUIREMENT)
12
+ .satisfied_by?(Gem::Version.new(Peatio::Blockchain::VERSION))
13
+ [
14
+ "Thought blockchain version requiremnt was not suttisfied by Peatio::Blockchain.",
15
+ "Thought blockchain requires #{BLOCKCHAIN_VERSION_REQUIREMENT}.",
16
+ "Peatio::Blockchain version is #{Peatio::Blockchain::VERSION}"
17
+ ].join('\n').tap {|s| Kernel.abort s }
18
+ end
19
+
20
+ unless Gem::Requirement.new(WALLET_VERSION_REQUIREMENT)
21
+ .satisfied_by?(Gem::Version.new(Peatio::Wallet::VERSION))
22
+ [
23
+ "Thought wallet version requiremnt was not suttisfied by Peatio::Wallet.",
24
+ "Thought wallet requires #{WALLET_VERSION_REQUIREMENT}.",
25
+ "Peatio::Wallet version is #{Peatio::Wallet::VERSION}"
26
+ ].join('\n').tap {|s| Kernel.abort s }
27
+ end
28
+ end
29
+
30
+ def register
31
+ Peatio::Blockchain.registry[:thought] = Thought::Blockchain.new
32
+ Peatio::Wallet.registry[:thoughtd] = Thought::Wallet.new
33
+ end
34
+ end
35
+
36
+ if defined?(Rails::Railtie)
37
+ require "peatio/thought/railtie"
38
+ else
39
+ check_compatibility
40
+ register
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio
4
+ module Thought
5
+ class Railtie < Rails::Railtie
6
+ config.before_initialize do
7
+ Hooks.check_compatibility
8
+ end
9
+
10
+ config.after_initialize do
11
+ Hooks.register
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio
4
+ module Thought
5
+ VERSION = "2.4.0"
6
+ end
7
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio
4
+ module Thought
5
+ class Wallet < Peatio::Wallet::Abstract
6
+ def initialize(settings={})
7
+ @settings = settings
8
+ end
9
+
10
+ def configure(settings={})
11
+ # Clean client state during configure.
12
+ @client = nil
13
+
14
+ @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
15
+
16
+ @wallet = @settings.fetch(:wallet) {
17
+ raise Peatio::Wallet::MissingSettingError, :wallet
18
+ }.slice(:uri, :address)
19
+
20
+ @currency = @settings.fetch(:currency) {
21
+ raise Peatio::Wallet::MissingSettingError, :currency
22
+ }.slice(:id, :base_factor, :options)
23
+ end
24
+
25
+ def create_address!(_options={})
26
+ {address: client.json_rpc(:getnewaddress)}
27
+ rescue Thought::Client::Error => e
28
+ raise Peatio::Wallet::ClientError, e
29
+ end
30
+
31
+ def create_transaction!(transaction, options={})
32
+ txid = client.json_rpc(:sendtoaddress,
33
+ [
34
+ transaction.to_address,
35
+ transaction.amount,
36
+ "",
37
+ "",
38
+ options[:subtract_fee].to_s == "true" # subtract fee from transaction amount.
39
+ ])
40
+ transaction.hash = txid
41
+ transaction
42
+ rescue Thought::Client::Error => e
43
+ raise Peatio::Wallet::ClientError, e
44
+ end
45
+
46
+ def load_balance!
47
+ client.json_rpc(:getbalance).to_d
48
+ rescue Thought::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,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "peatio/thought/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "peatio-thought"
9
+ spec.version = Peatio::Thought::VERSION
10
+ spec.authors = ["Andrew@Thought"]
11
+ spec.email = ["andrew@thought.live"]
12
+
13
+ spec.summary = "Peatio Thought Blockchain Plugin"
14
+ spec.description = "Peatio Thought Blockchain Plugin for Rubykube"
15
+ spec.homepage = "https://thought.live"
16
+ spec.license = "MIT"
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/thoughtnetwork/peatio-thought"
24
+ spec.metadata["changelog_uri"] = "https://github.com/thoughtnetwork/peatio-thought/blob/master/CHANGELOG.md"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
33
+ `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_dependency "activesupport", "~> 5.2.3"
40
+ spec.add_dependency "better-faraday", "~> 1.0.5"
41
+ spec.add_dependency "faraday", "~> 0.15.4"
42
+ spec.add_dependency "memoist", "~> 0.16.0"
43
+ spec.add_dependency "peatio", ">= 0.6.3"
44
+ spec.add_dependency 'net-http-persistent', '~> 3.0.1'
45
+
46
+ spec.add_development_dependency "bundler", "~> 1.17"
47
+ spec.add_development_dependency "irb"
48
+ spec.add_development_dependency "mocha", "~> 1.8"
49
+ spec.add_development_dependency "pry-byebug"
50
+ spec.add_development_dependency "rake", "~> 10.0"
51
+ spec.add_development_dependency "rspec", "~> 3.0"
52
+ spec.add_development_dependency "rubocop-github"
53
+ spec.add_development_dependency "simplecov"
54
+ spec.add_development_dependency "webmock", "~> 3.5"
55
+ end
metadata ADDED
@@ -0,0 +1,277 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peatio-thought
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew@Thought
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.3
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
+ name: better-faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.5
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
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.15.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.15.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: memoist
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.16.0
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
+ name: peatio
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.6.3
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.6.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: net-http-persistent
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.1
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
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.17'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.17'
111
+ - !ruby/object:Gem::Dependency
112
+ name: irb
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: mocha
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.8'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.8'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry-byebug
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rake
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '10.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '10.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rspec
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '3.0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '3.0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rubocop-github
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: simplecov
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: webmock
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '3.5'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '3.5'
223
+ description: Peatio Thought Blockchain Plugin for Rubykube
224
+ email:
225
+ - andrew@thought.live
226
+ executables: []
227
+ extensions: []
228
+ extra_rdoc_files: []
229
+ files:
230
+ - Gemfile
231
+ - Gemfile.lock
232
+ - LICENSE.txt
233
+ - README.md
234
+ - Rakefile
235
+ - bin/console
236
+ - bin/setup
237
+ - config/blockchains.yml
238
+ - config/currencies.yml
239
+ - config/wallets.yml
240
+ - docs/integration.md
241
+ - docs/json-rpc.md
242
+ - docs/testnet.md
243
+ - lib/peatio/thought.rb
244
+ - lib/peatio/thought/blockchain.rb
245
+ - lib/peatio/thought/client.rb
246
+ - lib/peatio/thought/hooks.rb
247
+ - lib/peatio/thought/railtie.rb
248
+ - lib/peatio/thought/version.rb
249
+ - lib/peatio/thought/wallet.rb
250
+ - peatio-thought.gemspec
251
+ homepage: https://thought.live
252
+ licenses:
253
+ - MIT
254
+ metadata:
255
+ homepage_uri: https://thought.live
256
+ source_code_uri: https://github.com/thoughtnetwork/peatio-thought
257
+ changelog_uri: https://github.com/thoughtnetwork/peatio-thought/blob/master/CHANGELOG.md
258
+ post_install_message:
259
+ rdoc_options: []
260
+ require_paths:
261
+ - lib
262
+ required_ruby_version: !ruby/object:Gem::Requirement
263
+ requirements:
264
+ - - ">="
265
+ - !ruby/object:Gem::Version
266
+ version: '0'
267
+ required_rubygems_version: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ requirements: []
273
+ rubygems_version: 3.0.3
274
+ signing_key:
275
+ specification_version: 4
276
+ summary: Peatio Thought Blockchain Plugin
277
+ test_files: []