From c8d06f8d82d6dfaae03f6b9e9df9bd517e29ea9e Mon Sep 17 00:00:00 2001 From: Roman Storm Date: Sun, 12 Nov 2017 21:37:06 -0800 Subject: [PATCH] update scripts to notify how many expected investors should be --- scripts/filterAddresses.js | 15 +++++++-------- scripts/whitelist.js | 31 ++++++++++++++++++------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/scripts/filterAddresses.js b/scripts/filterAddresses.js index 3201684..72e7fce 100644 --- a/scripts/filterAddresses.js +++ b/scripts/filterAddresses.js @@ -2,14 +2,15 @@ require('dotenv').config(); const ContributionABI = require('../build/contracts/PresaleOracles.json').abi; // const Web3 = require('web3'); -// // const MAINET_RPC_URL = 'https://mainnet.infura.io/metamask' -// // const KOVAN_RPC_URL = 'https://kovan.infura.io/metamask' +// const MAINET_RPC_URL = 'https://mainnet.infura.io/metamask' +// const KOVAN_RPC_URL = 'https://kovan.infura.io/metamask' // const local = `http://localhost:${process.env.RPC_PORT}`; // const provider = new Web3.providers.HttpProvider(local); // const web3 = new Web3(provider); -// var myContract = new web3.eth.Contract(ContributionABI, '0x6F3f79941f89E03D4aF9bDb8BE0623DC24F2bef0'); +// var myContract = new web3.eth.Contract(ContributionABI, process.env.PRESALE_ADDRESS); // const ARRAY_OF_ADDRESSES = require('./ARRAY_OF_ADDRESSES.json'); // filterAddresses(ARRAY_OF_ADDRESSES).then(console.log) +// readCap(); function setup({web3Param, contribAddress}){ web3 = web3Param; CONTRIBUTION_ADDRESS = contribAddress @@ -17,12 +18,11 @@ function setup({web3Param, contribAddress}){ } function readCap() { - myContract.methods.cap().call().then((cap) => { + myContract.methods.investorsLength().call().then((cap) => { console.log('cap', cap); }) } function isWhitelisted(toCheckAddress) { - readCap(); var count = 0; var leftRun = toCheckAddress.length; let notWhitelisted = []; @@ -30,7 +30,6 @@ function isWhitelisted(toCheckAddress) { if(toCheckAddress.length === 0 || !toCheckAddress) { rej('array is empty'); } - console.log(toCheckAddress.length) toCheckAddress.forEach((address, index) => { myContract.methods.whitelist(address).call().then((isWhitelisted) => { leftRun--; @@ -39,7 +38,7 @@ function isWhitelisted(toCheckAddress) { notWhitelisted.push(address); } if (leftRun === 0) { - console.log('FINISHED! notWhitelisted: ', notWhitelisted.length); + console.log('FINISHED filtering array! notWhitelisted: ', notWhitelisted.length); res(notWhitelisted); } }); @@ -50,7 +49,7 @@ function isWhitelisted(toCheckAddress) { function filterAddresses(arrayOfAddresses) { const date = Date.now(); - console.log(date, 'DATE NOW', arrayOfAddresses.length); + console.log(date, 'DATE NOW, to process array length', arrayOfAddresses.length); return new Promise((res, rej) => { return isWhitelisted(arrayOfAddresses).then((whitelistedAddress) => { res(whitelistedAddress); diff --git a/scripts/whitelist.js b/scripts/whitelist.js index 86552c9..d8ff43f 100644 --- a/scripts/whitelist.js +++ b/scripts/whitelist.js @@ -1,5 +1,6 @@ require('dotenv').config(); -const ARRAY_OF_ADDRESSES = require('./ARRAY_OF_ADDRESSES.json'); +let ARRAY_OF_ADDRESSES = require('./ARRAY_OF_ADDRESSES.json'); +ARRAY_OF_ADDRESSES = Array.from(new Set(ARRAY_OF_ADDRESSES)); const RPC_PORT = process.env.RPC_PORT; const PRESALE_ADDRESS = process.env.PRESALE_ADDRESS; const UNLOCKED_ADDRESS = process.env.UNLOCKED_ADDRESS; @@ -10,18 +11,8 @@ const provider = new Web3.providers.HttpProvider(`http://localhost:${RPC_PORT}`) const web3 = new Web3(provider); const { filterAddresses, setup } = require('./filterAddresses'); -setup({ web3Param: web3, contribAddress: PRESALE_ADDRESS}); -filterAddresses(ARRAY_OF_ADDRESSES).then(async (toWhitelist) => { - console.log(toWhitelist.length); - const addPerTx = 160; - const slices = Math.ceil(toWhitelist.length / addPerTx); - console.log(`THIS SCRIPT WILL GENERATE ${slices} transactions`); - var txcount = await web3.eth.getTransactionCount(UNLOCKED_ADDRESS); - const nonce = web3.utils.toHex(txcount); - console.log('STARTED', nonce); - return sendTransactionToContribution({array: toWhitelist, slice: slices, addPerTx, nonce}); -}).then(console.log).catch(console.error); +setup({ web3Param: web3, contribAddress: PRESALE_ADDRESS}); const GAS_PRICE = web3.utils.toWei(process.env.GAS_PRICE, 'gwei'); const GAS_LIMIT = '6700000'; const myContract = new web3.eth.Contract(ICO_ABI, PRESALE_ADDRESS, { @@ -30,6 +21,20 @@ const myContract = new web3.eth.Contract(ICO_ABI, PRESALE_ADDRESS, { gas: GAS_LIMIT // default gas price in wei }); +filterAddresses(ARRAY_OF_ADDRESSES).then(async (toWhitelist) => { + let currentInvestors = await myContract.methods.investorsLength().call(); + currentInvestors = Number(currentInvestors.toString(10)); + console.log('current whitelisted investors: ', currentInvestors); + console.log('to whitelist', toWhitelist.length); + console.log('Expected total whitelisted count after execution', toWhitelist.length + currentInvestors); + const addPerTx = 160; + const slices = Math.ceil(toWhitelist.length / addPerTx); + console.log(`THIS SCRIPT WILL GENERATE ${slices} transactions`); + var txcount = await web3.eth.getTransactionCount(UNLOCKED_ADDRESS); + const nonce = web3.utils.toHex(txcount); + console.log('STARTED', nonce); + return sendTransactionToContribution({array: toWhitelist, slice: slices, addPerTx, nonce}); +}).then(console.log).catch(console.error); async function sendTransactionToContribution({array, slice, addPerTx, nonce}) { if(array.length === 0){ @@ -58,7 +63,7 @@ async function sendTransactionToContribution({array, slice, addPerTx, nonce}) { sendTransactionToContribution({array, slice, addPerTx, nonce}); } else { res({ result: 'completed' }); - // process.exit(); + process.exit(); } });