generated from koii-network/task-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
105 lines (85 loc) · 3.57 KB
/
index.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
95
96
97
98
99
100
101
102
103
104
105
const { coreLogic } = require('./coreLogic');
const {
namespaceWrapper,
taskNodeAdministered,
app,
} = require('@_koii/namespace-wrapper');
if (app) {
// Write your Express Endpoints here.
// Ex. app.post('/accept-cid', async (req, res) => {})
// Sample API that return your task state
app.get('/taskState', async (req, res) => {
const state = await namespaceWrapper.getTaskState();
console.log('TASK STATE', state);
res.status(200).json({ taskState: state });
});
// Sample API that return the value stored in NeDB
app.get('/value', async (req, res) => {
const value = await namespaceWrapper.storeGet('value');
console.log('value', value);
res.status(200).json({ value: value });
});
}
async function setup() {
/*######################################################
################## DO NOT EDIT BELOW #################
######################################################*/
await namespaceWrapper.defaultTaskSetup();
process.on('message', m => {
console.log('CHILD got message:', m);
if (m.functionCall == 'submitPayload') {
console.log('submitPayload called');
coreLogic.submitTask(m.roundNumber);
} else if (m.functionCall == 'auditPayload') {
console.log('auditPayload called');
coreLogic.auditTask(m.roundNumber);
} else if (m.functionCall == 'executeTask') {
console.log('executeTask called');
coreLogic.task(m.roundNumber);
} else if (m.functionCall == 'generateAndSubmitDistributionList') {
console.log('generateAndSubmitDistributionList called');
coreLogic.selectAndGenerateDistributionList(
m.roundNumber,
m.isPreviousRoundFailed,
);
} else if (m.functionCall == 'distributionListAudit') {
console.log('distributionListAudit called');
coreLogic.auditDistribution(m.roundNumber);
}
});
/*######################################################
################ DO NOT EDIT ABOVE ###################
######################################################*/
/* GUIDE TO CALLS K2 FUNCTIONS MANUALLY
If you wish to do the development by avoiding the timers then you can do the intended calls to K2
directly using these function calls.
To disable timers please set the TIMERS flag in task-node ENV to disable
NOTE : K2 will still have the windows to accept the submission value, audit, so you are expected
to make calls in the intended slots of your round time.
*/
// Get the task state
// console.log(await namespaceWrapper.getTaskState());
// Get round
// const round = await namespaceWrapper.getRound();
// console.log("ROUND", round);
// Call to do the work for the task
// await coreLogic.task();
// Submission to K2 (Preferablly you should submit the cid received from IPFS)
// await coreLogic.submitTask(round - 1);
// Audit submissions
// await coreLogic.auditTask(round - 1);
// Upload distribution list to K2
// await coreLogic.selectAndGenerateDistributionList(10);
// Audit distribution list
// await coreLogic.auditDistribution(round - 2);
// Payout trigger
// const responsePayout = await namespaceWrapper.payoutTrigger();
// console.log("RESPONSE TRIGGER", responsePayout);
// Logs to be displayed on desktop-node
// namespaceWrapper.logger('error', 'Internet connection lost');
// await namespaceWrapper.logger('warn', 'Stakes are running low');
// await namespaceWrapper.logger('log', 'Task is running');
}
if (taskNodeAdministered) {
setup();
}