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
Instance Method Details
#account ⇒ Stellar::Account
Returns Stellar::Account instance for given keypair.
37 38 39 40 41 42 43 44 |
# File 'lib/mobius/client/blockchain/account.rb', line 37 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
31 32 33 |
# File 'lib/mobius/client/blockchain/account.rb', line 31 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 25 |
# File 'lib/mobius/client/blockchain/account.rb', line 21 def balance(asset = Mobius::Client.stellar_asset) balance = find_balance(asset) balance = balance&.dig("balance") return balance.to_d if balance end |
#info ⇒ Stellar::Account
Requests and caches Stellar::Account information from network.
48 49 50 |
# File 'lib/mobius/client/blockchain/account.rb', line 48 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.
59 60 61 62 |
# File 'lib/mobius/client/blockchain/account.rb', line 59 def next_sequence_value reload! info.sequence.to_i + 1 end |
#reload! ⇒ Object
Invalidates account information cache.
53 54 55 |
# File 'lib/mobius/client/blockchain/account.rb', line 53 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_d.zero?) || false end |