Example #1
0
def send(transaction):
    if "from" in transaction:
        addr = strip_0x(transaction['from']).decode("hex")
        sender = keys[accounts.index(addr)]
    else:
        sender = keys[0]

    if "value" in transaction:
        value = int(strip_0x(transaction['value']), 16)
    else:
        value = 0

    if "to" in transaction:
        to = strip_0x(transaction['to'])
    else:
        to = None

    if "data" in transaction:
        data = strip_0x(transaction['data']).decode("hex")
    else:
        data = ""

    if "gas" in transaction:
        gas = int(strip_0x(transaction['gas']), 16)
    else:
        gas = None

    # print "value: " + value.encode("hex")
    # print "to: " + to
    # print "from: " + accounts[keys.index(sender)].encode("hex")
    # print "data: " + data.encode("hex")
    # print "gas: " + str(gas)

    if isContract(transaction):
        estimated_cost = len(data.encode("hex")) / 2 * 200

        print "Adding contract..."
        print "Estimated gas cost: " + str(estimated_cost)

        if gas != None and estimated_cost > gas:
            print "* "
            print "* WARNING: Estimated cost higher than sent gas: " + str(
                estimated_cost) + " > " + str(gas)
            print "* "

        r = evm.evm(data, sender, value, gas).encode("hex")
    else:
        r = evm.send(sender, to, value, data, gas).encode("hex")

    r = "0x" + r
    return r
Example #2
0
def send(transaction):
    if "from" in transaction:
        addr = decode_hex(strip_0x(transaction['from']))
        sender = keys[accounts.index(addr)]
    else:
        sender = keys[0]

    if "value" in transaction:
        value = int(strip_0x(transaction['value']), 16)
    else:
        value = 0

    if "to" in transaction:
        to = strip_0x(transaction['to'])
    else:
        to = None

    if "data" in transaction:
        data = decode_hex(strip_0x(transaction['data']))
    else:
        data = ""

    if "gas" in transaction:
        gas = int(strip_0x(transaction['gas']), 16)
    else:
        gas = None

    # print("value: " + encode_hex(value))
    # print("to: " + to)
    # print("from: " + encode_hex(accounts[keys.index(sender)]))
    # print("data: " + encode_hex(data))
    # print("gas: " + str(gas))

    if isContract(transaction):
        estimated_cost = len(encode_hex(data)) / 2 * 200

        print("Adding contract...")
        print("Estimated gas cost: " + str(estimated_cost))

        if gas != None and estimated_cost > gas:
            print("* ")
            print("* WARNING: Estimated cost higher than sent gas: " + str(estimated_cost) + " > " + str(gas))
            print("* ")

        r = encode_hex(evm.evm(data, sender, value, gas))
    else:
        r = encode_hex(evm.send(sender, to, value, data, gas))

    r = "0x" + r
    return r
Example #3
0
def send(transaction):
    if "from" in transaction:
        addr = strip_0x(transaction['from']).decode("hex")
        sender = keys[accounts.index(addr)]
    else:
        sender = keys[0]

    if "value" in transaction:
        value = int(strip_0x(transaction['value']), 16)
    else:
        value = 0

    if "to" in transaction:
        to = strip_0x(transaction['to'])
    else:
        to = None

    if "data" in transaction:
        data = strip_0x(transaction['data']).decode("hex")
    else:
        data = ""

    if "gas" in transaction:
        gas = int(strip_0x(transaction['gas']), 16)
    else:
        gas = None

    # print "value: " + value.encode("hex")
    # print "to: " + to
    # print "from: " + accounts[keys.index(sender)].encode("hex")
    # print "data: " + data.encode("hex")
    # print "gas: " + str(gas)

    if isContract(transaction):
        estimated_cost = len(data.encode("hex")) / 2 * 200

        print "Adding contract..."
        print "Estimated gas cost: " + str(estimated_cost)

        if gas != None and estimated_cost > gas:
            print "* "
            print "* WARNING: Estimated cost higher than sent gas: " + str(estimated_cost) + " > " + str(gas)
            print "* "

        r = evm.evm(data, sender, value, gas).encode("hex")
    else:
        r = evm.send(sender, to, value, data, gas).encode("hex")

    r = "0x" + r
    return r