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

Commit d1c9f39

Browse files
committed
deploy_solidity_contract works with solc >= v040
1 parent afc8f66 commit d1c9f39

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

pyethapp/rpc_client.py

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
""" A simple way of interacting to a ethereum node through JSON RPC commands. """
22
import logging
3-
import time
3+
import os
44
import warnings
55
import json
66

@@ -9,7 +9,11 @@
99
from ethereum.keys import privtoaddr
1010
from ethereum.transactions import Transaction
1111
from ethereum.utils import denoms, int_to_big_endian, big_endian_to_int, normalize_address
12-
from ethereum._solidity import solidity_unresolved_symbols, solidity_library_symbol, solidity_resolve_symbols
12+
from ethereum._solidity import (
13+
solidity_unresolved_symbols,
14+
solidity_library_symbol,
15+
solidity_resolve_symbols
16+
)
1317
from tinyrpc.protocols.jsonrpc import JSONRPCErrorResponse, JSONRPCSuccessResponse
1418
from tinyrpc.protocols.jsonrpc import JSONRPCProtocol
1519
from tinyrpc.transports.http import HttpPostClientTransport
@@ -208,14 +212,42 @@ def new_contract_proxy(self, contract_interface, address):
208212
self.eth_estimateGas,
209213
)
210214

211-
def deploy_solidity_contract(self, sender, contract_name, all_contracts, # pylint: disable=too-many-locals
212-
libraries, constructor_parameters, timeout=None, gasprice=default_gasprice):
215+
def deploy_solidity_contract(
216+
self, # pylint: disable=too-many-locals
217+
sender,
218+
contract_name,
219+
all_contracts,
220+
libraries,
221+
constructor_parameters,
222+
contract_path=None,
223+
timeout=None,
224+
gasprice=default_gasprice
225+
):
226+
"""
227+
Deploy a solidity contract.
228+
Args:
229+
sender (address): the sender address
230+
contract_name (str): the name of the contract to compile
231+
all_contracts (dict): the json dictionary containing the result of compiling a file
232+
libraries (list): A list of libraries to use in deployment
233+
constructor_parameters (tuple): A tuple of arguments to pass to the constructor
234+
contract_path (str): If given then we are dealing with solc >= v0.4.9 and is
235+
a required argument to extract the contract data from the
236+
`all_contracts` dict.
237+
timeout (int): Amount of time to poll the chain to confirm deployment
238+
gasprice: The gasprice to provide for the transaction
239+
"""
213240

214-
if contract_name not in all_contracts:
215-
raise ValueError('Unkonwn contract {}'.format(contract_name))
241+
if contract_path is None:
242+
if contract_name not in all_contracts:
243+
raise ValueError('Unknown contract {}'.format(contract_name))
244+
contract_key = contract_name
245+
else:
246+
_, filename = os.path.split(contract_path)
247+
contract_key = filename + ":" + contract_name
216248

217249
libraries = dict(libraries)
218-
contract = all_contracts[contract_name]
250+
contract = all_contracts[contract_key]
219251
contract_interface = contract['abi']
220252
symbols = solidity_unresolved_symbols(contract['bin_hex'])
221253

@@ -231,11 +263,11 @@ def deploy_solidity_contract(self, sender, contract_name, all_contracts, # pyli
231263
raise Exception(msg)
232264

233265
dependencies = deploy_dependencies_symbols(all_contracts)
234-
deployment_order = dependencies_order_of_build(contract_name, dependencies)
266+
deployment_order = dependencies_order_of_build(contract_key, dependencies)
235267

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

238-
log.debug('Deploing dependencies: {}'.format(str(deployment_order)))
270+
log.debug('Deploying dependencies: {}'.format(str(deployment_order)))
239271

240272
for deploy_contract in deployment_order:
241273
dependency_contract = all_contracts[deploy_contract]

0 commit comments

Comments
 (0)