Commit 01b761c6 authored by chriseth's avatar chriseth

Merge pull request #58 from d11e9/legacyNpm

Legacy npm
parents 87e8f940 65fb2a47
...@@ -29,3 +29,15 @@ Starting from version 0.1.6, multiple files are supported with automatic import ...@@ -29,3 +29,15 @@ Starting from version 0.1.6, multiple files are supported with automatic import
console.log(contractName + ': ' + output.contracts[contractName].bytecode); console.log(contractName + ': ' + output.contracts[contractName].bytecode);
Note that all input files that are imported have to be supplied, the compiler will not load any additional files on its own. Note that all input files that are imported have to be supplied, the compiler will not load any additional files on its own.
###Using a legacy version
In order to allow compiling contracts using a specific version of solidity, the `solc.useVersion` method is available. This returns a new solc object using the version provided. **Note**: version strings must match the version substring of the files availble in `/bin/soljson-*.js`. See below for an example.
var solc = require('solc');
// by default the latest version is used
// ie: solc.useVersion('latest')
// getting a legacy version
var solcV011 = solc.useVersion( 'v0.1.1-2015-08-04-6ff4cd6' );
var output = solcV011.compile( "contract t { function g() {} }", 1 );
function setupMethods (soljson){
var soljson = require('./bin/soljson-latest.js'); var compileJSON = soljson.cwrap("compileJSON", "string", ["string", "number"]);
var compileJSONMulti =
var compileJSON = soljson.cwrap("compileJSON", "string", ["string", "number"]);
var compileJSONMulti =
'_compileJSONMulti' in soljson ? '_compileJSONMulti' in soljson ?
soljson.cwrap("compileJSONMulti", "string", ["string", "number"]) : soljson.cwrap("compileJSONMulti", "string", ["string", "number"]) :
null; null;
var compile = function(input, optimise) { var compile = function(input, optimise) {
var result = ''; var result = '';
if (typeof(input) != typeof('') && compileJSONMulti !== null) if (typeof(input) != typeof('') && compileJSONMulti !== null)
result = compileJSONMulti(JSON.stringify(input), optimise); result = compileJSONMulti(JSON.stringify(input), optimise);
else else
result = compileJSON(input, optimise); result = compileJSON(input, optimise);
return JSON.parse(result); return JSON.parse(result);
} }
var version = soljson.cwrap("version", "string", []);
module.exports = { return {
version: version,
compile: compile, compile: compile,
version: soljson.cwrap("version", "string", []) useVersion: function( versionString ){
return setupMethods( require('./bin/soljson-' + versionString + '.js' ) );
}
}
} }
module.exports = setupMethods( require('./bin/soljson-latest.js') );
{ {
"name": "solc", "name": "solc",
"version": "0.1.6", "version": "0.1.6-2",
"description": "Solidity compiler", "description": "Solidity compiler",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment