Skip to content

Commit f9e0953

Browse files
authored
Merge pull request #188 from ethereum/linker-legacy
Support old compilers (without contract file names) in linkBytecode
2 parents 6232150 + 03cab94 commit f9e0953

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

linker.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
var linkBytecode = function (bytecode, libraries) {
2+
// NOTE: for backwards compatibility support old compiler which didn't use file names
3+
var librariesComplete = {};
24
for (var libraryName in libraries) {
5+
var parsed = libraryName.match(/^([^:]*):?(.*)$/);
6+
if (parsed) {
7+
librariesComplete[parsed[2]] = libraries[libraryName];
8+
}
9+
librariesComplete[libraryName] = libraries[libraryName];
10+
}
11+
12+
for (libraryName in librariesComplete) {
313
// truncate to 37 characters
414
var internalName = libraryName.slice(0, 36);
515
// prefix and suffix with __
616
var libLabel = '__' + internalName + Array(37 - internalName.length).join('_') + '__';
717

8-
var hexAddress = libraries[libraryName];
18+
var hexAddress = librariesComplete[libraryName];
919
if (hexAddress.slice(0, 2) !== '0x' || hexAddress.length > 42) {
1020
throw new Error('Invalid address specified for ' + libraryName);
1121
}

0 commit comments

Comments
 (0)