-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpool.js
More file actions
43 lines (36 loc) · 993 Bytes
/
pool.js
File metadata and controls
43 lines (36 loc) · 993 Bytes
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
// pool.js
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const BAL_PATH = path.join(process.cwd(), 'balances.json');
function loadBalances() {
try {
if (fs.existsSync(BAL_PATH)) {
return JSON.parse(fs.readFileSync(BAL_PATH, 'utf8'));
}
} catch (e) {
console.warn('⚠️ Failed reading balances.json:', e.message);
}
return {};
}
function saveBalances(balances) {
fs.writeFileSync(BAL_PATH, JSON.stringify(balances, null, 2));
}
function sha256(data) {
return crypto.createHash('sha256').update(data).digest('hex');
}
function calcPPSReward(blockReward, networkDifficulty, shareDifficulty) {
const net = Math.pow(16, networkDifficulty);
const share = Math.pow(16, shareDifficulty);
return blockReward / (net / share);
}
function startsWithZeros(hash, zeros) {
return hash.startsWith('0'.repeat(zeros));
}
module.exports = {
loadBalances,
saveBalances,
sha256,
calcPPSReward,
startsWithZeros
};