Skip to content

Commit 7f71f09

Browse files
authored
Merge pull request #199 from ethereum/standardwrapper-link
Link bytecode if libraries were supplied in compileStandardWrapper
2 parents 7b10253 + faae7ef commit 7f71f09

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

linker.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@ var linkBytecode = function (bytecode, libraries) {
22
// NOTE: for backwards compatibility support old compiler which didn't use file names
33
var librariesComplete = {};
44
for (var libraryName in libraries) {
5-
var parsed = libraryName.match(/^([^:]*):?(.*)$/);
6-
if (parsed) {
7-
librariesComplete[parsed[2]] = libraries[libraryName];
5+
if (typeof libraryName === 'object') {
6+
// API compatible with the standard JSON i/o
7+
for (var lib in libraries[libraryName]) {
8+
librariesComplete[lib] = libraries[libraryName][lib];
9+
librariesComplete[libraryName + ':' + lib] = libraries[libraryName][lib];
10+
}
11+
} else {
12+
// backwards compatible API for early solc-js verisons
13+
var parsed = libraryName.match(/^([^:]*):?(.*)$/);
14+
if (parsed) {
15+
librariesComplete[parsed[2]] = libraries[libraryName];
16+
}
17+
librariesComplete[libraryName] = libraries[libraryName];
818
}
9-
librariesComplete[libraryName] = libraries[libraryName];
1019
}
1120

1221
for (libraryName in librariesComplete) {

translate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function translateGasEstimates (gasEstimates) {
5959
return gasEstimatesTranslated;
6060
}
6161

62-
function translateJsonCompilerOutput (output) {
62+
function translateJsonCompilerOutput (output, libraries) {
6363
var ret = {};
6464

6565
ret['errors'] = [];
@@ -110,13 +110,13 @@ function translateJsonCompilerOutput (output) {
110110
'evm': {
111111
'legacyAssembly': contractInput['assembly'],
112112
'bytecode': {
113-
'object': contractInput['bytecode'],
113+
'object': linker.linkBytecode(contractInput['bytecode'], libraries),
114114
'opcodes': contractInput['opcodes'],
115115
'sourceMap': contractInput['srcmap'],
116116
'linkReferences': linker.findLinkReferences(contractInput['bytecode'])
117117
},
118118
'deployedBytecode': {
119-
'object': contractInput['runtimeBytecode'],
119+
'object': linker.linkBytecode(contractInput['runtimeBytecode'], libraries),
120120
'sourceMap': contractInput['srcmapRuntime'],
121121
'linkReferences': linker.findLinkReferences(contractInput['runtimeBytecode'])
122122
},

wrapper.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ function setupMethods (soljson) {
135135
return sources;
136136
}
137137

138+
function librariesSupplied (input) {
139+
if (input['settings'] !== null) {
140+
return input['settings']['libraries'];
141+
}
142+
}
143+
138144
function translateOutput (output) {
139145
output = translate.translateJsonCompilerOutput(JSON.parse(output));
140146
if (output == null) {
@@ -148,17 +154,20 @@ function setupMethods (soljson) {
148154
return formatFatalError('Failed to process sources');
149155
}
150156

157+
// Try linking if libraries were supplied
158+
var libraries = librariesSupplied(input);
159+
151160
// Try to wrap around old versions
152161
if (compileJSONCallback !== null) {
153-
return translateOutput(compileJSONCallback(JSON.stringify({ 'sources': sources }), isOptimizerEnabled(input), readCallback));
162+
return translateOutput(compileJSONCallback(JSON.stringify({ 'sources': sources }), isOptimizerEnabled(input), readCallback), libraries);
154163
}
155164

156165
if (compileJSONMulti !== null) {
157-
return translateOutput(compileJSONMulti(JSON.stringify({ 'sources': sources }), isOptimizerEnabled(input)));
166+
return translateOutput(compileJSONMulti(JSON.stringify({ 'sources': sources }), isOptimizerEnabled(input)), libraries);
158167
}
159168

160169
// Try our luck with an ancient compiler
161-
return translateOutput(compileJSON(sources[Object.keys(sources)[0]], isOptimizerEnabled(input)));
170+
return translateOutput(compileJSON(sources[Object.keys(sources)[0]], isOptimizerEnabled(input)), libraries);
162171
};
163172

164173
var version = soljson.cwrap('version', 'string', []);

0 commit comments

Comments
 (0)