diff --git a/migrations/constructorArgs.json b/migrations/constructorArgs.json new file mode 100644 index 000000000..a33db013e --- /dev/null +++ b/migrations/constructorArgs.json @@ -0,0 +1,5 @@ +{ + "ten:testnet": { + "WitnetRequestBoardTrustableObscuro": "0000000000000000000000000000f7eb1d08e68c361b8a0c4a36f442c58f10000000000000000000000000000000b677d4a6d20c3b087c52a36e4bed558de0000000000000000000000000000000000000000000000000000000000000000001322e302e312d6466623331353500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e3aa000000000000000000000000000000000000000000000000000000000000fef90000000000000000000000000000000000000000000000000000000000010faa0000000000000000000000000000000000000000000000000000000000004e20" + } +} \ No newline at end of file diff --git a/migrations/scripts/1_deployer.js b/migrations/scripts/1_deployer.js index dff93b034..d4a97e3ac 100644 --- a/migrations/scripts/1_deployer.js +++ b/migrations/scripts/1_deployer.js @@ -3,7 +3,7 @@ const utils = require("../../src/utils") const WitnetDeployer = artifacts.require("WitnetDeployer") module.exports = async function (deployer, network, [,,, master]) { - const addresses = await utils.readAddresses() + const addresses = await utils.readJsonFromFile("./migrations/addresses.json") if (!addresses[network]) addresses[network] = {}; const factoryAddr = addresses[network]?.WitnetDeployer || addresses?.default?.WitnetDeployer || "" @@ -15,7 +15,7 @@ module.exports = async function (deployer, network, [,,, master]) { const factory = await WitnetDeployer.deployed() addresses[network].WitnetDeployer = factory.address if (!utils.isDryRun(network)) { - await utils.saveAddresses(addresses) + await utils.overwriteJsonFile("./migrations/addresses.json", addresses) } } else { const factory = await WitnetDeployer.at(factoryAddr) diff --git a/migrations/scripts/2_libs.js b/migrations/scripts/2_libs.js index cfac8690b..332711f19 100644 --- a/migrations/scripts/2_libs.js +++ b/migrations/scripts/2_libs.js @@ -4,7 +4,7 @@ const utils = require("../../src/utils") const WitnetDeployer = artifacts.require("WitnetDeployer") module.exports = async function (_, network, [, from]) { - const addresses = await utils.readAddresses() + const addresses = await utils.readJsonFromFile("./migrations/addresses.json") if (!addresses[network]) addresses[network] = {}; const targets = settings.getArtifacts(network) @@ -39,7 +39,7 @@ module.exports = async function (_, network, [, from]) { process.exit(1) } if (!utils.isDryRun(network)) { - await utils.saveAddresses(addresses) + await utils.overwriteJsonFile("./migrations/addresses.json", addresses) } } else { utils.traceHeader(`Skipped '${key}'`) diff --git a/migrations/scripts/3_core.js b/migrations/scripts/3_core.js index 35a059403..82e44bd7c 100644 --- a/migrations/scripts/3_core.js +++ b/migrations/scripts/3_core.js @@ -65,7 +65,7 @@ module.exports = async function (_, network, [, from]) { async function deploy (specs) { const { from, key, libs, intrinsics, immutables, network, targets } = specs - const addresses = await utils.readAddresses() + const addresses = await utils.readJsonFromFile("./migrations/addresses.json") if (!addresses[network]) addresses[network] = {}; const selection = utils.getWitnetArtifactsFromArgs() @@ -107,7 +107,9 @@ async function deploy (specs) { } // save addresses file if required if (!utils.isDryRun(network)) { - await utils.saveAddresses(addresses) + await utils.overwriteJsonFile("./migrations/addresses.json", addresses) + const args = {}; args[network] = {}; args[network][key] = constructorArgs.slice(2); + await utils.overwriteJsonFile("./migrations/constructorArgs.json", args) } } else { utils.traceHeader(`Skipped '${key}'`) diff --git a/migrations/scripts/4_proxies.js b/migrations/scripts/4_proxies.js index b4dedfe44..841b1dfc1 100644 --- a/migrations/scripts/4_proxies.js +++ b/migrations/scripts/4_proxies.js @@ -41,7 +41,7 @@ module.exports = async function (_, network, [, from, reporter]) { async function deploy (target) { const { from, key, network, specs, targets } = target - const addresses = await utils.readAddresses(network) + const addresses = await utils.readJsonFromFile("./migrations/addresses.json") if (!addresses[network]) addresses[network] = {}; const mutables = specs[key].mutables @@ -89,7 +89,7 @@ async function deploy (target) { process.exit(1) } if (!utils.isDryRun(network)) { - await utils.saveAddresses(addresses) + await utils.overwriteJsonFile("./migrations/addresses.json", addresses) } } else { const oldAddr = await getProxyImplementation(from, proxyAddr) diff --git a/migrations/scripts/5_apps.js b/migrations/scripts/5_apps.js index a5f2cda3d..fdea12d1b 100644 --- a/migrations/scripts/5_apps.js +++ b/migrations/scripts/5_apps.js @@ -30,7 +30,7 @@ module.exports = async function (_, network, [, from,, master]) { async function deploy (specs) { const { from, gas, key, libs, intrinsics, immutables, network, targets, vanity } = specs - const addresses = await utils.readAddresses() + const addresses = await utils.readJsonFromFile("./migrations/addresses.json") if (!addresses[network]) addresses[network] = {}; const artifact = artifacts.require(key) @@ -69,7 +69,7 @@ async function deploy (specs) { } // save addresses file if required if (!utils.isDryRun(network)) { - await utils.saveAddresses(addresses) + await utils.overwriteJsonFile("./migrations/addresses.json", addresses) } } else { utils.traceHeader(`Skipped '${key}'`) diff --git a/src/utils/index.js b/src/utils.js similarity index 74% rename from src/utils/index.js rename to src/utils.js index accb4fb32..0a71e0a88 100644 --- a/src/utils/index.js +++ b/src/utils.js @@ -2,9 +2,7 @@ const fs = require("fs") require("dotenv").config() const lockfile = require("proper-lockfile") const readline = require("readline") - -const traceHeader = require("./traceHeader") -const traceTx = require("./traceTx") +const web3 = require("web3") module.exports = { fromAscii, @@ -16,8 +14,8 @@ module.exports = { isNullAddress, padLeft, prompt, - readAddresses, - saveAddresses, + readJsonFromFile, + overwriteJsonFile, traceHeader, traceTx, } @@ -115,18 +113,33 @@ async function prompt (text) { return answer } -async function readAddresses () { - const filename = "./migrations/witnet.addresses.json" +async function readJsonFromFile (filename) { lockfile.lockSync(filename) - const addrs = JSON.parse(await fs.readFileSync(filename)) + const json = JSON.parse(await fs.readFileSync(filename)) lockfile.unlockSync(filename) - return addrs || {} + return json|| {} } -async function saveAddresses (addrs) { - const filename = "./migrations/witnet.addresses.json" +async function overwriteJsonFile (filename, extra) { lockfile.lockSync(filename) - const json = { ...JSON.parse(fs.readFileSync(filename)), ...addrs }; + const json = { ...JSON.parse(fs.readFileSync(filename)), ...extra }; fs.writeFileSync(filename, JSON.stringify(json, null, 4), { flag: "w+" }) lockfile.unlockSync(filename) } + +function traceHeader (header) { + console.log("") + console.log(" ", header) + console.log(" ", `${"-".repeat(header.length)}`) +} + +function traceTx (tx) { + console.info(" ", "> transaction hash: ", tx.receipt.transactionHash) + console.info(" ", "> gas used: ", tx.receipt.gasUsed.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")) + console.info(" ", "> gas price: ", tx.receipt.effectiveGasPrice / 10 ** 9, "gwei") + console.info(" ", "> total cost: ", web3.utils.fromWei( + BigInt(tx.receipt.gasUsed * tx.receipt.effectiveGasPrice).toString(), + "ether" + ), "ETH" + ) +} diff --git a/src/utils/traceHeader.js b/src/utils/traceHeader.js deleted file mode 100644 index de350909d..000000000 --- a/src/utils/traceHeader.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = function (header) { - console.log("") - console.log(" ", header) - console.log(" ", `${"-".repeat(header.length)}`) -} diff --git a/src/utils/traceTx.js b/src/utils/traceTx.js deleted file mode 100644 index 2a8f73679..000000000 --- a/src/utils/traceTx.js +++ /dev/null @@ -1,12 +0,0 @@ -const web3 = require("web3") - -module.exports = function (tx) { - console.info(" ", "> transaction hash: ", tx.receipt.transactionHash) - console.info(" ", "> gas used: ", tx.receipt.gasUsed.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")) - console.info(" ", "> gas price: ", tx.receipt.effectiveGasPrice / 10 ** 9, "gwei") - console.info(" ", "> total cost: ", web3.utils.fromWei( - BigInt(tx.receipt.gasUsed * tx.receipt.effectiveGasPrice).toString(), - "ether" - ), "ETH" - ) -}