296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
# File 'lib/rubysol/generator.rb', line 296
def self.mapping_getter_function( contract_class, name, type )
name = name.to_sym
index = 0
current_type = type
sig_args = []
while current_type.mapping? do
sig_args << current_type.key_type
current_type = current_type.value_type
index += 1
end
puts "[debug] auto-generate public mapping getter - #{name} : #{type} (#{contract_class.name}):"
puts "sig_args:"
pp sig_args
puts " index: #{index}"
sig_args = sig_args.map {|sig_arg| typeof(sig_arg) }
contract_class.sigs[ name ] = { inputs: sig_args,
outputs: [typeof(current_type)],
options: [:view, :public] }
contract_class.sigs_exclude << name
puts contract_class.sigs[ name ].pretty_print_inspect
contract_class.class_eval do
define_method name do |arg0:, arg1: nil, arg2: nil, arg3: nil|
puts "[debug] call public (state) mapping getter for #{name} : #{type} - index: #{index} (#{contract_class.name})"
puts "[debug] self -> #{self}"
args = [arg0, arg1, arg2, arg3]
puts "[debug] args -> #{args.pretty_print_inspect}"
value = instance_variable_get( "@#{name}" )
(0...index).each do |i|
value = value[ args[i] ]
end
value
end
end
typed_function( contract_class, name, inputs: sig_args )
end
|