@@ -17,6 +17,10 @@ class CompileError(Exception):
17
17
pass
18
18
19
19
20
+ class SolcMissing (Exception ):
21
+ pass
22
+
23
+
20
24
def get_compiler_path ():
21
25
""" Return the path to the solc compiler.
22
26
@@ -261,6 +265,34 @@ def compile_file(filepath, libraries=None, combined='bin,abi', optimize=True, ex
261
265
return solc_parse_output (output )
262
266
263
267
268
+ def solidity_get_contract_data (all_contracts , filepath , contract_name ):
269
+ """ A backwards compatible method of getting the contract data out
270
+ of a solc --combined-json output"""
271
+ try :
272
+ contract_data = all_contracts [contract_name ]
273
+ except :
274
+ if filepath is None :
275
+ filename = '<stdin>'
276
+ else :
277
+ _ , filename = os .path .split (filepath )
278
+ contract_data = all_contracts [filename + ":" + contract_name ]
279
+ return contract_data
280
+
281
+
282
+ def solidity_get_contract_key (all_contracts , filepath , contract_name ):
283
+ """ A backwards compatible method of getting the key to the all_contracts
284
+ dictionary for a particular contract"""
285
+ if contract_name in all_contracts :
286
+ return contract_name
287
+ else :
288
+ if filepath is None :
289
+ filename = '<stdin>'
290
+ else :
291
+ _ , filename = os .path .split (filepath )
292
+ contract_key = filename + ":" + contract_name
293
+ return contract_key if contract_key in all_contracts else None
294
+
295
+
264
296
def compile_contract (filepath , contract_name , libraries = None , combined = 'bin,abi' , optimize = True , extra_args = None ):
265
297
all_contracts = compile_file (
266
298
filepath ,
@@ -269,8 +301,7 @@ def compile_contract(filepath, contract_name, libraries=None, combined='bin,abi'
269
301
optimize = optimize ,
270
302
extra_args = extra_args
271
303
)
272
-
273
- return all_contracts [contract_name ]
304
+ return solidity_get_contract_data (all_contracts , filepath , contract_name )
274
305
275
306
276
307
def compile_last_contract (filepath , libraries = None , combined = 'bin,abi' , optimize = True , extra_args = None ):
@@ -296,7 +327,10 @@ def compile_last_contract(filepath, libraries=None, combined='bin,abi', optimize
296
327
297
328
def compile_code (sourcecode , libraries = None , combined = 'bin,abi' , optimize = True , extra_args = None ):
298
329
args = solc_arguments (libraries = libraries , combined = combined , optimize = optimize , extra_args = extra_args )
299
- args .insert (0 , get_compiler_path ())
330
+ compiler = get_compiler_path ()
331
+ if compiler is None :
332
+ raise SolcMissing ("solc not found" )
333
+ args .insert (0 , compiler )
300
334
301
335
process = subprocess .Popen (args , stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
302
336
stdoutdata , stderrdata = process .communicate (input = utils .to_string (sourcecode ))
@@ -335,7 +369,7 @@ def _code_or_path(sourcecode, path, contract_name, libraries, combined, extra_ar
335
369
last_contract = all_contract_names [- 1 ]
336
370
337
371
result = compile_code (sourcecode , libraries = libraries , combined = combined , extra_args = extra_args )
338
- return result [ last_contract ]
372
+ return solidity_get_contract_data ( result , path , last_contract )
339
373
340
374
@classmethod
341
375
def compile (cls , code , path = None , libraries = None , contract_name = '' , extra_args = None ):
@@ -378,7 +412,12 @@ def combined(cls, code, path=None, extra_args=None):
378
412
379
413
sorted_contracts = []
380
414
for name in solidity_names (code ):
381
- sorted_contracts .append ((name [1 ], contracts [name [1 ]]))
415
+ sorted_contracts .append (
416
+ (
417
+ name [1 ],
418
+ solidity_get_contract_data (contracts , path , name [1 ])
419
+ )
420
+ )
382
421
return sorted_contracts
383
422
384
423
@classmethod
0 commit comments