Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function compileContract(name, filename) {
console.log('compiling contract', name);
var input = fs.readFileSync(filename).toString();
var sources = {};
sources[filename] = input;
var output = solc.compile({ sources: sources }, 1, findImports); // 1 activates the optimiser
return output.contracts[name];
}
const compile = async (filename) => {
filename = filename.replace('.sol', '')
const filePath = path.join(CONTRACTS_PATH, filename + '.sol')
const source = fs.readFileSync(filePath, 'utf-8')
// grabs the contract reference
const compiled = solc.compile(source, 1)
const contract = compiled.contracts[':' + filename]
if (contract) {
console.log(' OK!')
}
if (compiled.errors) {
if (contract) {
console.log('warnings:')
} else {
console.log('errors:')
}
console.log(compiled.errors)
}
before(function(done) {
this.timeout(10000);
// Compile first
var result = solc.compile(fs.readFileSync("./test/Example.sol", {encoding: "utf8"}), 1);
// Clean up after solidity. Only remove solidity's listener,
// which happens to be the first.
process.removeListener("uncaughtException", process.listeners("uncaughtException")[0]);
var compiled = Schema.normalize(result.contracts["Example"]);
abi = compiled.abi;
binary = compiled.bytecode;
// Setup
var dirPath = temp.mkdirSync({
dir: path.resolve("./"),
prefix: 'tmp-test-contract-'
});
var expected_filepath = path.join(dirPath, "Example.json");
async function main() {
console.log("Compiling contracts...");
var inputs = {};
for (contract of Contracts){
var parts = contract.split(':');
inputs[contract+'.sol'] = fs.readFileSync("./contracts/"+parts[0]+".sol", 'utf8');
}
try{
var output = solc.compile({ sources: inputs }, 1, findImports)
}
catch(error){
console.log(error);
}
for (err in output.errors){
console.log(output.errors[err]);
}
if (!output.contracts || Object.keys(output.contracts).length == 0){
throw("Didn't compile");
}
// new RegExp('__([a-zA-Z.:]+)[_]*', 'g');
// const libraryRE = /__([a-zA-Z.:]+)[_]*/g.compile();
const libraryRE = new RegExp('__([a-zA-Z.:]+)[_]*', 'g');
for (var property in output.contracts) {
if (output.contracts.hasOwnProperty(property)) {
var contract = output.contracts[property];
function compileContracts(source_files) {
// Load the inputs
const sources = {};
for ( const file of source_files ) {
sources[file] = fs.readFileSync(file).toString();
}
// Compile the input
const output = solc.compile({
sources: sources
}, 1);
console.log(23423,output);
const result = {};
// Parse all compiled contracts
for ( const k in output.contracts ) {
// Find which contract was compiled
const contractKey = k.split(':').pop();
const contract = output.contracts[k];
// Get the bytecode and ABI
const bytecode = contract.bytecode;
const abi = JSON.parse(contract.interface);
result[contractKey] = {
const MAIN_ADDRESS = web.eth.accounts[ 0 ];
//web.personal.unlockAccount( MAIN_ADDRESS, "" );
//console.log( MAIN_ADDRESS, web.eth.getBalance( MAIN_ADDRESS ).toNumber() );
//Code
const GAME_SOL = __dirname + "/../contracts/sheet-music.sol";
const GAME_CODE = FS.readFileSync( GAME_SOL ).toString();
//Main
var compiled = Solc.compile( GAME_CODE );
if( compiled.errors ) {
console.log( "ERRORS/WARNINGS:" );
console.log( compiled.errors );
}
if( compiled.contracts[ ":SheetMusic" ] ) {
compile( compiled.contracts[ ":SheetMusic" ], "sheet-music" );
} else {
throw new Error( "Failed to compile" );
var solc = require('solc')
module.exports = solc.compile(`
contract MyContract {
}
`)
_compileAndClean(filePath) {
try {
let source = fs.readFileSync(filePath, { encoding: 'utf8' })
let compiled = solc.compile(source, 1)
if (compiled.errors) return [compiled.errors, null]
let contractName = getContractName(filePath)
let cleaned = this._clean(compiled, contractName)
return [null, cleaned]
}
catch(e) {
throw(e)
}
}
async function getAbis() {
const output = await solc.compile({ sources: input }, 1);
erc20Abi = output.contracts["ERC20Interface.sol:ERC20"].interface;
networkAbi = output.contracts["KyberNetwork.sol:KyberNetwork"].interface;
feeBurnerAbi = output.contracts["FeeBurner.sol:FeeBurner"].interface;
feeBurnerWrapperAbi = output.contracts["WrapFeeBurner.sol:WrapFeeBurner"].interface;
}
const input = {
language: 'Solidity',
sources: srcObject,
settings: {
optimizer: {
enabled: true,
runs: 200
},
outputSelection: {
'*': {
'*': ['*']
}
}
}
}
const compiledContracts = JSON.parse(solc.compile(JSON.stringify(input), findImports))
if (compiledContracts.errors) throw compiledContracts.errors.map(err => err.formattedMessage).join('\n')
this.createDirectoryIfNotExists('build/contracts')
await Promise.all(
Object.entries(compiledContracts.contracts).map(array =>
Promise.all(
Object.entries(array[1]).map(([contractName, jsonObject]) =>
fsPromise.writeFile(`${process.cwd()}/build/contracts/${contractName}.json`, JSON.stringify(jsonObject, null, '\t'))
)
)
)
)
}