Class: Types::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/soliscript/simulacrum.rb

Instance Method Summary collapse

Instance Method Details

#_accountObject

add ethereum account “magic” e.g. balance (getter), send (method), transfer (method)



118
119
120
121
# File 'lib/soliscript/simulacrum.rb', line 118

def 
   ## get "attached" account - make private? why? why not

   [ @value ]
end

#balanceObject



123
# File 'lib/soliscript/simulacrum.rb', line 123

def balance()  .balance;  end

#send(value) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/soliscript/simulacrum.rb', line 125

def send( value )
   ## note: always use simple string in account lookup!!!

   from =  [ Simulacrum.msg.sender.as_data ]    
   to   =  

   ## check for more datatypes or (simply) use to_int or to_i - why? why not?

   value = value.is_a?( UInt ) ? value.as_data : value

   ## check for below 0 - why? why not?        

   if value > from.balance
      raise ArgumentError, "insufficent funds - account has #{from.balance} and required min. #{value}; sorry"
   end 

   from.balance -= value
   to.balance   += value
end

#transfer(value) ⇒ Object

check - transfer same as send (but with different rollback/error exception policy?)



143
# File 'lib/soliscript/simulacrum.rb', line 143

def transfer( value ) send( value ); end