-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathaccredit.js
More file actions
94 lines (76 loc) · 3.24 KB
/
accredit.js
File metadata and controls
94 lines (76 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var common = require('./common/common_functions');
var csv_shared = require('./common/csv_shared');
var abis = require('./helpers/contract_abis');
var BigNumber = require('bignumber.js');
let distribData = new Array();
let fullFileData = new Array();
let badData = new Array();
let securityToken;
async function startScript(tokenSymbol, batchSize) {
securityToken = await csv_shared.start(tokenSymbol, batchSize);
let result_processing = await csv_shared.read('./CLI/data/accredited_data.csv', accredit_processing);
distribData = result_processing.distribData;
fullFileData = result_processing.fullFileData;
badData = result_processing.badData;
await saveInBlockchain();
};
function accredit_processing(csv_line) {
let isAddress = web3.utils.isAddress(csv_line[0]);
let isAccredited = (typeof JSON.parse(csv_line[1].toLowerCase())) == "boolean" ? JSON.parse(csv_line[1].toLowerCase()) : "not-valid";
if (isAddress &&
(isAccredited != "not-valid")) {
return [true, new Array(web3.utils.toChecksumAddress(csv_line[0]), isAccredited)]
} else {
return [false, new Array(csv_line[0], isAccredited)]
}
}
async function saveInBlockchain() {
let gtmModules;
try {
gtmModules = await securityToken.methods.getModulesByName(web3.utils.toHex('USDTieredSTO')).call();
} catch (e) {
console.log("Please attach USDTieredSTO module before launch this action.", e)
process.exit(0)
}
if (!gtmModules.length) {
console.log("Please attach USDTieredSTO module before launch this action.")
process.exit(0)
}
let usdTieredSTO = new web3.eth.Contract(abis.usdTieredSTO(), gtmModules[0]);
console.log(`
--------------------------------------------------------
----- Sending accreditation changes to blockchain -----
--------------------------------------------------------
`);
for (let i = 0; i < distribData.length; i++) {
try {
// Splitting the user arrays to be organized by input
for (let i = 0; i < distribData.length; i++) {
try {
let investorArray = [], isAccreditedArray = [];
for (let j = 0; j < distribData[i].length; j++) {
investorArray.push(distribData[i][j][0])
isAccreditedArray.push(distribData[i][j][1])
}
let changeAccreditedAction = await usdTieredSTO.methods.changeAccredited(investorArray, isAccreditedArray);
let tx = await common.sendTransaction(changeAccreditedAction);
console.log(`Batch ${i} - Attempting to change accredited accounts:\n\n`, investorArray, "\n\n");
console.log("---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------");
console.log("Change accredited transaction was successful.", tx.gasUsed, "gas used. Spent:", web3.utils.fromWei(BigNumber(tx.gasUsed * defaultGasPrice).toString(), "ether"), "Ether");
console.log("---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------\n\n");
} catch (err) {
console.log("ERROR:", err);
}
}
} catch (err) {
console.log("ERROR", err)
process.exit(0)
}
}
return;
}
module.exports = {
executeApp: async (tokenSymbol, batchSize) => {
return startScript(tokenSymbol, batchSize);
}
}