From 0f90d90fd3108b99268d953b8c41c1b90a1721af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Tue, 18 May 2021 13:47:32 +0200 Subject: [PATCH] chore(bridge): attend @tommytrg code-style review --- migrations/01_initial.js | 1 - migrations/02_singleton_libs.js | 31 ++++++++++++++----------------- migrations/04_singleton_proxy.js | 7 ++----- migrations/99_upgrade_proxy.js | 1 - 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/migrations/01_initial.js b/migrations/01_initial.js index c07f5be6a..bc6c81180 100644 --- a/migrations/01_initial.js +++ b/migrations/01_initial.js @@ -2,7 +2,6 @@ const fs = require('fs') const Migrations = artifacts.require("Migrations"); module.exports = async function (deployer, network) { - if (!fs.existsSync('./migrations/addresses.json')) { await fs.open('./migrations/addresses.json', 'w', function (err, file) { if (err) throw new Error("Fatal: cannot create ./migrations/addreses.json"); diff --git a/migrations/02_singleton_libs.js b/migrations/02_singleton_libs.js index e491923f5..547f61dc6 100644 --- a/migrations/02_singleton_libs.js +++ b/migrations/02_singleton_libs.js @@ -5,7 +5,6 @@ const utils = require('../utils') const SingletonFactory = artifacts.require("SingletonFactory") module.exports = async function (deployer, network, accounts) { - let addresses = require('./addresses.json') const singletons = require('./singletons.json') @@ -69,17 +68,19 @@ module.exports = async function (deployer, network, accounts) { ; let bytecode = artifact.toJSON().bytecode - if (singletons.libs[lib].links) singletons.libs[lib].links.forEach( - // Join dependent library address(es) into the library bytecode to be deployed: - // Please note: dependent libraries should have been previously deployed, - // so order in which libraries are declared in the config file actually matters. - sublib => { - const sublib_artifact = artifacts.require(sublib) - const sublib_addr = sublib_artifact.address.slice(2).toLowerCase() - const sublib_mark = `__${sublib_artifact.contractName}${'_'.repeat(38 - sublib_artifact.contractName.length)}` - bytecode = bytecode.split(sublib_mark).join(sublib_addr) - } - ) + if (singletons.libs[lib].links) { + singletons.libs[lib].links.forEach( + // Join dependent library address(es) into the library bytecode to be deployed: + // Please note: dependent libraries should have been previously deployed, + // so order in which libraries are declared in the config file actually matters. + sublib => { + const sublib_artifact = artifacts.require(sublib) + const sublib_addr = sublib_artifact.address.slice(2).toLowerCase() + const sublib_mark = `__${sublib_artifact.contractName}${'_'.repeat(38 - sublib_artifact.contractName.length)}` + bytecode = bytecode.split(sublib_mark).join(sublib_addr) + } + ) + } artifact.bytecode = bytecode var lib_addr = await factory.determineAddr.call(bytecode, salt) @@ -89,11 +90,7 @@ module.exports = async function (deployer, network, accounts) { traceHeader(`Singleton inception of library '${lib}':`) const balance = await web3.eth.getBalance(from) - const gas = singletons.libs[lib].gas - ? singletons.libs[lib].gas - : 10 ** 6 - ; - + const gas = singletons.libs[lib].gas || 10 ** 6 const tx = await factory.deploy(bytecode, salt, {from: from, gas: gas}) traceDeploymentTx(tx.receipt, web3.utils.fromWei((balance - await web3.eth.getBalance(from)).toString())) } else { diff --git a/migrations/04_singleton_proxy.js b/migrations/04_singleton_proxy.js index ec323aedf..5f6e5fb39 100644 --- a/migrations/04_singleton_proxy.js +++ b/migrations/04_singleton_proxy.js @@ -6,7 +6,6 @@ const SingletonFactory = artifacts.require("SingletonFactory") const WitnetRequestBoard = artifacts.require("WitnetRequestBoard") module.exports = async function (deployer, network, accounts) { - let addresses = require('./addresses.json') const factory = await SingletonFactory.deployed() @@ -45,14 +44,12 @@ module.exports = async function (deployer, network, accounts) { traceHeader(`Singleton inception of contract '${contract}':`) const balance = await web3.eth.getBalance(from) - const gas = singletons.contracts[contract].gas - ? singletons.contracts[contract].gas - : 10 ** 6 + const gas = singletons.contracts[contract].gas || 10 ** 6 // Compose initialization call: 'upgradeWitnetRequestBoard(wrb.address)' let initCall = '0x47b1e79b000000000000000000000000' + wrb.address.slice(2) - const tx = await factory.deployAndInit(bytecode, initCall, salt, {from: from, gas: gas}) + const tx = await factory.deployAndInit(bytecode, initCall, salt, {from, gas}) utils.traceEvents(tx.logs) traceDeploymentTx(tx.receipt, web3.utils.fromWei((balance - await web3.eth.getBalance(from)).toString())) } else { diff --git a/migrations/99_upgrade_proxy.js b/migrations/99_upgrade_proxy.js index 7d691ada2..6ad04408a 100644 --- a/migrations/99_upgrade_proxy.js +++ b/migrations/99_upgrade_proxy.js @@ -3,7 +3,6 @@ const WitnetRequestBoardProxy = artifacts.require("WitnetRequestBoardProxy") const WitnetRequestBoard = artifacts.require("WitnetRequestBoard") module.exports = async function (deployer, network, accounts) { - const WRB = await WitnetRequestBoard.deployed() const WRBProxy = await WitnetRequestBoardProxy.deployed()