Class: Glueby::Wallet
- Inherits:
-
Object
- Object
- Glueby::Wallet
- Defined in:
- lib/glueby/wallet.rb
Instance Attribute Summary collapse
-
#internal_wallet ⇒ Object
readonly
Returns the value of attribute internal_wallet.
Class Method Summary collapse
-
.configure(config) ⇒ Object
deprecated
Deprecated.
-
Use Glueby.configure instead
-
- .create ⇒ Object
- .load(wallet_id) ⇒ Object
Instance Method Summary collapse
-
#balances(only_finalized = true) ⇒ HashMap
Hash of balances which key is color_id or empty string, and value is amount.
- #id ⇒ Object
- #token_utxos(color_id = nil, only_finalized = true, page = 1, per = 25) ⇒ Object
Instance Attribute Details
#internal_wallet ⇒ Object (readonly)
Returns the value of attribute internal_wallet.
5 6 7 |
# File 'lib/glueby/wallet.rb', line 5 def internal_wallet @internal_wallet end |
Class Method Details
.configure(config) ⇒ Object
Deprecated.
-
Use Glueby.configure instead
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/glueby/wallet.rb', line 17 def configure(config) case config[:adapter] when 'core' Glueby::Internal::RPC.configure(config) Glueby::Internal::Wallet.wallet_adapter = Glueby::Internal::Wallet::TapyrusCoreWalletAdapter.new when 'activerecord' Glueby::Internal::RPC.configure(config) Glueby::Internal::Wallet.wallet_adapter = Glueby::Internal::Wallet::ActiveRecordWalletAdapter.new when 'mysql' Glueby::Internal::RPC.configure(config) Glueby::Internal::Wallet.wallet_adapter = Glueby::Internal::Wallet::MySQLWalletAdapter.new else raise 'Not implemented' end end |
Instance Method Details
#balances(only_finalized = true) ⇒ HashMap
Returns hash of balances which key is color_id or empty string, and value is amount.
39 40 41 42 43 44 45 46 47 |
# File 'lib/glueby/wallet.rb', line 39 def balances(only_finalized = true) utxos = @internal_wallet.list_unspent(only_finalized) utxos.inject({}) do |balances, output| key = output[:color_id] || '' balances[key] ||= 0 balances[key] += output[:amount] balances end end |
#id ⇒ Object
34 35 36 |
# File 'lib/glueby/wallet.rb', line 34 def id @internal_wallet.id end |
#token_utxos(color_id = nil, only_finalized = true, page = 1, per = 25) ⇒ Object
49 50 51 |
# File 'lib/glueby/wallet.rb', line 49 def token_utxos(color_id = nil, only_finalized = true, page = 1, per = 25) @internal_wallet.list_unspent_with_count(only_finalized, nil, color_id: color_id, page: page, per: per) end |