Module: ConversionFunctions

Defined in:
lib/solidity/typed/conversion.rb

Instance Method Summary collapse

Instance Method Details

#address(obj) ⇒ Object

todo/check: use AddressType.try_convert( literal_or_obj ) or such - why? why not?



10
11
12
13
14
15
16
17
18
19
# File 'lib/solidity/typed/conversion.rb', line 10

def address( obj )
    ## hack for now support  address(0) 
    ##  todo/fix:  address( '0x0' ) too!!!!
    return Types::Address.zero                    if obj.is_a?(::Integer) && obj == 0

    ## note: for now assume contract is always "construct"ed (and, thus, has an address assigned)
    return Types::Address.new( obj.__address__ )  if obj.is_a?( Contract )

    Types::Address.new( obj )
end

#bytes(obj) ⇒ Object Also known as: bytes4



39
40
41
42
43
# File 'lib/solidity/typed/conversion.rb', line 39

def bytes( obj )
  return obj           if obj.is_a?( Types::Bytes )

  Types::Bytes.new( obj )   
end

#uint(obj) ⇒ Object Also known as: uint256, uint224, uint112



22
23
24
25
26
27
# File 'lib/solidity/typed/conversion.rb', line 22

def uint( obj )
    return obj.to_uint   if obj.is_a?( Types::Address )
    return obj           if obj.is_a?( Types::UInt )

    Types::UInt.new( obj )   ## assume obj is a integer number
end