update scripts to notify how many expected investors should be

This commit is contained in:
Roman Storm 2017-11-12 21:37:06 -08:00
parent b4724fd0bc
commit c8d06f8d82
2 changed files with 25 additions and 21 deletions

View File

@ -2,14 +2,15 @@ require('dotenv').config();
const ContributionABI = require('../build/contracts/PresaleOracles.json').abi; const ContributionABI = require('../build/contracts/PresaleOracles.json').abi;
// const Web3 = require('web3'); // const Web3 = require('web3');
// // const MAINET_RPC_URL = 'https://mainnet.infura.io/metamask' // const MAINET_RPC_URL = 'https://mainnet.infura.io/metamask'
// // const KOVAN_RPC_URL = 'https://kovan.infura.io/metamask' // const KOVAN_RPC_URL = 'https://kovan.infura.io/metamask'
// const local = `http://localhost:${process.env.RPC_PORT}`; // const local = `http://localhost:${process.env.RPC_PORT}`;
// const provider = new Web3.providers.HttpProvider(local); // const provider = new Web3.providers.HttpProvider(local);
// const web3 = new Web3(provider); // 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'); // const ARRAY_OF_ADDRESSES = require('./ARRAY_OF_ADDRESSES.json');
// filterAddresses(ARRAY_OF_ADDRESSES).then(console.log) // filterAddresses(ARRAY_OF_ADDRESSES).then(console.log)
// readCap();
function setup({web3Param, contribAddress}){ function setup({web3Param, contribAddress}){
web3 = web3Param; web3 = web3Param;
CONTRIBUTION_ADDRESS = contribAddress CONTRIBUTION_ADDRESS = contribAddress
@ -17,12 +18,11 @@ function setup({web3Param, contribAddress}){
} }
function readCap() { function readCap() {
myContract.methods.cap().call().then((cap) => { myContract.methods.investorsLength().call().then((cap) => {
console.log('cap', cap); console.log('cap', cap);
}) })
} }
function isWhitelisted(toCheckAddress) { function isWhitelisted(toCheckAddress) {
readCap();
var count = 0; var count = 0;
var leftRun = toCheckAddress.length; var leftRun = toCheckAddress.length;
let notWhitelisted = []; let notWhitelisted = [];
@ -30,7 +30,6 @@ function isWhitelisted(toCheckAddress) {
if(toCheckAddress.length === 0 || !toCheckAddress) { if(toCheckAddress.length === 0 || !toCheckAddress) {
rej('array is empty'); rej('array is empty');
} }
console.log(toCheckAddress.length)
toCheckAddress.forEach((address, index) => { toCheckAddress.forEach((address, index) => {
myContract.methods.whitelist(address).call().then((isWhitelisted) => { myContract.methods.whitelist(address).call().then((isWhitelisted) => {
leftRun--; leftRun--;
@ -39,7 +38,7 @@ function isWhitelisted(toCheckAddress) {
notWhitelisted.push(address); notWhitelisted.push(address);
} }
if (leftRun === 0) { if (leftRun === 0) {
console.log('FINISHED! notWhitelisted: ', notWhitelisted.length); console.log('FINISHED filtering array! notWhitelisted: ', notWhitelisted.length);
res(notWhitelisted); res(notWhitelisted);
} }
}); });
@ -50,7 +49,7 @@ function isWhitelisted(toCheckAddress) {
function filterAddresses(arrayOfAddresses) { function filterAddresses(arrayOfAddresses) {
const date = Date.now(); 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 new Promise((res, rej) => {
return isWhitelisted(arrayOfAddresses).then((whitelistedAddress) => { return isWhitelisted(arrayOfAddresses).then((whitelistedAddress) => {
res(whitelistedAddress); res(whitelistedAddress);

View File

@ -1,5 +1,6 @@
require('dotenv').config(); 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 RPC_PORT = process.env.RPC_PORT;
const PRESALE_ADDRESS = process.env.PRESALE_ADDRESS; const PRESALE_ADDRESS = process.env.PRESALE_ADDRESS;
const UNLOCKED_ADDRESS = process.env.UNLOCKED_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 web3 = new Web3(provider);
const { filterAddresses, setup } = require('./filterAddresses'); 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_PRICE = web3.utils.toWei(process.env.GAS_PRICE, 'gwei');
const GAS_LIMIT = '6700000'; const GAS_LIMIT = '6700000';
const myContract = new web3.eth.Contract(ICO_ABI, PRESALE_ADDRESS, { 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 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}) { async function sendTransactionToContribution({array, slice, addPerTx, nonce}) {
if(array.length === 0){ if(array.length === 0){
@ -58,7 +63,7 @@ async function sendTransactionToContribution({array, slice, addPerTx, nonce}) {
sendTransactionToContribution({array, slice, addPerTx, nonce}); sendTransactionToContribution({array, slice, addPerTx, nonce});
} else { } else {
res({ result: 'completed' }); res({ result: 'completed' });
// process.exit(); process.exit();
} }
}); });