Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Deploy linked libraries
for (let linkedFile in bytecode.linkReferences) {
for (let linkedLib in bytecode.linkReferences[linkedFile]) {
let libObj = output.contracts[linkedFile][linkedLib]
let LibContract = new web3.eth.Contract(libObj.abi)
var libContract = await LibContract.deploy({
data: libObj.evm.bytecode.object
}).send({
from,
gas: 3000000
})
let libs = { [`${linkedFile}:${linkedLib}`]: libContract._address }
bytecode.object = linker.linkBytecode(bytecode.object, libs)
}
}
if (!bytecode.object) {
throw new Error(
'No Bytecode. Do the method signatures match the interface?'
)
}
if (process.env.BUILD) {
fs.writeFileSync(
__dirname + '/../src/contracts/' + contractName + '.js',
'module.exports = ' +
JSON.stringify(
{
abi,
]) {
libObj.evm.bytecode.object = await deployLib(
linkedFile2,
linkedLib2,
libObj.evm.bytecode
)
}
}
const LibContract = new web3.eth.Contract(libObj.abi)
const gas = solidityCoverage ? 3000000 * 5 : 3000000
const libContract = await LibContract.deploy({
data: libObj.evm.bytecode.object
}).send({ from, gas })
const libs = { [`${linkedFile}:${linkedLib}`]: libContract._address }
return linker.linkBytecode(bytecode.object, libs)
}
for (const linkedLib2 in linkReferences[linkedFile2]) {
libObj.evm.bytecode.object = await deployLib(
linkedFile2,
linkedLib2,
libObj.evm.bytecode
)
}
}
const LibContract = new web3.eth.Contract(libObj.abi)
const gas = solidityCoverage ? 3000000 * 5 : 3000000
const libContract = await LibContract.deploy({
data: libObj.evm.bytecode.object
}).send({ from, gas })
const libs = { [`${linkedFile}:${linkedLib}`]: libContract._address }
return linker.linkBytecode(bytecode.object, libs)
}
async function measureFunctionGas(
compiledContracts,
contractName,
contractCreationGas,
dependencies,
functionInfo
) {
let contract = compiledContracts.contracts[contractName];
let bytecode = contract.bytecode;
bytecode = linker.linkBytecode(bytecode, dependencies);
let abi = JSON.parse(contract.interface);
let createdContract = web3.eth.contract(abi);
let returnedMap = await new Promise((resolve, reject) => {
createdContract.new({
from: web3.eth.coinbase,
gas: contractCreationGas,
data: '0x' + bytecode
}, (err, myContract) => {
if (err) {
console.log(err);
return reject(err);
}
let gasPerFunction = [];
if (myContract.address != undefined) {
function measureDeploymentGasPerContract(compiledContracts, contractDeploymentInfo) {
let bytecode;
let gasPerContract = [];
for (contract in contractDeploymentInfo) {
dependencies = contractDeploymentInfo[contract].dependencies;
bytecode = '0x' + compiledContracts.contracts[contract].bytecode;
if (Object.keys(dependencies).length > 0) {
bytecode = linker.linkBytecode(bytecode, dependencies);
}
gasPerContract[contract] = web3.eth.estimateGas({
data: bytecode,
gasLimit: contractDeploymentInfo[contract].deploymentGasLimit
});
}
return gasPerContract;
}
linkMessageBus: async function(bin, libraryName, libAddress) {
let linkOptions = {};
linkOptions[libraryName] = libAddress;
return linker.linkBytecode(bin, linkOptions);
}
};