Module: RuntimeHelper

Included in:
Contract
Defined in:
lib/rubysol/contract/runtime.rb

Instance Method Summary collapse

Instance Method Details

#assert(condition, message = 'no message') ⇒ Object

keep assert here - why? why not?

use AssertHelper or ErrorHelper or ...

note: change from require to assert

to avoid confusion with ruby require - why? why not?


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rubysol/contract/runtime.rb', line 12

def assert(condition, message='no message')
  unless condition
    # caller_location = caller_locations.detect { |l| l.path.include?('/app/models/contracts') }
    # file = caller_location.path.gsub(%r{.*app/models/contracts/}, '')
    # line = caller_location.lineno
    
    puts "!! ASSERT FAILED - #{message}"

    error_message = "#{message}"     ##. (#{file}:#{line})"
    ## todo/fix: change to (built-in) ???Error, ....
    ##  check for error to raise for assertion fail??
    raise error_message
  end
end

#blockObject



38
# File 'lib/rubysol/contract/runtime.rb', line 38

def block()                Runtime.block; end

#current_transactionObject

todo/check: change current_transaction to tx - why? why not?



35
# File 'lib/rubysol/contract/runtime.rb', line 35

def current_transaction()  Runtime.current_transaction; end

#log(event_klass, *args, **kwargs) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rubysol/contract/runtime.rb', line 40

def log( event_klass, *args, **kwargs )

  raise "event class expected; got: >#{event_klass.inspect}<; sorry"  unless event_klass.ancestors.include?( Types::Event)
  
  rec = if kwargs.size > 0
          event_klass.new( **kwargs )
        else
          event_klass.new( *args )
        end
  data = rec.as_data   ## "serialize" to "plain" types
  
  current_transaction.log_event( { event: event_klass.name, 
                                   data:  data })
end

#msgObject



37
# File 'lib/rubysol/contract/runtime.rb', line 37

def msg()                  Runtime.msg; end

#thisObject

note: for now this is just the solidity alias/used name

for ruby's self  - anything missing - why? why not?
- to get the address - use address( this )


31
# File 'lib/rubysol/contract/runtime.rb', line 31

def this()  self; end