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.
This commit is contained in:
Basti 2019-04-02 17:35:28 +02:00
parent ce446e530d
commit adb7122a28
No known key found for this signature in database
GPG Key ID: BE4634D632D39B67

View File

@ -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();
};