Class: ABI::Constructor

Inherits:
Object
  • Object
show all
Defined in:
lib/abiparser/constructor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inputs: [], payable: false) ⇒ Constructor

:input_types



53
54
55
56
57
58
59
60
61
62
# File 'lib/abiparser/constructor.rb', line 53

def initialize( inputs: [],
                payable: false )
   @inputs  = inputs
   @payable = payable

   ##  parse inputs into types
   ##    note: use "calculated" sig(nature) and NOT the type
   ##        (differs for tuples, that is, types with components !!!)
   ##  @input_types  = @inputs.map {|param| Type.parse( param.sig ) }
end

Instance Attribute Details

#inputsObject (readonly)

Returns the value of attribute inputs.



50
51
52
# File 'lib/abiparser/constructor.rb', line 50

def inputs
  @inputs
end

Class Method Details

.parse(o) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/abiparser/constructor.rb', line 4

def self.parse( o )
    ## note:
    ##  - has no name
    ##  - has no ouptputs
    ## e.g.
    ##   {"inputs":[],
    ##    "stateMutability":"nonpayable",
    ##    "type":"constructor"}

  inputs  = o['inputs'].map {|param| Param.parse( param ) }
  payable = nil

  ## old soliditity before v0.6
  ##  newer version uses stateMutability
  if o.has_key?( 'stateMutability' )
    case o[ 'stateMutability' ]
    when 'nonpayable'    ## default
      payable  = false
    when 'payable'
      payable  = true
    else
       pp o
       ## todo/fix: change to ParseError
       raise ArgumentError, "unexpected stateMutability (constructor) value ; got: #{ o[ 'stateMutability' ]}"
    end
  end

  ## check - assert "strict" abi version keys - why? why not?
  if o.has_key?( 'stateMutability' ) && (o.has_key?( 'payable') || o.has_key?( 'constant'))
    pp o
    puts "!! WARN:  ABI version mismatch? got stateMutability AND payable OR constant"
    exit 1
  end

  if o.has_key?( 'constant')
    pp o
    puts "!! WARN: constant for constructor possible?"
    exit 1
  end

  payable = o['payable']    if o.has_key?( 'payable')

  new( inputs: inputs,  payable: payable )
end

Instance Method Details

#declObject



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/abiparser/constructor.rb', line 98

def decl
  buf = "constructor"
  if @inputs.empty?
    buf << "()"
  else
    buf2 = @inputs.map {|param| param.decl }
    buf << "(#{buf2.join(', ')})"
  end
  buf << ";"
  buf
end

#docObject



87
88
89
90
91
92
93
94
95
96
# File 'lib/abiparser/constructor.rb', line 87

def doc
    buf = "constructor"
    if @inputs.empty?
      buf << "()"
    else
      buf2 = @inputs.map {|param| param.doc }
      buf << "(#{buf2.join(', ')})"
    end
    buf
end

#payable?Boolean

add - why? why not? def constant?() false; end alias_method :readonly?, :constant?

Returns:

  • (Boolean)


69
# File 'lib/abiparser/constructor.rb', line 69

def payable?() @payable; end

#sigObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/abiparser/constructor.rb', line 71

def sig
  ## note: signature
  ##  only includes name and inputs
  ##   excludes / drops outputs!!!

  buf = "constructor"
  if @inputs.empty?
    buf << "()"
  else
    buf2 = @inputs.map {|param| param.sig }
    buf << "(#{buf2.join(',')})"
  end
  buf
end