Skip to content
This repository has been archived by the owner on Aug 8, 2018. It is now read-only.

deploy_solidity_contract works with solc >= v0.4.9 #188

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions pyethapp/rpc_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" A simple way of interacting to a ethereum node through JSON RPC commands. """
import logging
import time
import os
import warnings
import json

Expand All @@ -9,7 +9,11 @@
from ethereum.keys import privtoaddr
from ethereum.transactions import Transaction
from ethereum.utils import denoms, int_to_big_endian, big_endian_to_int, normalize_address
from ethereum._solidity import solidity_unresolved_symbols, solidity_library_symbol, solidity_resolve_symbols
from ethereum._solidity import (
solidity_unresolved_symbols,
solidity_library_symbol,
solidity_resolve_symbols
)
from tinyrpc.protocols.jsonrpc import JSONRPCErrorResponse, JSONRPCSuccessResponse
from tinyrpc.protocols.jsonrpc import JSONRPCProtocol
from tinyrpc.transports.http import HttpPostClientTransport
Expand Down Expand Up @@ -208,14 +212,44 @@ def new_contract_proxy(self, contract_interface, address):
self.eth_estimateGas,
)

def deploy_solidity_contract(self, sender, contract_name, all_contracts, # pylint: disable=too-many-locals
libraries, constructor_parameters, timeout=None, gasprice=default_gasprice):
def deploy_solidity_contract(
self, # pylint: disable=too-many-locals
sender,
contract_name,
all_contracts,
libraries,
constructor_parameters,
contract_path=None,
timeout=None,
gasprice=default_gasprice
):
"""
Deploy a solidity contract.
Args:
sender (address): the sender address
contract_name (str): the name of the contract to compile
all_contracts (dict): the json dictionary containing the result of compiling a file
libraries (list): A list of libraries to use in deployment
constructor_parameters (tuple): A tuple of arguments to pass to the constructor
contract_path (str): If we are dealing with solc >= v0.4.9 then the path
to the contract is a required argument a required argument
to extract the contract data from the `all_contracts` dict.
timeout (int): Amount of time to poll the chain to confirm deployment
gasprice: The gasprice to provide for the transaction
"""

if contract_name not in all_contracts:
raise ValueError('Unkonwn contract {}'.format(contract_name))
if contract_name in all_contracts:
contract_key = contract_name
elif contract_path is not None:
_, filename = os.path.split(contract_path)
contract_key = filename + ":" + contract_name
if contract_key not in all_contracts:
raise ValueError('Unknown contract {}'.format(contract_name))
else:
raise ValueError('Unknown contract {} and no contract_path given'.format(contract_name))

libraries = dict(libraries)
contract = all_contracts[contract_name]
contract = all_contracts[contract_key]
contract_interface = contract['abi']
symbols = solidity_unresolved_symbols(contract['bin_hex'])

Expand All @@ -231,11 +265,11 @@ def deploy_solidity_contract(self, sender, contract_name, all_contracts, # pyli
raise Exception(msg)

dependencies = deploy_dependencies_symbols(all_contracts)
deployment_order = dependencies_order_of_build(contract_name, dependencies)
deployment_order = dependencies_order_of_build(contract_key, dependencies)

deployment_order.pop() # remove `contract_name` from the list

log.debug('Deploing dependencies: {}'.format(str(deployment_order)))
log.debug('Deploying dependencies: {}'.format(str(deployment_order)))

for deploy_contract in deployment_order:
dependency_contract = all_contracts[deploy_contract]
Expand Down