-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdebugger.js
94 lines (83 loc) · 2.57 KB
/
debugger.js
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
require('dotenv').config;
const os = require('os');
const path = require('path');
const { Connection, PublicKey } = require('@_koi/web3.js');
class Debugger {
/*
Create .env file with following variables or direclty input values to be used in live-debugging mode.
*/
static taskID =
process.env.TASK_ID || '3sFhZoxfze7RQJqMGSR3L3gtg8AeiYZ6D42QwFc3nuEV';
static webpackedFilePath = process.env.WEBPACKED_FILE_PATH || 'dist/main.js';
static keywords = [process.env.TEST_KEYWORD] || ['TEST'];
static nodeDir = process.env.NODE_DIR || '';
static async getConfig() {
Debugger.nodeDir = await this.getNodeDirectory();
let destinationPath =
'executables/' + (await this.gettask_audit_program()) + '.js';
let logPath = 'namespace/' + Debugger.taskID + '/task.log';
console.log('Debugger.nodeDir', Debugger.nodeDir);
return {
webpackedFilePath: Debugger.webpackedFilePath,
destinationPath: destinationPath,
keywords: Debugger.keywords,
logPath: logPath,
nodeDir: Debugger.nodeDir,
taskID: Debugger.taskID,
};
}
static async getNodeDirectory() {
if (Debugger.nodeDir) {
return Debugger.nodeDir;
}
const homeDirectory = os.homedir();
let nodeDirectory;
switch (os.platform()) {
case 'linux':
nodeDirectory = path.join(
homeDirectory,
'.config',
'KOII-Desktop-Node',
);
break;
case 'darwin':
nodeDirectory = path.join(
homeDirectory,
'Library',
'Application Support',
'KOII-Desktop-Node',
);
break;
case 'win32':
// For Windows, construct the path explicitly as specified
nodeDirectory = path.join(
homeDirectory,
'AppData',
'Roaming',
'KOII-Desktop-Node',
);
break;
default:
nodeDirectory = path.join(
homeDirectory,
'AppData',
'Roaming',
'KOII-Desktop-Node',
);
}
return nodeDirectory;
}
static async gettask_audit_program() {
const connection = new Connection('https://testnet.koii.network');
const taskId = Debugger.taskID;
const accountInfo = await connection.getAccountInfo(new PublicKey(taskId));
if (!accountInfo) {
console.log(`${taskId} doesn't contain any distribution list data`);
return null;
}
const data = JSON.parse(accountInfo.data.toString());
console.log('data.task_audit_program', data.task_audit_program);
return data.task_audit_program;
}
}
module.exports = Debugger;