From adb7122a289fffcc115d85533ab9e6ed291bb825 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 2 Apr 2019 17:35:28 +0200 Subject: [PATCH] Add helper script for updating local address file Can be run after starting the devchain, so that all local truffle scripts work with the new network ID. --- scripts/helpers/update_local_networkid.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 scripts/helpers/update_local_networkid.js diff --git a/scripts/helpers/update_local_networkid.js b/scripts/helpers/update_local_networkid.js new file mode 100644 index 0000000..b4bda0f --- /dev/null +++ b/scripts/helpers/update_local_networkid.js @@ -0,0 +1,22 @@ +const fs = require('fs'); +const getNetworkId = require('./networkid.js'); + +module.exports = async function(callback) { + const daoAddressPath = 'lib/addresses/dao.json'; + + // TODO maybe do the same for KreditsKit address file + try { + const networkId = await getNetworkId(web3); + const daoAddresses = JSON.parse(fs.readFileSync(daoAddressPath)); + const oldNetworkId = Math.max(...Object.keys(daoAddresses).map(a => parseInt(a))); + const localDaoAddress = daoAddresses[oldNetworkId]; + daoAddresses[networkId] = localDaoAddress; + delete daoAddresses[oldNetworkId]; + fs.writeFileSync(daoAddressPath, JSON.stringify(daoAddresses, null, 2)); + console.log('Updated local network ID for DAO address'); + } catch(e) { + console.log(e); + } + + callback(); +};