Class: Mobius::Client::Blockchain::Account
- Inherits:
-
Object
- Object
- Mobius::Client::Blockchain::Account
- Extended by:
- Dry::Initializer
- Defined in:
- lib/mobius/client/blockchain/account.rb
Overview
Service class used to interact with account on Stellar network.
Instance Method Summary collapse
-
#account ⇒ Stellar::Account
Returns Stellar::Account instance for given keypair.
-
#authorized?(to_keypair) ⇒ Boolean
Returns true if given keypair is added as cosigner to current account.
-
#balance(asset = Mobius::Client.stellar_asset) ⇒ Float
Returns balance for given asset.
-
#info ⇒ Stellar::Account
Requests and caches Stellar::Account information from network.
- #initialize(keypair) ⇒ Object constructor
-
#next_sequence_value ⇒ Integer
Invalidates cache and returns next sequence value for given account.
-
#reload! ⇒ Object
Invalidates account information cache.
-
#trustline_exists?(asset = Mobius::Client.stellar_asset) ⇒ Boolean
Returns true if trustline exists for given asset and limit is positive.
Constructor Details
#initialize(keypair) ⇒ Object
8 |
# File 'lib/mobius/client/blockchain/account.rb', line 8 param :keypair |
Instance Method Details
#account ⇒ Stellar::Account
Returns Stellar::Account instance for given keypair.
36 37 38 39 40 41 42 43 |
# File 'lib/mobius/client/blockchain/account.rb', line 36 def account @account ||= if keypair.sign? Stellar::Account.from_seed(keypair.seed) else Stellar::Account.from_address(keypair.address) end end |
#authorized?(to_keypair) ⇒ Boolean
Returns true if given keypair is added as cosigner to current account. TODO: Add weight check/return
30 31 32 |
# File 'lib/mobius/client/blockchain/account.rb', line 30 def (to_keypair) !find_signer(to_keypair.address).nil? end |
#balance(asset = Mobius::Client.stellar_asset) ⇒ Float
Returns balance for given asset
21 22 23 24 |
# File 'lib/mobius/client/blockchain/account.rb', line 21 def balance(asset = Mobius::Client.stellar_asset) balance = find_balance(asset) balance && balance.dig("balance").to_f end |
#info ⇒ Stellar::Account
Requests and caches Stellar::Account information from network.
47 48 49 |
# File 'lib/mobius/client/blockchain/account.rb', line 47 def info @info ||= Mobius::Client.horizon_client.account_info(account) end |
#next_sequence_value ⇒ Integer
Invalidates cache and returns next sequence value for given account.
58 59 60 61 |
# File 'lib/mobius/client/blockchain/account.rb', line 58 def next_sequence_value reload! info.sequence.to_i + 1 end |
#reload! ⇒ Object
Invalidates account information cache.
52 53 54 |
# File 'lib/mobius/client/blockchain/account.rb', line 52 def reload! @info = nil end |
#trustline_exists?(asset = Mobius::Client.stellar_asset) ⇒ Boolean
Returns true if trustline exists for given asset and limit is positive.
13 14 15 16 |
# File 'lib/mobius/client/blockchain/account.rb', line 13 def trustline_exists?(asset = Mobius::Client.stellar_asset) balance = find_balance(asset) (balance && !balance.dig("limit").to_f.zero?) || false end |