Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let file_folder = answers['file_folder'];
console.log('Current working directory: '+file_folder)
// make sure the file to be compiled in under current folder
var file_path = file_folder +'/'+file_name;
console.log('File being compiled and compared: '+file_name);
// read contract file as input or log err message otherwise
var input = fs.readFileSync(file_path,'utf8');
var bytecode_from_compiler;
var bytecode_from_blockchain;
console.log('==========================================')
console.log('Compiler Version: '+solc_version)
// use specified solc version on the fly by loading from github
console.log(chalk.bold.green('Compiling in progress, ')+' Please be patient...')
solc.loadRemoteVersion(solc_version, function(err, solc_specific){
if(err){
console.log('Solc failed to loaded'+err);
}
var input_json = { language: "Solidity",
sources:
{file: {"content": input} },
settings: {
optimizer: {
// disabled by default
enabled: is_optimized,
runs: 200
},
outputSelection: {
"*": {
"*": [ "*" ]
"compilerVersion": version,
"optimization": optimization,
"contractName": name,
"sourceCode": input
}
console.log(version)
try {
// latest version doesn't need to be loaded remotely
if (version == "latest") {
var output = solc.compile(input, optimise);
testValidCode(output, data, bytecode, res);
} else {
solc.loadRemoteVersion(version, function(err, solcV) {
if (err) {
console.error(err);
res.write(JSON.stringify({"valid": false}));
res.end();
}
else {
var output = solcV.compile(input, optimise);
testValidCode(output, data, bytecode, res);
}
});
}
return;
} catch (e) {
console.error(e.stack);
}
var contract_address = process.argv[4];
// get choice of optimization (0:no,1:yes) from the fourth param on the terminal console
var is_optimized = process.argv[5];
// get the current folder path
var file_folder = __dirname;
// make sure the file to be compiled in under current folder
var file_path = file_folder +'/'+file_name;
// read contract file as input or log err message otherwise
var input = fs.readFileSync(file_path,'utf8');
var bytecode_from_compiler;
var bytecode_from_blockchain;
console.log('==========================================')
console.log('Compiler Version: '+solc_version)
// use specified solc version on the fly by loading from github
solc.loadRemoteVersion(solc_version, function(err, solc_specific){
if(err){
console.log('Solc failed to loaded'+err);
}
// if solc successfully loaded, compile the contract and get the JSON output
var output = solc_specific.compile(input, is_optimized);
// get bytecode from JSON output
var bytecode = output['contracts'][':'+''+file_name.slice(0,file_name.length-4)]['bytecode'];
// every bytecode starts with a fixed opcode: "PUSH1 0x60 PUSH1 0x40 MSTORE"
// which is 6060604052 in bytecode whose length is 10
var fixed_prefix= bytecode.slice(0,10);
// every bytecode from compiler would have constructor bytecode inserted before actual deployed code.
// the starting point is a fixed opcode: "CALLDATASIZE ISZERO"
// which is 3615 in bytecode
var starting_point = bytecode.search('3615');
var remaining_part = bytecode.slice(starting_point);
// a165627a7a72305820 is a fixed prefix of swarm info that was appended to contract bytecode
return new Promise((resolve, reject) => {
// tslint:disable-next-line:no-any
solc.loadRemoteVersion(ver, (err: any, solcSnapshot: any) => {
if (err) {
reject(err);
} else {
solcSnapshots[ver] = solcSnapshot;
resolve(solcSnapshot);
}
});
});
};
return new Promise((resolve, reject) => {
cli.info(`Compiling with Solidity version: ${solcVersion}`)
solc.loadRemoteVersion(solcVersion, (err, solcSnapshot) => {
if (err) {
reject(err)
} else {
let compiled = JSON.parse(solcSnapshot.compile(JSON.stringify(input), findImports))
// Reject if there are errors
if (compiled.errors !== undefined) {
for (let e of compiled.errors) {
if (e.severity === 'error') {
reject(compiled)
}
}
}
resolve({compiled, importedFiles})
}
(async () => {
let metadata_raw = (await read(process.stdin)).trim();
let metadata = JSON.parse(metadata_raw);
let input = {};
input['settings'] = metadata['settings'];
let fileName = '';
let contractName = '';
for (fileName in metadata['settings']['compilationTarget'])
contractName = metadata['settings']['compilationTarget'][fileName];
delete input['settings']['compilationTarget']
console.log('Re-compiling ' + fileName + ':' + contractName + ' with Solidity ' + metadata['compiler']['version']);
console.log('Retrieving compiler...');
solcjs.loadRemoteVersion('v' + metadata['compiler']['version'], (error, solcjs) => {
if (error) throw error;
input['sources'] = retrieveSources(metadata['sources']);
input['language'] = metadata['language'];
input['settings']['metadata'] = input['settings']['metadata'] || {}
delete input['settings']['useLiteralContent'];
//input['settings']['metadata']['useLiteralContent'] = true;
input['settings']['outputSelection'] = input['settings']['outputSelection'] || {}
input['settings']['outputSelection'][fileName] = input['settings']['outputSelection'][fileName] || {}
input['settings']['outputSelection'][fileName][contractName] = ['evm.bytecode', 'metadata'];
console.log('Compiling...');
let output = JSON.parse(solcjs.compile(JSON.stringify(input)));
console.log('Bytecode: ' + output['contracts'][fileName][contractName]['evm']['bytecode']['object'])
console.log('Metadata: ' + output['contracts'][fileName][contractName]['metadata']);
if (output['contracts'][fileName][contractName]['metadata'].trim() != metadata_raw)
const solc = require('solc');
const Web3 = require('web3');
const fs = require('fs');
var input = fs.readFileSync("MultiSigWallet.sol", "utf8");
var web3 = new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:8545"));
solc.loadRemoteVersion("v0.4.15+commit.bbb8e64f", function(err, solc_specific) {
if (err) {
console.log("Solc failed to load: " + err);
return;
}
var output = solc_specific.compile(input, 1);
var bytecode = output.contracts[":MultiSigWallet"].bytecode;
var abi = JSON.parse(output.contracts[":MultiSigWallet"].interface);
console.log(output.contracts[":MultiSigWallet"].interface);
var contract = new web3.eth.Contract(abi);
console.log("Compiling finished, deploying the contract ...");
contract.deploy({
data: "0x" + bytecode,
arguments: [[
return await new Promise((resolve, reject) => {
solc.loadRemoteVersion(releaseVersion, (error, remoteSolc) => {
if (error) {
reject("wallet.cannot_load_solidity_version");
} else {
solcRefs[version] = remoteSolc;
resolve(remoteSolc);
}
});
});
};
import fs from 'fs';
import path from 'path';
import solc, { SolcCompiler } from 'solc';
import {promisify} from 'util';
import {readFileContent} from '../utils';
import BaseWrapper, {ContractJson} from './baseWrapper';
const loadRemoteVersion = promisify(solc.loadRemoteVersion);
class SolcjsWrapper extends BaseWrapper {
protected solc: SolcCompiler;
public async findInputs(files: string[]) {
return Object.assign({}, ...files.map((file) => ({[file]: readFileContent(file)})));
}
protected convertSources(sources: Record) {
const convertedSources: Record = {};
Object.keys(sources).map((key) => convertedSources[key.replace(/\\/g, '/')] = {content: sources[key]});
return convertedSources;
}
protected async loadCompiler() {
if (this.solc) {
import solc from 'solc';
import {promisify} from 'util';
import {readFileContent, isDirectory, relativePathToWorkingDir} from '../utils';
import {Config} from '../config/config';
import {buildInputObject} from './buildUitls';
import {ImportFile} from '@resolver-engine/imports';
const loadRemoteVersion = promisify(solc.loadRemoteVersion);
export async function loadCompiler(config: Config) {
if (config.solcVersion) {
if (isDirectory(config.solcVersion)) {
return require(relativePathToWorkingDir(config.solcVersion));
}
return loadRemoteVersion(config.solcVersion);
}
return solc;
}
export function compileSolcjs(config: Config) {
return async function compile(sources: ImportFile[], findImports: (file: string) => any) {
const solc = await loadCompiler(config);
const input = buildInputObject(sources, config.compilerOptions);
const output = solc.compile(JSON.stringify(input), findImports);