Class: Mobius::Client::App
- Inherits:
-
Object
- Object
- Mobius::Client::App
- Extended by:
- Dry::Initializer
- Defined in:
- lib/mobius/client/app.rb
Overview
Interface to user balance in application. rubocop:disable Metrics/ClassLength
Instance Method Summary collapse
-
#app_account ⇒ Mobius::Client::Blockchain::Account
Returns application account.
-
#app_balance ⇒ Float
Returns application balance.
-
#app_keypair ⇒ Stellar::KeyPair
Returns application keypair.
-
#authorized? ⇒ Bool
Checks if developer is authorized to use an application.
-
#balance ⇒ Object
deprecated
Deprecated.
use #user_balance instead
-
#charge(amount, target_address: nil) ⇒ Object
Charges user’s wallet.
- #initialize(seed) ⇒ Object constructor
-
#pay(amount, target_address: nil) ⇒ Object
deprecated
Deprecated.
use #charge instead
-
#payout(amount, target_address: user_keypair.address) ⇒ Object
Sends money from application account to user’s account or target_address, if given.
-
#transfer(amount, address) ⇒ Object
Sends money from user’s account to third party.
-
#user_account ⇒ Mobius::Client::Blockchain::Account
Returns user account.
-
#user_balance ⇒ Float
Returns user balance.
-
#user_keypair ⇒ Stellar::KeyPair
Returns user keypair.
Constructor Details
#initialize(seed) ⇒ Object
10 |
# File 'lib/mobius/client/app.rb', line 10 param :seed |
Instance Method Details
#app_account ⇒ Mobius::Client::Blockchain::Account
Returns application account
107 108 109 |
# File 'lib/mobius/client/app.rb', line 107 def app_account @app_account ||= Mobius::Client::Blockchain::Account.new(app_keypair) end |
#app_balance ⇒ Float
Returns application balance.
37 38 39 |
# File 'lib/mobius/client/app.rb', line 37 def app_balance app_account.balance end |
#app_keypair ⇒ Stellar::KeyPair
Returns application keypair
95 96 97 |
# File 'lib/mobius/client/app.rb', line 95 def app_keypair @app_keypair ||= Mobius::Client.to_keypair(seed) end |
#authorized? ⇒ Bool
Checks if developer is authorized to use an application.
15 16 17 |
# File 'lib/mobius/client/app.rb', line 15 def user_account.(app_keypair) end |
#balance ⇒ Object
use #user_balance instead
20 21 22 23 24 25 26 |
# File 'lib/mobius/client/app.rb', line 20 def balance warn <<~MSG [DEPRECATED] method Mobius::Client::App#balance is deprecated and will be removed, use Mobius::Client::App#user_balance instead" MSG user_balance end |
#charge(amount, target_address: nil) ⇒ Object
Charges user’s wallet.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mobius/client/app.rb', line 56 def charge(amount, target_address: nil) amount = cast_amount(amount) raise Mobius::Client::Error::InsufficientFunds if user_balance < amount submit_tx do |operations| operations << payment_op(amount, dest: app_keypair, src: user_keypair) operations << payment_op(amount, dest: target_address, src: app_keypair) if target_address end rescue Faraday::ClientError => err handle(err) end |
#pay(amount, target_address: nil) ⇒ Object
use #charge instead
Makes payment.
45 46 47 48 49 50 51 |
# File 'lib/mobius/client/app.rb', line 45 def pay(amount, target_address: nil) warn <<~MSG [DEPRECATED] method Mobius::Client::App#pay is deprecated and will be removed, use Mobius::Client::App#charge instead" MSG charge(amount, target_address) end |
#payout(amount, target_address: user_keypair.address) ⇒ Object
Sends money from application account to user’s account or target_address, if given
83 84 85 86 87 88 89 90 91 |
# File 'lib/mobius/client/app.rb', line 83 def payout(amount, target_address: user_keypair.address) amount = cast_amount(amount) raise Mobius::Client::Error::InsufficientFunds if app_balance < amount submit_tx do |operations| operations << payment_op(amount, dest: target_address, src: app_keypair) end rescue Faraday::ClientError => err handle(err) end |
#transfer(amount, address) ⇒ Object
Sends money from user’s account to third party.
72 73 74 75 76 77 78 |
# File 'lib/mobius/client/app.rb', line 72 def transfer(amount, address) amount = cast_amount(amount) raise Mobius::Client::Error::InsufficientFunds if app_balance < amount submit_tx { |operations| operations << payment_op(amount, dest: address, src: user_keypair) } rescue Faraday::ClientError => err handle(err) end |
#user_account ⇒ Mobius::Client::Blockchain::Account
Returns user account
113 114 115 |
# File 'lib/mobius/client/app.rb', line 113 def user_account @user_account ||= Mobius::Client::Blockchain::Account.new(user_keypair) end |
#user_balance ⇒ Float
Returns user balance.
30 31 32 33 |
# File 'lib/mobius/client/app.rb', line 30 def user_balance validate! user_account.balance end |
#user_keypair ⇒ Stellar::KeyPair
Returns user keypair
101 102 103 |
# File 'lib/mobius/client/app.rb', line 101 def user_keypair @user_keypair ||= Mobius::Client.to_keypair(address) end |