Example #1
0
def transpile(clss, target="deploy"):
    if target not in ["deploy", "abi", "bytecode", "lll", "vyper", "vy"]:
        raise ValueError("Unrecognized target for transpilation")
    if type(clss) is Lll:
        #todo: need to rework this
        if target == "bytecode":
            asm = compile_to_assembly(clss.node)
            return '0x' + assembly_to_evm(asm).hex()
        raise ValueError("lll can only be compiled to bytecode for now")

    vyp = python_to_vyper(clss)

    if target == "vyper" or target == "vy":
        return vyp

    if target == "bytecode":
        return Bytecode('0x' + compiler.compile(str(vyp)).hex())

    if target == "abi":
        return Abi(compiler.mk_full_signature(str(vyp)))

    if target == "deploy":
        abi = Abi(compiler.mk_full_signature(str(vyp)))
        bytecode = Bytecode('0x' + compiler.compile(str(vyp)).hex())
        return Deploy(abi, bytecode)

    return Lll(optimizer.optimize(parse_to_lll(str(vyp))))
Example #2
0
def gas_estimate(origcode, *args, **kwargs):
    o = {}
    code = optimizer.optimize(parser.parse_to_lll(origcode))

    # Extract the stuff inside the LLL bracket
    if code.value == 'seq':
        if code.args[-1].value == 'return':
            code = code.args[-1].args[1].args[0]
    else:
        code = code.args[1].args[0]
    assert code.value == 'seq'
    for arg in code.args:
        if hasattr(arg, 'func_name'):
            o[arg.func_name] = arg.total_gas
    return o