Class: Glueby::Wallet

Inherits:
Object
  • Object
show all
Defined in:
lib/glueby/wallet.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#internal_walletObject (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

.createObject



8
9
10
# File 'lib/glueby/wallet.rb', line 8

def create
  new(Glueby::Internal::Wallet.create)
end

.load(wallet_id) ⇒ Object



12
13
14
# File 'lib/glueby/wallet.rb', line 12

def load(wallet_id)
  new(Glueby::Internal::Wallet.load(wallet_id))
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.

Returns:

  • (HashMap)

    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

#idObject



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