-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconfig.js
More file actions
103 lines (89 loc) · 2.97 KB
/
config.js
File metadata and controls
103 lines (89 loc) · 2.97 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
95
96
97
98
99
100
101
102
103
/* eslint-disable global-require */
/*************************************************************************
* [2018] - [2020] Rand Labs Inc.
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Rand Labs Inc.
* The intellectual and technical concepts contained
* herein are proprietary to Rand Labs Inc.
*/
const process = require('process');
const path = require('path');
const algosdk = require('algosdk');
// ------------------------------------------------------------------------------
let settings = null;
let algodClient = null;
let addresses = {};
let signatures = {};
// ------------------------------------------------------------------------------
function initialize() {
// setup the settings filename
let filename = 'settings';
for (let idx = 0; idx < process.argv.length; idx++) {
// eslint-disable-next-line security/detect-object-injection
if (process.argv[idx] == '--settings') {
if (idx + 1 >= process.argv.length) {
throw new Error('ERROR: Missing filename in "--settings" parameter.');
}
filename = process.argv[idx + 1];
}
}
try {
filename = path.resolve(__dirname, '.', filename);
// eslint-disable-next-line security/detect-non-literal-require
settings = require(filename);
recoverAccounts();
setupClient();
settings.algodClient = algodClient;
settings.signatures = signatures;
settings.addresses = addresses;
settings.admin = !settings.noAdmin;
}
catch (err) {
throw new Error('ERROR: Unable to load settings file.');
}
settings.base_dir = path.dirname(filename);
if (!settings.base_dir.endsWith(path.sep)) {
settings.base_dir += path.sep;
}
return settings;
}
function recoverAccounts () {
for (let i = 0; i < 20; i++) {
if (settings["account" + i]) {
addresses[i] = settings["account" + i].publicKey;
if (settings["account" + i].privateKey) {
signatures[addresses[i]] = algosdk.mnemonicToSecretKey(settings["account" + i].privateKey);
}
}
else {
break;
}
}
if (settings.minterAccount) {
settings.minterAddress = settings.minterAccount.publicKey;
signatures[settings.minterAddress] = algosdk.mnemonicToSecretKey(settings.minterAccount.privateKey);
}
if (settings.dispenserAccount) {
settings.dispenserAddress = settings.dispenserAccount.publicKey;
signatures[settings.dispenserAddress] = algosdk.mnemonicToSecretKey(settings.dispenserAccount.privateKey);
}
if (settings.clearStateAttackAccount) {
settings.clearStateAttackAddr = settings.clearStateAttackAccount.publicKey;
signatures[settings.clearStateAttackAddr] = algosdk.mnemonicToSecretKey(settings.clearStateAttackAccount.privateKey);
}
}
function setupClient() {
if (!algodClient) {
algodClient = new algosdk.Algodv2(settings.algodClient.apiToken, settings.algodClient.server, settings.algodClient.port);
}
else {
return algodClient;
}
return algodClient;
}
// ------------------------------------------------------------------------------
module.exports = {
initialize
};