This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
forked from koii-network/task-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
94 lines (69 loc) · 2.66 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
const { coreLogic } = require('./coreLogic');
const { app } = require('./init');
const {
namespaceWrapper,
taskNodeAdministered,
} = require('./namespaceWrapper');
async function setup() {
console.log('setup function called');
// Run default setup
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();
} else if (m.functionCall == 'generateAndSubmitDistributionList') {
console.log('generateAndSubmitDistributionList called');
coreLogic.submitDistributionList(m.roundNumber);
} else if (m.functionCall == 'distributionListAudit') {
console.log('distributionListAudit called');
coreLogic.auditDistribution(m.roundNumber);
}
});
/* 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.submitDistributionList(round - 2)
// Audit distribution list
//await coreLogic.auditDistribution(round - 2);
// Payout trigger
// const responsePayout = await namespaceWrapper.payoutTrigger();
// console.log("RESPONSE TRIGGER", responsePayout);
}
if (taskNodeAdministered) {
setup();
}
if (app) {
// Write your Express Endpoints here.
// For Example
// 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 });
});
}