-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWithdrawService.js
43 lines (36 loc) · 1.47 KB
/
WithdrawService.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
const { handleWithdrawals, checkWithrawals } = require('./SingleTxPerBlock')
const { handle } = require('./MultipleTxsPerBlock')
const { WithdrawServiceInterval, BatchSize, massivePerBlock } = require('./utils/constants.json')
function start() {
console.log("Withdrawal service started!!!")
handleWithdraws();
}
async function handleWithdraws() {
let pending = 0;
while (true) {
console.log("Checking WITHDRAWALS!!!")
if (pending == 0)
pending = await checkWithrawals();
if(pending > 0){
console.log(`Found #${pending} pending withdrawals!!!`)
let txs = pending / BatchSize;
if (txs > parseInt(txs)){
txs = parseInt(txs) +1;
} else {
txs = parseInt(txs)
}
console.log("Sending #"+txs+" transactions")
if (massivePerBlock)
await handle(txs, BatchSize);
else {
for(let i = 0; i < txs; i++){
await handleWithdrawals(txs, BatchSize);
}
}
pending = 0;
console.log("all withdrawals processed, check again")
}
await new Promise(resolve => setTimeout(resolve, parseInt(WithdrawServiceInterval) ? WithdrawServiceInterval : 2000)); // sleep for 2 seconds before checking pending withdrawals if WithdrawServiceInterval not defined
}
}
start();