Skip to content

Commit

Permalink
chore(bridge): attend @Tommytrg code-style review
Browse files Browse the repository at this point in the history
  • Loading branch information
guidiaz committed May 18, 2021
1 parent cc25a99 commit 0f90d90
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
1 change: 0 additions & 1 deletion migrations/01_initial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
31 changes: 14 additions & 17 deletions migrations/02_singleton_libs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions migrations/04_singleton_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion migrations/99_upgrade_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 0f90d90

Please sign in to comment.