mobius-client 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mobius/client/app.rb +15 -0
- data/lib/mobius/client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa4d61727ba66679c6a5089ec75012d4c87e1d24
|
4
|
+
data.tar.gz: a2418ab7d25c6f54e3f8e9a36800f8b929be5913
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbf295dd5c30ae4decfddad11da7f071a4b9840a648a1fd5a9ad190af01058e63e6db0d53c40fe2c38e90001c739f5081bbd48fa1542cb0c42b381211ab4930b
|
7
|
+
data.tar.gz: a89f53e9a33aba413fe7e53b0e71b737acdd7954315de9283f7876ca3c5f41358597f00a58ba9f5c151f308d9a2b10ce18cdfa6ee8f40197e2d8693263bc2fcd
|
data/lib/mobius/client/app.rb
CHANGED
@@ -31,6 +31,7 @@ class Mobius::Client::App
|
|
31
31
|
# Makes payment.
|
32
32
|
# @param amount [Float] Payment amount.
|
33
33
|
# @param target_address [String] Optional: third party receiver address.
|
34
|
+
# rubocop:disable Metrics/AbcSize
|
34
35
|
def pay(amount, target_address: nil)
|
35
36
|
current_balance = balance
|
36
37
|
raise Mobius::Client::Error::InsufficientFunds if current_balance < amount.to_f
|
@@ -38,11 +39,15 @@ class Mobius::Client::App
|
|
38
39
|
post_tx(envelope_base64).tap do
|
39
40
|
[app_account, user_account].each(&:reload!)
|
40
41
|
end
|
42
|
+
rescue Faraday::ClientError => err
|
43
|
+
handle(err)
|
41
44
|
end
|
45
|
+
# rubocop:enable Metrics/AbcSize
|
42
46
|
|
43
47
|
# Sends money from application account to third party.
|
44
48
|
# @param amount [Float] Payment amount.
|
45
49
|
# @param address [String] Target address.
|
50
|
+
# rubocop:disable Metrics/AbcSize
|
46
51
|
def transfer(amount, address)
|
47
52
|
current_balance = app_balance
|
48
53
|
raise Mobius::Client::Error::InsufficientFunds if current_balance < amount.to_f
|
@@ -50,7 +55,10 @@ class Mobius::Client::App
|
|
50
55
|
post_tx(envelope_base64).tap do
|
51
56
|
[app_account, user_account].each(&:reload!)
|
52
57
|
end
|
58
|
+
rescue Faraday::ClientError => err
|
59
|
+
handle(err)
|
53
60
|
end
|
61
|
+
# rubocop:enable Metrics/AbcSize
|
54
62
|
|
55
63
|
private
|
56
64
|
|
@@ -132,5 +140,12 @@ class Mobius::Client::App
|
|
132
140
|
@user_account ||= Mobius::Client::Blockchain::Account.new(user_keypair)
|
133
141
|
end
|
134
142
|
|
143
|
+
def handle(err)
|
144
|
+
ops = err.response.dig(:body, "extras", "result_codes", "operations")
|
145
|
+
raise Mobius::Client::Error::AccountMissing if ops.include?("op_no_destination")
|
146
|
+
raise Mobius::Client::Error::TrustlineMissing if ops.include?("op_no_trust")
|
147
|
+
raise err
|
148
|
+
end
|
149
|
+
|
135
150
|
FEE = 100
|
136
151
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobius-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Viktor Sokolov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|