peatio-bitgo 1.1.0 → 1.1.1

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: 8a34d3e594f4aae64bc53a35b59dadd67910a9e3d815eee4e3dd9efa647390e4
4
- data.tar.gz: 7aa28dfabb7d3d38c6fe97d8cd33a0f925c2aab1f96b264ae8cb2e771cd6148e
3
+ metadata.gz: 77fecc938decb7012e77db67d8334287226c3a3761d0fa6f075c0e93119418d8
4
+ data.tar.gz: fb16e7373708ebdf0b08fa85580d335853f64164854cad3ea1744a09277c15b1
5
5
  SHA512:
6
- metadata.gz: 58e8eded29b3926165b4007c85034ac36f90c61bfba87b9d655cab1f14dc192e69dfe1bb1250c5e3e0a11c5e77ce43be9e4b5d7f10a34884be62a04371cbb18e
7
- data.tar.gz: 0c2910b5e815efe56c0e1e46da0bf1e2b50d48571ca5a0f2aee4b2b9d55135a18755789d59045c1ae93ccad5b40358700b49f823ace670e117d7f7129f49b626
6
+ metadata.gz: b5a7d4d96979e76c524ba8b5e67304cb497d3f911ed05873b20bbe2df94bda0bd192d7f3896e8437e86889db41844a4b56cbd04246dd71d7058dcf9be7c188c5
7
+ data.tar.gz: b86529c189d9399b28b35d493c8db850c9fc6187f50508d9df3131be329b9097fdc2431edbcc579275eda2d2f0cdef31f7455644dc7fc0d81f3ef39cb19b3382
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- peatio-bitgo (1.1.0)
4
+ peatio-bitgo (1.1.1)
5
5
  activesupport (~> 5.2.3)
6
6
  better-faraday (~> 1.0.5)
7
7
  faraday (~> 0.15.4)
@@ -12,9 +12,9 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activemodel (5.2.4.1)
16
- activesupport (= 5.2.4.1)
17
- activesupport (5.2.4.1)
15
+ activemodel (5.2.4.2)
16
+ activesupport (= 5.2.4.2)
17
+ activesupport (5.2.4.2)
18
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
19
  i18n (>= 0.7, < 2)
20
20
  minitest (~> 5.1)
@@ -35,52 +35,85 @@ GEM
35
35
  coderay (1.1.2)
36
36
  concurrent-ruby (1.1.6)
37
37
  connection_pool (2.2.2)
38
+ cookiejar (0.3.3)
38
39
  crack (0.4.3)
39
40
  safe_yaml (~> 1.0.0)
41
+ daemons (1.3.1)
40
42
  diff-lcs (1.3)
43
+ em-http-request (1.1.5)
44
+ addressable (>= 2.3.4)
45
+ cookiejar (!= 0.3.1)
46
+ em-socksify (>= 0.3)
47
+ eventmachine (>= 1.0.3)
48
+ http_parser.rb (>= 0.6.0)
49
+ em-socksify (0.3.2)
50
+ eventmachine (>= 1.0.0.beta.4)
51
+ em-synchrony (1.0.6)
52
+ eventmachine (>= 1.0.0.beta.1)
41
53
  em-websocket (0.5.1)
42
54
  eventmachine (>= 0.12.9)
43
55
  http_parser.rb (~> 0.6.0)
44
56
  eventmachine (1.2.7)
45
57
  faraday (0.15.4)
46
58
  multipart-post (>= 1.2, < 3)
59
+ faraday_middleware (0.13.1)
60
+ faraday (>= 0.7.4, < 1.0)
61
+ faye (1.2.4)
62
+ cookiejar (>= 0.3.0)
63
+ em-http-request (>= 0.3.0)
64
+ eventmachine (>= 0.12.0)
65
+ faye-websocket (>= 0.9.1)
66
+ multi_json (>= 1.0.0)
67
+ rack (>= 1.0.0)
68
+ websocket-driver (>= 0.5.1)
69
+ faye-websocket (0.10.9)
70
+ eventmachine (>= 0.12.0)
71
+ websocket-driver (>= 0.5.1)
47
72
  hashdiff (1.0.1)
48
73
  http_parser.rb (0.6.0)
49
74
  i18n (1.8.2)
50
75
  concurrent-ruby (~> 1.0)
51
76
  jwt (2.2.1)
52
77
  memoist (0.16.2)
53
- method_source (0.9.2)
78
+ method_source (1.0.0)
54
79
  minitest (5.14.0)
55
80
  mocha (1.11.2)
81
+ multi_json (1.14.1)
56
82
  multipart-post (2.1.1)
57
83
  mysql2 (0.5.3)
58
84
  net-http-persistent (3.0.1)
59
85
  connection_pool (~> 2.2)
60
- peatio (0.6.3)
86
+ peatio (2.4.3)
61
87
  activemodel (> 5.2, <= 6.0.0)
62
88
  amqp
63
89
  bunny
64
90
  clamp
91
+ em-synchrony (~> 1.0)
65
92
  em-websocket
66
93
  eventmachine
94
+ faraday_middleware (~> 0.13.1)
95
+ faye (~> 1.2)
67
96
  jwt
68
97
  mysql2
69
- pry (0.12.2)
70
- coderay (~> 1.1.0)
71
- method_source (~> 0.9.0)
72
- pry-byebug (3.8.0)
98
+ prometheus-client
99
+ thin
100
+ prometheus-client (2.0.0)
101
+ pry (0.13.0)
102
+ coderay (~> 1.1)
103
+ method_source (~> 1.0)
104
+ pry-byebug (3.9.0)
73
105
  byebug (~> 11.0)
74
- pry (~> 0.10)
106
+ pry (~> 0.13.0)
75
107
  public_suffix (4.0.3)
76
- rake (10.5.0)
108
+ rack (2.2.2)
109
+ rake (13.0.1)
77
110
  rspec (3.9.0)
78
111
  rspec-core (~> 3.9.0)
79
112
  rspec-expectations (~> 3.9.0)
80
113
  rspec-mocks (~> 3.9.0)
81
114
  rspec-core (3.9.1)
82
115
  rspec-support (~> 3.9.1)
83
- rspec-expectations (3.9.0)
116
+ rspec-expectations (3.9.1)
84
117
  diff-lcs (>= 1.2.0, < 2.0)
85
118
  rspec-support (~> 3.9.0)
86
119
  rspec-mocks (3.9.1)
@@ -88,13 +121,20 @@ GEM
88
121
  rspec-support (~> 3.9.0)
89
122
  rspec-support (3.9.2)
90
123
  safe_yaml (1.0.5)
124
+ thin (1.7.2)
125
+ daemons (~> 1.0, >= 1.0.9)
126
+ eventmachine (~> 1.0, >= 1.0.4)
127
+ rack (>= 1, < 3)
91
128
  thread_safe (0.3.6)
92
129
  tzinfo (1.2.6)
93
130
  thread_safe (~> 0.1)
94
- webmock (3.8.2)
131
+ webmock (3.8.3)
95
132
  addressable (>= 2.3.6)
96
133
  crack (>= 0.3.2)
97
134
  hashdiff (>= 0.4.0, < 2.0.0)
135
+ websocket-driver (0.7.1)
136
+ websocket-extensions (>= 0.1.0)
137
+ websocket-extensions (0.1.4)
98
138
 
99
139
  PLATFORMS
100
140
  ruby
@@ -104,7 +144,7 @@ DEPENDENCIES
104
144
  mocha (~> 1.8)
105
145
  peatio-bitgo!
106
146
  pry-byebug
107
- rake (~> 10.0)
147
+ rake (~> 13.0)
108
148
  rspec (~> 3.0)
109
149
  webmock (~> 3.5)
110
150
 
@@ -13,9 +13,9 @@
13
13
  # Geth gateway client settings.
14
14
  uri: http://127.0.0.1:8545
15
15
  secret: 'changeme'
16
- bitgo_test_net: true
17
- bitgo_access_token: 'v2x659261647b540ee3acda5c50ae4e878we323474eea5cbff9b9615139629'
18
- bitgo_wallet_id: '5e5388ad80334347ceb3540c741d'
16
+ testnet: true
17
+ access_token: 'v2x659261647b540ee3acda5c50ae4e878we323474eea5cbff9b9615139629'
18
+ wallet_id: '5e5388ad80334347ceb3540c741d'
19
19
 
20
20
  - name: Ethereum Hot Wallet
21
21
  blockchain_key: eth-rinkeby
@@ -31,9 +31,9 @@
31
31
  # Geth gateway client settings.
32
32
  uri: http://127.0.0.1:8545
33
33
  secret: 'test'
34
- bitgo_test_net: true
35
- bitgo_access_token: 'v2x659261647b540ee3acda5c50ae4e878we323474eea5cbff9b9615139629'
36
- bitgo_wallet_id: '5e5388ad80334347ceb3540c741d'
34
+ testnet: true
35
+ access_token: 'v2x659261647b540ee3acda5c50ae4e878we323474eea5cbff9b9615139629'
36
+ wallet_id: '5e5388ad80334347ceb3540c741d'
37
37
 
38
38
  - name: Ethereum Warm Wallet
39
39
  blockchain_key: eth-rinkeby
@@ -49,6 +49,6 @@
49
49
  # Geth gateway client settings.
50
50
  uri: http://127.0.0.1:8545
51
51
  secret: 'test'
52
- bitgo_test_net: true
53
- bitgo_access_token: 'v2x659261647b540ee3acda5c50ae4e878we323474eea5cbff9b9615139629'
54
- bitgo_wallet_id: '5e5388ad80334347ceb3540c741d'
52
+ testnet: true
53
+ access_token: 'v2x659261647b540ee3acda5c50ae4e878we323474eea5cbff9b9615139629'
54
+ wallet_id: '5e5388ad80334347ceb3540c741d'
@@ -0,0 +1,36 @@
1
+ ## Bitgo wallet configuration
2
+
3
+ 1. Login to your bitgo account
4
+ 2. Click in create wallet button
5
+ ![scheme](images/create_wallet.png)
6
+ 3. Choose wallet for appropriate currency
7
+ ![scheme](images/choose_wallet.png)
8
+ 4. Setup your wallet
9
+ ![scheme](images/setup_wallet.png)
10
+ 5. Put name of your wallet
11
+ ![scheme](images/wallet_name.png)
12
+ 6. Put password of your wallet
13
+ ![scheme](images/wallet_secret.png)
14
+ P.S. You should save this password for future wallet configuration
15
+
16
+ ## Peatio BITGO wallet configuration
17
+
18
+ 1. Go to tower admin panel Settings -> Wallets -> Add wallet
19
+ * Uri == Bitgo service URI
20
+ * Secret == Wallet password
21
+ * Bitgo Wallet Id
22
+ ![scheme](images/wallet_id.png)
23
+ * Bitgo Access Token
24
+ ![scheme](images/wallet_access_token.png)
25
+ ![scheme](images/create_wallet_access_token.png)
26
+ ![scheme](images/access_token.png)
27
+
28
+ ## Webhook configuration
29
+
30
+ ![scheme](images/webhook.png)
31
+ ![scheme](images/webhook_creating.png)
32
+
33
+ Where url should be "https://{host_url}/api/v2/peatio/public/webhooks/{event}"
34
+
35
+ * For deposit wallets event should be 'deposit'
36
+ * For hot wallets event should be 'withdraw'
Binary file
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  module Peatio
2
2
  module Bitgo
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
@@ -14,7 +14,7 @@ module Peatio
14
14
 
15
15
  @wallet = @settings.fetch(:wallet) do
16
16
  raise Peatio::Wallet::MissingSettingError, :wallet
17
- end.slice(:uri, :address, :secret, :bitgo_access_token, :bitgo_wallet_id, :bitgo_test_net)
17
+ end.slice(:uri, :address, :secret, :access_token, :wallet_id, :testnet)
18
18
 
19
19
  @currency = @settings.fetch(:currency) do
20
20
  raise Peatio::Wallet::MissingSettingError, :currency
@@ -22,11 +22,13 @@ module Peatio
22
22
  end
23
23
 
24
24
  def create_address!(options = {})
25
- if options[:address_id].present?
26
- response = client.rest_api(:get, "/wallet/#{bitgo_wallet_id}/address/#{options[:address_id]}")
25
+ currency = erc20_currency_id
26
+ options.deep_symbolize_keys!
27
+ if options.dig(:pa_details,:address_id).present?
28
+ response = client.rest_api(:get, "#{currency}/wallet/#{wallet_id}/address/#{options.dig(:pa_details, :address_id)}")
27
29
  { address: response['address'], secret: bitgo_wallet_passphrase }
28
30
  else
29
- response = client.rest_api(:post, "/wallet/#{bitgo_wallet_id}/address")
31
+ response = client.rest_api(:post, "#{currency}/wallet/#{wallet_id}/address")
30
32
  { address: response['address'], secret: bitgo_wallet_passphrase, details: { address_id: response['id'] }}
31
33
  end
32
34
  rescue Bitgo::Client::Error => e
@@ -49,7 +51,7 @@ module Peatio
49
51
  amount -= fee.to_i
50
52
  end
51
53
 
52
- txid = client.rest_api(:post, "/wallet/#{bitgo_wallet_id}/sendcoins", {
54
+ txid = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
53
55
  address: transaction.to_address.to_s,
54
56
  amount: amount.to_s,
55
57
  walletPassphrase: bitgo_wallet_passphrase
@@ -64,7 +66,7 @@ module Peatio
64
66
 
65
67
 
66
68
  def build_raw_transaction(transaction)
67
- client.rest_api(:post, "/wallet/#{bitgo_wallet_id}/tx/build", {
69
+ client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/tx/build", {
68
70
  recipients: [{
69
71
  address: transaction.to_address,
70
72
  amount: convert_to_base_unit(transaction.amount).to_s
@@ -74,9 +76,8 @@ module Peatio
74
76
 
75
77
  def create_eth_transaction(transaction, options = {})
76
78
  amount = convert_to_base_unit(transaction.amount)
77
- amount -= options.fetch(:gas_limit).to_i * options.fetch(:gas_price).to_i if options.dig(:subtract_fee)
78
79
 
79
- txid = client.rest_api(:post, "/wallet/#{bitgo_wallet_id}/sendcoins", {
80
+ txid = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
80
81
  address: transaction.to_address.to_s,
81
82
  amount: amount.to_s,
82
83
  walletPassphrase: bitgo_wallet_passphrase,
@@ -89,15 +90,26 @@ module Peatio
89
90
  end
90
91
 
91
92
  def load_balance!
92
- response = client.rest_api(:get, "/wallet/#{bitgo_wallet_id}")
93
- convert_from_base_unit(response.fetch('balanceString'))
93
+ if @currency.fetch(:options).slice(:erc20_contract_address).present?
94
+ load_erc20_balance!
95
+ else
96
+ response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}")
97
+ convert_from_base_unit(response.fetch('balanceString'))
98
+ end
99
+ rescue Bitgo::Client::Error => e
100
+ raise Peatio::Wallet::ClientError, e
101
+ end
102
+
103
+ def load_erc20_balance!
104
+ response = client.rest_api(:get, "#{erc20_currency_id}/wallet/#{wallet_id}?allTokens=true")
105
+ convert_from_base_unit(response.dig('tokens', currency_id, 'balanceString'))
94
106
  rescue Bitgo::Client::Error => e
95
107
  raise Peatio::Wallet::ClientError, e
96
108
  end
97
109
 
98
110
  def trigger_webhook_event(event)
99
- currency_id = @wallet.fetch(:bitgo_test_net).present? ? 't' + @currency.fetch(:id) : @currency.fetch(:id)
100
- return unless currency_id == event['coin'] && @wallet.fetch(:bitgo_wallet_id) == event['wallet']
111
+ currency_id = @wallet.fetch(:testnet).present? ? 't' + @currency.fetch(:id) : @currency.fetch(:id)
112
+ return unless currency_id == event['coin'] && @wallet.fetch(:wallet_id) == event['wallet']
101
113
 
102
114
  if event['type'] == 'transfer'
103
115
  transactions = fetch_transfer!(event['transfer'])
@@ -114,7 +126,7 @@ module Peatio
114
126
 
115
127
  def fetch_transfer!(id)
116
128
  # TODO: Add Rspecs for this one
117
- response = client.rest_api(:get, "/wallet/#{bitgo_wallet_id}/transfer/#{id}")
129
+ response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}/transfer/#{id}")
118
130
  parse_entries(response['entries']).map do |entry|
119
131
  to_address = if response.dig('coinSpecific', 'memo').present?
120
132
  build_address(response.dig('coinSpecific', 'memo').first)
@@ -145,7 +157,7 @@ module Peatio
145
157
  end
146
158
 
147
159
  def transfer_webhook(url)
148
- client.rest_api(:post, "/wallet/#{bitgo_wallet_id}/webhooks", {
160
+ client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
149
161
  type: 'transfer',
150
162
  allToken: true,
151
163
  url: url,
@@ -155,7 +167,7 @@ module Peatio
155
167
  end
156
168
 
157
169
  def address_confirmation_webhook(url)
158
- client.rest_api(:post, "/wallet/#{bitgo_wallet_id}/webhooks", {
170
+ client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
159
171
  type: 'address_confirmation_webhook',
160
172
  allToken: true,
161
173
  url: url,
@@ -173,12 +185,11 @@ module Peatio
173
185
  private
174
186
 
175
187
  def client
176
- currency_id = @currency.fetch(:id) { raise Peatio::Wallet::MissingSettingError, :id }
177
188
  uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
178
- access_token = @wallet.fetch(:bitgo_access_token) { raise Peatio::Wallet::MissingSettingError, :bitgo_access_token }
189
+ access_token = @wallet.fetch(:access_token) { raise Peatio::Wallet::MissingSettingError, :access_token }
179
190
 
180
- currency_code_prefix = @wallet.fetch(:bitgo_test_net) ? 't' : ''
181
- uri = uri.gsub(/\/+\z/, '') + '/' + currency_code_prefix + currency_id
191
+ currency_code_prefix = @wallet.fetch(:testnet) ? 't' : ''
192
+ uri = uri.gsub(/\/+\z/, '') + '/' + currency_code_prefix
182
193
  @client ||= Client.new(uri, access_token)
183
194
  end
184
195
 
@@ -186,12 +197,24 @@ module Peatio
186
197
  "#{memo['address']}?memoId=#{memo['value']}"
187
198
  end
188
199
 
200
+ # All these functions will have to be done with the coin set to eth or teth
201
+ # since that is the actual coin type being used.
202
+ def erc20_currency_id
203
+ return 'eth' if @currency.fetch(:options).slice(:erc20_contract_address).present?
204
+
205
+ currency_id
206
+ end
207
+
208
+ def currency_id
209
+ @currency.fetch(:id) { raise Peatio::Wallet::MissingSettingError, :id }
210
+ end
211
+
189
212
  def bitgo_wallet_passphrase
190
213
  @wallet.fetch(:secret)
191
214
  end
192
215
 
193
- def bitgo_wallet_id
194
- @wallet.fetch(:bitgo_wallet_id)
216
+ def wallet_id
217
+ @wallet.fetch(:wallet_id)
195
218
  end
196
219
 
197
220
  def normalize_txid(txid)
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency "bundler", "~> 1.16"
34
34
  spec.add_development_dependency "mocha", "~> 1.8"
35
35
  spec.add_development_dependency "pry-byebug"
36
- spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rake", "~> 13.0"
37
37
  spec.add_development_dependency "rspec", "~> 3.0"
38
38
  spec.add_development_dependency "webmock", "~> 3.5"
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peatio-bitgo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nadia Ch., Maksym N.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-06 00:00:00.000000000 Z
11
+ date: 2020-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '10.0'
145
+ version: '13.0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '10.0'
152
+ version: '13.0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rspec
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -198,6 +198,19 @@ files:
198
198
  - configs/blockchains.yml
199
199
  - configs/currencies.yml
200
200
  - configs/wallets.yml
201
+ - docs/configuration.md
202
+ - docs/images/.DS_Store
203
+ - docs/images/access_token.png
204
+ - docs/images/choose_wallet.png
205
+ - docs/images/create_wallet.png
206
+ - docs/images/create_wallet_access_token.png
207
+ - docs/images/setup_wallet.png
208
+ - docs/images/wallet_access_token.png
209
+ - docs/images/wallet_id.png
210
+ - docs/images/wallet_name.png
211
+ - docs/images/wallet_secret.png
212
+ - docs/images/webhook.png
213
+ - docs/images/webhook_creating.png
201
214
  - docs/integration.md
202
215
  - lib/peatio/bitgo.rb
203
216
  - lib/peatio/bitgo/blockchain.rb