Dynamically set AppIds
AppIds are used to lookup the actual contract addresses of each app. Because of different registry names (open.aragonpm.eth vs. aragonpm.eth) we have to use different ids in the local dev chain and in the testnet/mainnet. To allow this we need to set the appids dynamically. There is an open aragon issue to solve this and also allow to use open.aragonpm.eth in the devchain by default. https://github.com/aragon/aragen/issues/10
This commit is contained in:
@@ -5,8 +5,7 @@ const path = require('path');
|
||||
const argv = require('yargs').argv
|
||||
const namehash = require('eth-ens-namehash').hash
|
||||
|
||||
const libPath = path.join(__dirname, '..', 'lib');
|
||||
const addressesPath = path.join(libPath, 'addresses');
|
||||
const fileInject = require('./helpers/file_inject.js')
|
||||
|
||||
const DAOFactory = artifacts.require('DAOFactory')
|
||||
const KreditsKit = artifacts.require('KreditsKit')
|
||||
@@ -48,16 +47,18 @@ module.exports = async function(callback) {
|
||||
|
||||
const apps = fs.readdirSync('./apps')
|
||||
console.log(`Found apps: [${apps}].${apm}`)
|
||||
const appIds = apps.map(app => namehash(`kredits-${app}.${apm}`))
|
||||
let appIds = {}
|
||||
apps.sort().forEach((app) => {
|
||||
let [first, ...rest] = app;
|
||||
let contractName = `${first.toUpperCase()}${rest.join('')}`
|
||||
appIds[contractName] = namehash(`kredits-${app}.${apm}`)
|
||||
})
|
||||
|
||||
KreditsKit.new(daoFactory.address, ensAddr, appIds).then((kreditsKit) => {
|
||||
KreditsKit.new(daoFactory.address, ensAddr, Object.values(appIds)).then((kreditsKit) => {
|
||||
console.log(`Deployed KreditsKit at: ${kreditsKit.address}`);
|
||||
|
||||
let addresseFile = path.join(addressesPath, `KreditsKit.json`);
|
||||
let addresses = JSON.parse(fs.readFileSync(addresseFile));
|
||||
|
||||
addresses[networkId] = kreditsKit.address;
|
||||
fs.writeFileSync(addresseFile, JSON.stringify(addresses));
|
||||
fileInject(path.join(__dirname, '..', 'lib/addresses/KreditsKit.json'), networkId, kreditsKit.address);
|
||||
fileInject(path.join(__dirname, '..', 'lib/app_ids.json'), networkId, appIds);
|
||||
|
||||
callback();
|
||||
}).catch((e) => {
|
||||
|
||||
8
scripts/helpers/file_inject.js
Normal file
8
scripts/helpers/file_inject.js
Normal file
@@ -0,0 +1,8 @@
|
||||
// help, give me a better name
|
||||
|
||||
const fs = require('fs');
|
||||
module.exports = function (file, networkId, data) {
|
||||
let content = JSON.parse(fs.readFileSync(file));
|
||||
content[networkId] = data;
|
||||
fs.writeFileSync(file, JSON.stringify(content));
|
||||
}
|
||||
11
scripts/helpers/networkid.js
Normal file
11
scripts/helpers/networkid.js
Normal file
@@ -0,0 +1,11 @@
|
||||
module.exports = function(web3) {
|
||||
return new Promise((resolve, reject) => {
|
||||
web3.version.getNetwork((err, network) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(network);
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const libPath = path.join(__dirname, '..', 'lib');
|
||||
const addressesPath = path.join(libPath, 'addresses');
|
||||
|
||||
const fileInject = require('./helpers/file_inject.js');
|
||||
|
||||
const addressesPath = path.join(__dirname, '..', 'lib/addresses');
|
||||
|
||||
const KreditsKit = artifacts.require('KreditsKit')
|
||||
|
||||
@@ -39,11 +41,7 @@ module.exports = async function(callback) {
|
||||
}
|
||||
const daoAddress = deployEvents[0].dao;
|
||||
|
||||
let addresseFile = path.join(addressesPath, `dao.json`);
|
||||
let addresses = JSON.parse(fs.readFileSync(addresseFile));
|
||||
|
||||
addresses[networkId] = daoAddress;
|
||||
fs.writeFileSync(addresseFile, JSON.stringify(addresses));
|
||||
fileInject(path.join(addressesPath, 'dao.json'), networkId, daoAddress)
|
||||
|
||||
console.log(`\n\nCreated new DAO at: ${daoAddress}`)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user