@@ -335,9 +335,15 @@ function processContracts({
335
335
originalSourcePaths,
336
336
solcVersion
337
337
} ) {
338
- if ( ! compilerOutput . contracts ) return [ ] ;
338
+ let { contracts } = compilerOutput ;
339
+ if ( ! contracts ) return [ ] ;
340
+ //HACK: versions of Solidity prior to 0.4.20 are confused by our "project:/"
341
+ //prefix (or, more generally, by paths containing colons)
342
+ //and put contracts in a weird form as a result. we detect
343
+ //this case and repair it.
344
+ contracts = repairOldContracts ( contracts ) ;
339
345
return (
340
- Object . entries ( compilerOutput . contracts )
346
+ Object . entries ( contracts )
341
347
// map to [[{ source, contractName, contract }]]
342
348
. map ( ( [ sourcePath , sourceContracts ] ) =>
343
349
Object . entries ( sourceContracts ) . map ( ( [ contractName , contract ] ) => ( {
@@ -418,6 +424,40 @@ function processContracts({
418
424
) ;
419
425
}
420
426
427
+ function repairOldContracts ( contracts ) {
428
+ const contractNames = [ ] . concat (
429
+ ...Object . values ( contracts ) . map ( source => Object . keys ( source ) )
430
+ ) ;
431
+ if ( contractNames . some ( name => name . includes ( ":" ) ) ) {
432
+ //if any of the "contract names" contains a colon... hack invoked!
433
+ //(notionally we could always apply this hack but let's skip it most of the
434
+ //time please :P )
435
+ let repairedContracts = { } ;
436
+ for ( const [ sourcePrefix , sourceContracts ] of Object . entries ( contracts ) ) {
437
+ for ( const [ mixedPath , contract ] of Object . entries ( sourceContracts ) ) {
438
+ let sourcePath , contractName ;
439
+ const lastColonIndex = mixedPath . lastIndexOf ( ":" ) ;
440
+ if ( lastColonIndex === - 1 ) { //if there is none
441
+ sourcePath = sourcePrefix ;
442
+ contractName = mixedPath ;
443
+ } else {
444
+ contractName = mixedPath . slice ( lastColonIndex + 1 ) ; //take the part after the final colon
445
+ sourcePath = sourcePrefix + ":" + mixedPath . slice ( 0 , lastColonIndex ) ; //the part before the final colon
446
+ }
447
+ if ( ! repairedContracts [ sourcePath ] ) {
448
+ repairedContracts [ sourcePath ] = { } ;
449
+ }
450
+ repairedContracts [ sourcePath ] [ contractName ] = contract ;
451
+ }
452
+ }
453
+ debug ( "repaired contracts: %O" , repairedContracts ) ;
454
+ return repairedContracts ;
455
+ } else {
456
+ //otherwise just return contracts as-is rather than processing
457
+ return contracts ;
458
+ }
459
+ }
460
+
421
461
function formatLinkReferences ( linkReferences ) {
422
462
if ( ! linkReferences ) {
423
463
return [ ] ;
0 commit comments