@@ -261,6 +261,34 @@ def compile_file(filepath, libraries=None, combined='bin,abi', optimize=True, ex
261
261
return solc_parse_output (output )
262
262
263
263
264
+ def solidity_get_contract_data (all_contracts , filepath , contract_name ):
265
+ """ A backwards compatible method of getting the contract data out
266
+ of a solc --combined-json output"""
267
+ try :
268
+ contract_data = all_contracts [contract_name ]
269
+ except :
270
+ if filepath is None :
271
+ filename = '<stdin>'
272
+ else :
273
+ _ , filename = os .path .split (filepath )
274
+ contract_data = all_contracts [filename + ":" + contract_name ]
275
+ return contract_data
276
+
277
+
278
+ def solidity_get_contract_key (all_contracts , filepath , contract_name ):
279
+ """ A backwards compatible method of getting the key to the all_contracts
280
+ dictionary for a particular contract"""
281
+ if contract_name in all_contracts :
282
+ return contract_name
283
+ else :
284
+ if filepath is None :
285
+ filename = '<stdin>'
286
+ else :
287
+ _ , filename = os .path .split (filepath )
288
+ contract_key = filename + ":" + contract_name
289
+ return contract_key if contract_key in all_contracts else None
290
+
291
+
264
292
def compile_contract (filepath , contract_name , libraries = None , combined = 'bin,abi' , optimize = True , extra_args = None ):
265
293
all_contracts = compile_file (
266
294
filepath ,
@@ -269,8 +297,7 @@ def compile_contract(filepath, contract_name, libraries=None, combined='bin,abi'
269
297
optimize = optimize ,
270
298
extra_args = extra_args
271
299
)
272
-
273
- return all_contracts [contract_name ]
300
+ return solidity_get_contract_data (all_contracts , filepath , contract_name )
274
301
275
302
276
303
def compile_last_contract (filepath , libraries = None , combined = 'bin,abi' , optimize = True , extra_args = None ):
@@ -335,7 +362,7 @@ def _code_or_path(sourcecode, path, contract_name, libraries, combined, extra_ar
335
362
last_contract = all_contract_names [- 1 ]
336
363
337
364
result = compile_code (sourcecode , libraries = libraries , combined = combined , extra_args = extra_args )
338
- return result [ last_contract ]
365
+ return solidity_get_contract_data ( result , path , last_contract )
339
366
340
367
@classmethod
341
368
def compile (cls , code , path = None , libraries = None , contract_name = '' , extra_args = None ):
@@ -378,7 +405,12 @@ def combined(cls, code, path=None, extra_args=None):
378
405
379
406
sorted_contracts = []
380
407
for name in solidity_names (code ):
381
- sorted_contracts .append ((name [1 ], contracts [name [1 ]]))
408
+ sorted_contracts .append (
409
+ (
410
+ name [1 ],
411
+ solidity_get_contract_data (contracts , path , name [1 ])
412
+ )
413
+ )
382
414
return sorted_contracts
383
415
384
416
@classmethod
0 commit comments