Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 0 additions & 94 deletions CLI/commands/accredit.js

This file was deleted.

94 changes: 0 additions & 94 deletions CLI/commands/changeNonAccreditedLimit.js

This file was deleted.

53 changes: 35 additions & 18 deletions CLI/commands/common/common_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function getFinalOptions(options) {
async function getGasLimit(options, action) {
let block = await web3.eth.getBlock("latest");
let networkGasLimit = block.gasLimit;
let gas = Math.round(options.factor * (await action.estimateGas({ from: options.from.address, value: options.value})));
let gas = Math.round(options.factor * (await action.estimateGas({ from: options.from.address, value: options.value })));
return (gas > networkGasLimit) ? networkGasLimit : gas;
}

Expand All @@ -65,16 +65,16 @@ async function checkPermissions(action) {
module.exports = {
convertToDaysRemaining: function (timeRemaining) {
var seconds = parseInt(timeRemaining, 10);

var days = Math.floor(seconds / (3600 * 24));
seconds -= days * 3600 * 24;
var hrs = Math.floor(seconds / 3600);
seconds -= hrs * 3600;
seconds -= days * 3600 * 24;
var hrs = Math.floor(seconds / 3600);
seconds -= hrs * 3600;
var mnts = Math.floor(seconds / 60);
seconds -= mnts * 60;
seconds -= mnts * 60;
return (days + " days, " + hrs + " Hrs, " + mnts + " Minutes, " + seconds + " Seconds");
},
logAsciiBull: function() {
logAsciiBull: function () {
console.log(`
/######%%, /#(
##########%%%%%, ,%%%. %
Expand Down Expand Up @@ -103,8 +103,8 @@ module.exports = {

options = getFinalOptions(options);
let gasLimit = await getGasLimit(options, action);
console.log(chalk.black.bgYellowBright(`---- Transaction executed: ${action._method.name} - Gas limit provided: ${gasLimit} ----`));

console.log(chalk.black.bgYellowBright(`---- Transaction executed: ${action._method.name} - Gas limit provided: ${gasLimit} ----`));

let nonce = await web3.eth.getTransactionCount(options.from.address);
let abi = action.encodeABI();
Expand All @@ -117,24 +117,24 @@ module.exports = {
nonce: nonce,
value: web3.utils.toHex(options.value)
};

const transaction = new Tx(parameter);
transaction.sign(Buffer.from(options.from.privateKey.replace('0x', ''), 'hex'));
return await web3.eth.sendSignedTransaction('0x' + transaction.serialize().toString('hex'))
.on('transactionHash', function(hash){
console.log(`
.on('transactionHash', function (hash) {
console.log(`
Your transaction is being processed. Please wait...
TxHash: ${hash}`
);
})
.on('receipt', function(receipt){
console.log(`
);
})
.on('receipt', function (receipt) {
console.log(`
Congratulations! The transaction was successfully completed.
Gas used: ${receipt.gasUsed} - Gas spent: ${web3.utils.fromWei((new web3.utils.BN(options.gasPrice)).mul(new web3.utils.BN(receipt.gasUsed)))} Ether
Review it on Etherscan.
TxHash: ${receipt.transactionHash}\n`
);
});
);
});
},
getEventFromLogs: function (jsonInterface, logs, eventName) {
let eventJsonInterface = jsonInterface.find(o => o.name === eventName && o.type === 'event');
Expand All @@ -145,5 +145,22 @@ module.exports = {
let eventJsonInterface = jsonInterface.find(o => o.name === eventName && o.type === 'event');
let filteredLogs = logs.filter(l => l.topics.includes(eventJsonInterface.signature));
return filteredLogs.map(l => web3.eth.abi.decodeLog(eventJsonInterface.inputs, l.data, l.topics.slice(1)));
},
splitIntoBatches: function (data, batchSize) {
let allBatches = [];
for (let index = 0; index < data.length; index += batchSize) {
allBatches.push(data.slice(index, index + batchSize));
}
return allBatches;
},
transposeBatches: function (batches) {
let result = [];
if (batches.length > 0 && batches[0].length > 0) {
let columns = batches[0][0].length;
for (let index = 0; index < columns; index++) {
result[index] = batches.map(batch => batch.map(record => record[index]));
}
}
return result;
}
};
16 changes: 9 additions & 7 deletions CLI/commands/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,30 @@ module.exports = Object.freeze({
BURN: 5
},
DURATION: {
seconds: function(val) {
seconds: function (val) {
return val
},
minutes: function(val) {
minutes: function (val) {
return val * this.seconds(60)
},
hours: function(val) {
hours: function (val) {
return val * this.minutes(60)
},
days: function(val) {
days: function (val) {
return val * this.hours(24)
},
weeks: function(val) {
weeks: function (val) {
return val * this.days(7)
},
years: function(val) {
years: function (val) {
return val * this.days(365)
}
},
FUND_RAISE_TYPES: {
ETH: 0,
POLY: 1,
DAI: 2
}
},
DEFAULT_BATCH_SIZE: 75,
ADDRESS_ZERO: '0x0000000000000000000000000000000000000000'
});
35 changes: 35 additions & 0 deletions CLI/commands/helpers/csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const csvParse = require('csv-parse/lib/sync');
const fs = require('fs');
const web3Utils = require('web3-utils');

function _cast(obj) {
if (/^(\-|\+)?([1-9]+[0-9]*)$/.test(obj)) { // Int
obj = parseInt(obj);
}
else if (/^[+-]?([0-9]*[.])?[0-9]+$/.test(obj)) { // Float
obj = parseFloat(obj);
}
else if (/^(\d{1,2})[-\/](\d{1,2})[-\/](\d{4})$/.test(obj)) { // Datetime
var matches = /^(\d{1,2})[-\/](\d{1,2})[-\/](\d{4})$/.exec(obj);
var composedDate = new Date(matches[3], matches[1] - 1, matches[2]);
var timestampDate = composedDate.getTime();
obj = timestampDate / 1000;
}
else if (obj.toLowerCase() === "true" || obj.toLowerCase() === "false") { // Boolean
obj = JSON.parse(obj.toLowerCase());
} else if (web3Utils.isAddress(obj)) {
obj = web3Utils.toChecksumAddress(obj);
}
return obj;
}

function parse(_csvFilePath, _batchSize) {
// Read file
let input = fs.readFileSync(_csvFilePath);
// Parse csv
let data = csvParse(input, { cast: _cast });

return data;
}

module.exports = parse;
Loading