diff --git a/log/stress_0200.log b/log/stress_0200.log index be0c737..41ccad9 100644 --- a/log/stress_0200.log +++ b/log/stress_0200.log @@ -1,6 +1,6 @@ type gasUsed gasPrice 1ETH*USD gasUsed*gasPrice(Ether) gasUsed*gasPrice(USD) create 1692580 2 303 0.00338516 1.02570348 register 119815 2 303 0.00023963 0.07260789000000001 -batchAttend 2968867 2 303 0.005937734 1.799133402 +batchAttend 2969251 2 303 0.005938502 1.799366106 payback 84325 2 303 0.00016865 0.05110095 withdraw 37660 2 303 0.00007532 0.022821960000000002 diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js index d7b5123..daae607 100644 --- a/migrations/2_deploy_contracts.js +++ b/migrations/2_deploy_contracts.js @@ -10,13 +10,15 @@ let name = ''; // empty name falls back to the contract default let deposit = 0; // 0 falls back to the contract default let limitOfParticipants = 0; // 0 falls back to the contract default let confirmationAddress = 0; - // eg: truffle migrate --config '{"name":"CodeUp No..", "encryption":"./tmp/test_public.key", "confirmation":true}' if (yargs.argv.config) { var config = JSON.parse(yargs.argv.config); } module.exports = function(deployer) { + const app_config = require('../app_config.js')[deployer.network]; + console.log('app_config', app_config) + if (deployer.network == 'test') return 'no need to deploy contract'; if (config.name){ name = config.name; @@ -28,10 +30,14 @@ module.exports = function(deployer) { deployer .then(() => { if (config.confirmation) { - return deployer.deploy(ConfirmationRepository) - .then(instance => { - confirmationAddress = ConfirmationRepository.address; - }) + if (app_config && app_config.contract_addresses['ConfirmationRepository']) { + confirmationAddress = app_config.contract_addresses['ConfirmationRepository']; + }else{ + return deployer.deploy(ConfirmationRepository) + .then(instance => { + confirmationAddress = ConfirmationRepository.address; + }) + } } }) .then(() => { diff --git a/package.json b/package.json index 2cde395..98efbf4 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "material-ui": "^0.15.2", "mathjs": "^3.2.1", "moment": "^2.18.1", + "prompt": "^1.0.0", "react": "15.3.2", "react-addons-css-transition-group": "^15.1.0", "react-dom": "15.3.2", diff --git a/scripts/change_owner.js b/scripts/change_owner.js index 677c57a..cdfe42a 100644 --- a/scripts/change_owner.js +++ b/scripts/change_owner.js @@ -1,7 +1,8 @@ let arg = require('yargs').argv; let fs = require('fs'); -let Conference = artifacts.require("./Conference.sol"); let setGas = require('./util/set_gas'); +let setContract = require('./util/set_contract'); + if (!(arg.f && arg.t)) { throw('usage: truffle exec scripts/change_owner.js -f original_owner.txt -t address_to_change.txt'); } @@ -11,7 +12,7 @@ module.exports = async function() { let from = fs.readFileSync(arg.f, 'utf8').trim().split('\n')[0]; let to = fs.readFileSync(arg.t, 'utf8').trim().split('\n')[0]; console.log('Changing ownership from ', from, ' to ', to); - let conference = await Conference.deployed(); + const conference = await setContract(artifacts, 'Conference'); let owner = await conference.owner.call(); console.log('owner', owner, from, owner === from) if (owner != from) { diff --git a/scripts/decrypt.js b/scripts/decrypt.js index d0a2b58..c15bfe8 100644 --- a/scripts/decrypt.js +++ b/scripts/decrypt.js @@ -27,7 +27,8 @@ module.exports = async function(callback) { if (contractAccount) { conference = await Conference.at(contractAccount); }else{ - conference = await Conference.deployed(); + let setContract = require('./util/set_contract'); + conference = await setContract(artifacts, 'Conference'); } let event = conference.RegisterEvent({}, {fromBlock:fromBlock}); console.log(['regisered at ', '@twitter', 'full name'].join('\t')); diff --git a/scripts/repository.js b/scripts/repository.js index 97a8b5d..ec88f7c 100644 --- a/scripts/repository.js +++ b/scripts/repository.js @@ -1,25 +1,25 @@ let fs = require('fs'); let setGas = require('./util/set_gas'); +let setContract = require('./util/set_contract'); let ConfirmationRepository = artifacts.require("./ConfirmationRepository.sol"); + let repository; let arg = require('yargs').argv; -if (!(arg.i && arg.t)) { - throw('usage: truffle exec scripts/repository.js -t confirmation -i codes.txt'); +if (!(arg.i)) { + throw('usage: truffle exec scripts/repository.js -i codes.txt'); } module.exports = async function(callback) { - let gas = await setGas(web3); - let file = arg.i; - console.log('file', file) - switch (arg.t) { - case 'confirmation': - repository = await ConfirmationRepository.deployed(); - console.log('repository', repository.address) - break; - default: - throw('-t must be either confirmation'); + const gas = await setGas(web3); + const conference = await setContract(artifacts, 'Conference'); + const repositoryAddress = await conference.confirmationRepository.call(); + if (!repositoryAddress) { + throw("repository address does not exist") } + const repository = await ConfirmationRepository.at(repositoryAddress); + let file = arg.i; + let codes = fs.readFileSync(file, 'utf8').trim().split('\n'); let encrypted_codes = []; for (var i = 0; i < codes.length; i++) { diff --git a/src/index.js b/src/index.js index 1e10a5e..678160c 100644 --- a/src/index.js +++ b/src/index.js @@ -69,12 +69,29 @@ function setup(){ window.onload = function() { setup().then(({provider, web3, read_only, network_id}) => { + var env; + switch (network_id) { + case '1': + env = 'mainnet'; + break; + case '3': + env = 'ropsten'; + break; + default: + env = 'development'; + } + var network_obj = require('../app_config.js')[env]; + var Conference = TruffleContract(artifacts); let contract, contractAddress; Conference.setProvider(provider); Conference.setNetwork(network_id); try { - contract = Conference.at(Conference.address); + if (network_obj.contract_addresses['Conference']) { + contract = Conference.at(network_obj.contract_addresses['Conference']); + }else{ + contract = Conference.at(Conference.address); + } } catch (e) { console.log("ERROR") console.log(e) @@ -96,34 +113,6 @@ window.onload = function() { window.web3 = web3 const eventEmitter = EventEmitter() - var network_obj; - switch (network_id) { - case '1': - network_obj = { - name: 'MAINNET', - etherscan_url: 'https://etherscan.io' - } - break; - case '3': - network_obj = { - name: 'ROPSTEN NET', - etherscan_url: 'https://ropsten.etherscan.io' - } - break; - case '42': - network_obj = { - name: 'KOVAN NET', - etherscan_url: 'https://kovan.etherscan.io' - } - break; - default: - network_obj = { - name: 'PRIVATE NET', - etherscan_url: null - } - - } - function getBalance(address){ return new Promise(function(resolve,reject){ web3.eth.getBalance(address, function(err, result){