Class: Address

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address, balance: 0) ⇒ Address

Returns a new instance of Address.



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

def initialize( address, balance: 0 )
  @address = address
  @balance = balance
end

Class Method Details

.zeroObject



5
# File 'lib/universum/address.rb', line 5

def self.zero() '0x0000'; end

Instance Method Details

#_add(value) ⇒ Object



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

def _add( value )
  @balance += value
end

#_send(from, value) ⇒ Object

private (internal use only) methods - PLEASE do NOT use (use transfer/send)



31
32
33
34
35
36
37
38
# File 'lib/universum/address.rb', line 31

def _send( from, value )
  ## todo/fix: assert value > 0
  ## todo/fix: add missing  -= part in transfer!!!!

  ## use this (current contract) for debit (-) ammount
  from._sub( value )    # sub(tract) / debit from the sender (current contract)
  _add( value )         # add / credit to the recipient
end

#_sub(value) ⇒ Object



40
41
42
# File 'lib/universum/address.rb', line 40

def _sub( value )
  @balance -= value
end

#balanceObject



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

def balance() @balance; end

#hexObject

return address as a hex string (e.g. ‘0x1111’ etc.)



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

def hex()     @address; end

#send(value) ⇒ Object



23
24
25
26
# File 'lib/universum/address.rb', line 23

def send( value )  ## @payable @public
  ## note: auto-adds "global" from address (using Universum.this)
  _send( Universum.this, value )
end

#transfer(value) ⇒ Object



17
18
19
20
21
# File 'lib/universum/address.rb', line 17

def transfer( value )  ## @payable @public
  ## todo/fix: throw exception if insufficient funds
  ## todo/fix: use assert( send( value )
  send( value )   # returns true/false
end