Skip to content

Commit

Permalink
Merge pull request #308 from fubuloubu/gas_cost_abi
Browse files Browse the repository at this point in the history
Modification of abi format to include gas cost estimate for functions…
  • Loading branch information
DavidKnott authored Sep 6, 2017
2 parents e1e7fb9 + 319f25c commit f879014
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions viper/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ def compile(code, *args, **kwargs):
return compile_lll.assembly_to_evm(compile_lll.compile_to_assembly(lll))


def mk_full_signature(code, *args, **kwargs):
o = parser.mk_full_signature(parser.parse(code))
return o


def gas_estimate(origcode, *args, **kwargs):
o = {}
code = optimizer.optimize(parser.parse_to_lll(origcode))
Expand All @@ -32,6 +27,18 @@ def gas_estimate(origcode, *args, **kwargs):
return o


def mk_full_signature(code, *args, **kwargs):
abi = parser.mk_full_signature(parser.parse(code))
# Add gas estimates for each function to ABI
gas_estimates = gas_estimate(code)
for idx, func in enumerate(abi):
func_name = func['name'].split('(')[0]
# Skip __init__, has no estimate
if func_name != '__init__':
abi[idx]['gas'] = gas_estimates[func_name]
return abi


# Dummy object, as some tools expect this interface
class Compiler(object):

Expand Down

0 comments on commit f879014

Please sign in to comment.