Module: Address

Included in:
Account, Contract
Defined in:
lib/universum/address.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.zeroObject



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

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

Instance Method Details

#_add(value) ⇒ Object



49
50
51
52
# File 'lib/universum/address.rb', line 49

def _add( value )
  @balance ||= 0   ## return 0 if undefined
  @balance += value
end

#_sub(value) ⇒ Object

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



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

def _sub( value )
  @balance ||= 0   ## return 0 if undefined
  @balance -= value
end

#addressObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/universum/address.rb', line 11

def address
  if @address
    @address
  else
    if is_a? Contract
       ##  fix/todo:  use/lookup proper addr from contract
       ## construct address for now from object_id
       "0x#{(object_id << 1).to_s(16)}"
    else  ## assume Account
       '0x0000'
    end
  end
end

#balanceObject



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

def balance
  @balance ||= 0   ## return 0 if undefined
end

#send(value) ⇒ Object



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

def send( value )  ## @payable @public
  ## todo/fix: assert value > 0
  ## todo/fix: add missing  -= part in transfer!!!!

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

#transfer(value) ⇒ Object

method address



25
26
27
28
# File 'lib/universum/address.rb', line 25

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