Skip to content

Commit de0a3ce

Browse files
committed
Backport new callback API to 0.5
1 parent 586d1c1 commit de0a3ce

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ It also accepts an optional callback function to resolve unmet dependencies. Thi
4646
It cannot be used together with callback-based, asynchronous, filesystem access. A workaround is to collect the names of dependencies, return an error, and keep re-running the compiler until all
4747
of them are resolved.
4848

49+
Starting 0.5.12 it also accepts an object in place of the callback to supply different kind of callbacks, however only file imports are supported.
50+
4951
*Note*: as an intermittent backwards compatibility feature, between versions 0.5.0 and 0.5.2, `compileStandard` and `compileStandardWrapper` also exists and behave like `compile` does.
5052

5153
#### Example usage without the import callback
@@ -106,8 +108,12 @@ function findImports (path) {
106108
return { error: 'File not found' }
107109
}
108110

111+
// Current syntax
109112
var output = JSON.parse(solc.compile(JSON.stringify(input), findImports))
110113

114+
// New syntax (supported from 0.5.12)
115+
var output = JSON.parse(solc.compile(JSON.stringify(input), { import: findImports }))
116+
111117
// `output` here contains the JSON output as specified in the documentation
112118
for (var contractName in output.contracts['test.sol']) {
113119
console.log(contractName + ': ' + output.contracts['test.sol'][contractName].evm.bytecode.object)

test/package.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ tape('Compilation', function (t) {
435435
var L = getBytecodeStandard(output, 'lib.sol', 'L');
436436
st.ok(L);
437437
st.ok(L.length > 0);
438+
439+
var outputNewApi = JSON.parse(solc.compile(JSON.stringify(input), { import: findImports }));
440+
st.deepEqual(output, outputNewApi);
438441
st.end();
439442
});
440443

wrapper.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ function setupMethods (soljson) {
2727

2828
// This calls compile() with args || cb
2929
var runWithReadCallback = function (readCallback, compile, args) {
30+
// Forward compatibility with 0.6.x
31+
if (typeof readCallback === 'object') {
32+
readCallback = readCallback.import;
33+
}
34+
3035
if (readCallback === undefined) {
3136
readCallback = function (path) {
3237
return {

0 commit comments

Comments
 (0)