Class: Account

Inherits:
Object
  • Object
show all
Defined in:
lib/universum/account.rb

Constant Summary collapse

@@directory =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#txObject (readonly)

Returns the value of attribute tx.



44
45
46
# File 'lib/universum/account.rb', line 44

def tx
  @tx
end

Class Method Details

.[](key) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/universum/account.rb', line 15

def self.[]( key )
  o = find_by_address( key )
  if o
    o
  else
    o = new( key )
    ## note: auto-register (new) address in (yellow page) directory
    @@directory[ key ] = o
    o
  end
end

.allObject



27
# File 'lib/universum/account.rb', line 27

def self.all()  @@directory.values;  end

.at(key) ⇒ Object

another “classic” alias for find_by_address



13
# File 'lib/universum/account.rb', line 13

def self.at( key) find_by_address( key ); end

.find(key) ⇒ Object

make find_by_address the default finder



12
# File 'lib/universum/account.rb', line 12

def self.find( key ) find_by_address( key ); end

.find_by_address(key) ⇒ Object



7
8
9
10
11
# File 'lib/universum/account.rb', line 7

def self.find_by_address( key )
   ## clean key (allow "embedded" name e.g 0x1111 (Alice))
   key = key.gsub(/\(.+\)/, '' ).strip
   @@directory[ key ]
end

Instance Method Details

#_auto_inc_txObject

“internal” method - (auto) increment transaction (tx) counter



45
# File 'lib/universum/account.rb', line 45

def _auto_inc_tx() @tx += 1; end

#addressObject

account (builtin) services / transaction methods



34
# File 'lib/universum/account.rb', line 34

def address() @address; end

#address_hexObject

add convenience shortcut address_hex - why? why not?



35
# File 'lib/universum/account.rb', line 35

def address_hex() @address.hex; end

#balanceObject

note: add convenience shortcut - why? why not?



37
# File 'lib/universum/account.rb', line 37

def balance() @address.balance; end

#balance=(value) ⇒ Object

note: for now allow write access too!!!



39
40
41
# File 'lib/universum/account.rb', line 39

def balance=( value )
  @address.send( '@balance=', value )
end