mobius-client 0.3.0 → 0.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 +5 -5
- data/.travis.yml +3 -3
- data/README.md +2 -1
- data/lib/mobius/client/app.rb +51 -22
- data/lib/mobius/client/blockchain/account.rb +2 -1
- data/lib/mobius/client/version.rb +1 -1
- data/lib/mobius/client.rb +1 -4
- data/mobius-client.gemspec +1 -1
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bb3a779d514fea2f8482f7843d4c2e78ce01902a
|
4
|
+
data.tar.gz: bf92f3da028fc789bb158f81318239d66ee84add
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f6a32e7302f77b8530e6b8f79ef84091cf69ff1902721f928bbb1392227fef2a18d9563250fb178062359e0788f97d082de26d670aa7edf485c0d476afa9794
|
7
|
+
data.tar.gz: b6af2c669c2a6311fe6a5ddadf55a78a9eb98d33938dd720cbdbb5d0f715b1de4320fd02a5bc7a9496e98e9921b9a7e13acadcee72fc82cba8e410540a633ed8
|
data/.travis.yml
CHANGED
@@ -9,14 +9,14 @@ rvm:
|
|
9
9
|
- 2.5
|
10
10
|
cache: bundler
|
11
11
|
before_install:
|
12
|
-
- gem update --system && gem install bundler
|
13
|
-
before_script:
|
12
|
+
- gem update --system && gem install --no-document bundler
|
14
13
|
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
15
14
|
- chmod +x ./cc-test-reporter
|
15
|
+
before_script:
|
16
16
|
- ./cc-test-reporter before-build
|
17
17
|
after_script:
|
18
18
|
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
19
19
|
script:
|
20
20
|
- bundle exec rake
|
21
|
-
- bundle exec bundle-audit update
|
21
|
+
- bundle exec bundle-audit check --update --ignore CVE-2016-10545
|
22
22
|
- bundle exec rubocop
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
[](https://badge.fury.io/rb/mobius-client)
|
2
2
|
[](https://travis-ci.org/mobius-network/mobius-client-ruby)
|
3
|
-
[](https://codeclimate.com/github/mobius-network/mobius-client-ruby/maintainability)
|
4
|
+
[](https://codeclimate.com/github/mobius-network/mobius-client-ruby/test_coverage)
|
4
5
|
|
5
6
|
# Mobius DApp Store Ruby SDK
|
6
7
|
|
data/lib/mobius/client/app.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Interface to user balance in application.
|
2
|
+
# rubocop:disable Metrics/ClassLength
|
2
3
|
class Mobius::Client::App
|
3
4
|
extend Dry::Initializer
|
4
5
|
|
@@ -15,9 +16,18 @@ class Mobius::Client::App
|
|
15
16
|
user_account.authorized?(app_keypair)
|
16
17
|
end
|
17
18
|
|
19
|
+
# @deprecated use {#user_balance} instead
|
20
|
+
def balance
|
21
|
+
warn <<~MSG
|
22
|
+
[DEPRECATED] method Mobius::Client::App#balance is deprecated and will be removed,
|
23
|
+
use Mobius::Client::App#user_balance instead"
|
24
|
+
MSG
|
25
|
+
user_balance
|
26
|
+
end
|
27
|
+
|
18
28
|
# Returns user balance.
|
19
29
|
# @return [Float] User balance.
|
20
|
-
def
|
30
|
+
def user_balance
|
21
31
|
validate!
|
22
32
|
user_account.balance
|
23
33
|
end
|
@@ -33,7 +43,10 @@ class Mobius::Client::App
|
|
33
43
|
# @param target_address [String] Optional: third party receiver address.
|
34
44
|
# @deprecated use {#charge} instead
|
35
45
|
def pay(amount, target_address: nil)
|
36
|
-
warn
|
46
|
+
warn <<~MSG
|
47
|
+
[DEPRECATED] method Mobius::Client::App#pay is deprecated and will be removed,
|
48
|
+
use Mobius::Client::App#charge instead"
|
49
|
+
MSG
|
37
50
|
charge(amount, target_address)
|
38
51
|
end
|
39
52
|
|
@@ -77,6 +90,30 @@ class Mobius::Client::App
|
|
77
90
|
handle(err)
|
78
91
|
end
|
79
92
|
|
93
|
+
# Returns application keypair
|
94
|
+
# @return [Stellar::KeyPair] Application KeyPair
|
95
|
+
def app_keypair
|
96
|
+
@app_keypair ||= Mobius::Client.to_keypair(seed)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Returns user keypair
|
100
|
+
# @return [Stellar::KeyPair] User KeyPair
|
101
|
+
def user_keypair
|
102
|
+
@user_keypair ||= Mobius::Client.to_keypair(address)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Returns application account
|
106
|
+
# @return [Mobius::Client::Blockchain::Account] Application Account
|
107
|
+
def app_account
|
108
|
+
@app_account ||= Mobius::Client::Blockchain::Account.new(app_keypair)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Returns user account
|
112
|
+
# @return [Mobius::Client::Blockchain::Account] User Account
|
113
|
+
def user_account
|
114
|
+
@user_account ||= Mobius::Client::Blockchain::Account.new(user_keypair)
|
115
|
+
end
|
116
|
+
|
80
117
|
private
|
81
118
|
|
82
119
|
def submit_tx
|
@@ -84,17 +121,24 @@ class Mobius::Client::App
|
|
84
121
|
|
85
122
|
tx = Stellar::Transaction.for_account(
|
86
123
|
account: user_keypair,
|
87
|
-
sequence: user_account.next_sequence_value
|
124
|
+
sequence: user_account.next_sequence_value
|
88
125
|
)
|
89
126
|
|
90
127
|
yield(tx.operations)
|
128
|
+
calc_fee(tx)
|
129
|
+
txe = base64(tx)
|
91
130
|
|
92
|
-
tx.fee = FEE * tx.operations.size
|
93
|
-
|
94
|
-
txe = tx.to_envelope(app_keypair).to_xdr(:base64)
|
95
131
|
post_txe(txe).tap { [app_account, user_account].each(&:reload!) }
|
96
132
|
end
|
97
133
|
|
134
|
+
def calc_fee(txn)
|
135
|
+
txn.fee = FEE * txn.operations.size
|
136
|
+
end
|
137
|
+
|
138
|
+
def base64(txn)
|
139
|
+
txn.to_envelope(app_keypair).to_xdr(:base64)
|
140
|
+
end
|
141
|
+
|
98
142
|
def post_txe(txe)
|
99
143
|
Mobius::Client.horizon_client.horizon.transactions._post(tx: txe)
|
100
144
|
end
|
@@ -112,22 +156,6 @@ class Mobius::Client::App
|
|
112
156
|
raise Mobius::Client::Error::TrustlineMissing unless user_account.trustline_exists?
|
113
157
|
end
|
114
158
|
|
115
|
-
def app_keypair
|
116
|
-
@app_keypair ||= Mobius::Client.to_keypair(seed)
|
117
|
-
end
|
118
|
-
|
119
|
-
def user_keypair
|
120
|
-
@user_keypair ||= Mobius::Client.to_keypair(address)
|
121
|
-
end
|
122
|
-
|
123
|
-
def app_account
|
124
|
-
@app_account ||= Mobius::Client::Blockchain::Account.new(app_keypair)
|
125
|
-
end
|
126
|
-
|
127
|
-
def user_account
|
128
|
-
@user_account ||= Mobius::Client::Blockchain::Account.new(user_keypair)
|
129
|
-
end
|
130
|
-
|
131
159
|
def handle(err)
|
132
160
|
ops = err.response.dig(:body, "extras", "result_codes", "operations")
|
133
161
|
raise Mobius::Client::Error::AccountMissing if ops.include?("op_no_destination")
|
@@ -143,3 +171,4 @@ class Mobius::Client::App
|
|
143
171
|
|
144
172
|
FEE = 100
|
145
173
|
end
|
174
|
+
# rubocop:enable Metrics/ClassLength
|
@@ -20,7 +20,8 @@ class Mobius::Client::Blockchain::Account
|
|
20
20
|
# @return [Float] Balance value.
|
21
21
|
def balance(asset = Mobius::Client.stellar_asset)
|
22
22
|
balance = find_balance(asset)
|
23
|
-
balance
|
23
|
+
balance = balance&.dig("balance")
|
24
|
+
return balance.to_d if balance
|
24
25
|
end
|
25
26
|
|
26
27
|
# Returns true if given keypair is added as cosigner to current account.
|
data/lib/mobius/client.rb
CHANGED
data/mobius-client.gemspec
CHANGED
@@ -28,11 +28,11 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency "bundler", "~> 1.16"
|
29
29
|
spec.add_development_dependency "bundler-audit", "~> 0.6.0"
|
30
30
|
spec.add_development_dependency "httplog", "~> 1.0", ">= 1.0.2"
|
31
|
+
spec.add_development_dependency "pry-byebug"
|
31
32
|
spec.add_development_dependency "rake", "~> 12.0"
|
32
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
33
34
|
spec.add_development_dependency "rubocop", "~> 0.53"
|
34
35
|
spec.add_development_dependency "rubocop-rspec", "~> 1.23"
|
35
|
-
spec.add_development_dependency "pry-byebug"
|
36
36
|
spec.add_development_dependency "simplecov", ">= 0.16.1"
|
37
37
|
spec.add_development_dependency "simplecov-console", ">= 0.4.2"
|
38
38
|
spec.add_development_dependency "timecop", "~> 0.9", ">= 0.9.1"
|
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.
|
4
|
+
version: 0.4.0
|
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-06
|
11
|
+
date: 2018-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 1.0.2
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: pry-byebug
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: rake
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,20 +128,6 @@ dependencies:
|
|
114
128
|
- - "~>"
|
115
129
|
- !ruby/object:Gem::Version
|
116
130
|
version: '1.23'
|
117
|
-
- !ruby/object:Gem::Dependency
|
118
|
-
name: pry-byebug
|
119
|
-
requirement: !ruby/object:Gem::Requirement
|
120
|
-
requirements:
|
121
|
-
- - ">="
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version: '0'
|
124
|
-
type: :development
|
125
|
-
prerelease: false
|
126
|
-
version_requirements: !ruby/object:Gem::Requirement
|
127
|
-
requirements:
|
128
|
-
- - ">="
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
version: '0'
|
131
131
|
- !ruby/object:Gem::Dependency
|
132
132
|
name: simplecov
|
133
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -406,7 +406,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
406
406
|
version: '0'
|
407
407
|
requirements: []
|
408
408
|
rubyforge_project:
|
409
|
-
rubygems_version: 2.
|
409
|
+
rubygems_version: 2.6.13
|
410
410
|
signing_key:
|
411
411
|
specification_version: 4
|
412
412
|
summary: Mobius Ruby Client
|