Top Level Namespace

Defined Under Namespace

Modules: Rubysol Classes: Builder, CodegenClassic, Contract, ContractDef, Proc, Source

Instance Method Summary collapse

Instance Method Details

say hello



42
# File 'lib/rubidity.rb', line 42

puts Rubysol::Module::Rubidity.banner

#patch(src) ⇒ Object

require(s.balanceOf >= amount, ‘Insufficient balance’)

s.balanceOf -= amount s.balanceOf += amount

emit :Transfer, from: msg.sender, to: to, amount: amount



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rubidity/codegen.rb', line 12

def patch( src )
    ## change require() to assert
    src = src.gsub( /\brequire\b/, 'assert' )
 
    ## s. to ivars (@)
    src = src.gsub( /\bs\./, '@' )
 
    ## change emit :  to log
    src = src.gsub( /\bemit[ ]+:/, 'log ' )
    src
end

#spec_to_type(spec, structs: {}) ⇒ Object

storage totalSupply:args=> storage balanceOf:key_type=>:address, :value_type=>:uint256, :args=> storage allowance

                :key_type=>:address,
:value_type=>{:type=>:mapping, :key_type=>:address, :value_type=>:uint256, :args=>[],


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rubidity/codegen.rb', line 35

def spec_to_type( spec, structs: {} )
  type = spec.is_a?( Symbol ) ? spec : spec[:type] 

  ## check structs first
  struct_class = structs[ type ]
  if struct_class
    puts "  found struct class >#{type}<:"
    pp struct_class
    return struct_class
  end

  case type  
  when :uint8, :uint32, :uint112, :uint224, :uint256  then Types::UInt
  when :address   then Types::Address
  when :string    then Types::String
  when :bytes     then Types::Bytes
  when :timestamp then Types::Timestamp
  when :bool      then Bool   ## note: Bool is always "global" - why? why not?
  when :mapping   then mapping( spec_to_type( spec[:key_type], structs: structs ), 
                                spec_to_type( spec[:value_type], structs: structs ) )                                
  when :array     then array( spec_to_type( spec[:sub_type], structs: structs ))
  else
    raise ArgumentError, "unknown type - #{type}" 
  end
end