Skip to content

Commit 495ca2d

Browse files
authored
Merge pull request #247 from ethereum/new-api
Support the new solc public methods (solidity_compile/solidity_version/solidity_license)
2 parents e5419cc + b2130fc commit 495ca2d

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

wrapper.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function setupMethods (soljson) {
1313
}
1414
var compileJSONCallback = null;
1515
var compileStandard = null;
16-
if (('_compileJSONCallback' in soljson) || ('_compileStandard' in soljson)) {
16+
if (('_compileJSONCallback' in soljson) || ('_compileStandard' in soljson) || ('_solidity_compile' in soljson)) {
1717
var copyString = function (str, ptr) {
1818
var length = soljson.lengthBytesUTF8(str);
1919
var buffer = soljson._malloc(length + 1);
@@ -65,6 +65,12 @@ function setupMethods (soljson) {
6565
return runWithReadCallback(readCallback, compileStandardInternal, [ input ]);
6666
};
6767
}
68+
if ('_solidity_compile' in soljson) {
69+
var solidityCompile = soljson.cwrap('solidity_compile', 'string', ['string', 'number']);
70+
compileStandard = function (input, readCallback) {
71+
return runWithReadCallback(readCallback, solidityCompile, [ input ]);
72+
};
73+
}
6874
}
6975

7076
var compile = function (input, optimise, readCallback) {
@@ -170,18 +176,27 @@ function setupMethods (soljson) {
170176
return translateOutput(compileJSON(sources[Object.keys(sources)[0]], isOptimizerEnabled(input)), libraries);
171177
};
172178

173-
var version = soljson.cwrap('version', 'string', []);
179+
var version;
180+
if ('_solidity_version' in soljson) {
181+
version = soljson.cwrap('solidity_version', 'string', []);
182+
} else {
183+
version = soljson.cwrap('version', 'string', []);
184+
}
174185

175186
var versionToSemver = function () {
176187
return translate.versionToSemver(version());
177188
};
178189

179-
var license = function () {
180-
// return undefined
181-
};
182-
183-
if ('_license' in soljson) {
190+
var license;
191+
if ('_solidity_license' in soljson) {
192+
license = soljson.cwrap('solidity_license', 'string', []);
193+
} else if ('_license' in soljson) {
184194
license = soljson.cwrap('license', 'string', []);
195+
} else {
196+
// pre 0.4.14
197+
license = function () {
198+
// return undefined
199+
};
185200
}
186201

187202
return {

0 commit comments

Comments
 (0)