cors, bug

This commit is contained in:
Ben Wilson
2023-06-21 14:32:33 -04:00
parent 4a937ddd8d
commit 2547b06a48
6 changed files with 126 additions and 24 deletions
+45
View File
@@ -0,0 +1,45 @@
export class StratumV1ClientStatistics {
public bestDifficulty: number = 0;
public historicSubmissions = [];
constructor() {
}
public addSubmission(targetDifficulty: number, submissionDifficulty: number, networkDifficulty: number) {
if (this.historicSubmissions.length >= 1000) {
this.historicSubmissions.shift();
}
this.historicSubmissions.push({
difficulty: targetDifficulty,
time: new Date()
});
if (submissionDifficulty > this.bestDifficulty) {
this.bestDifficulty = submissionDifficulty;
}
}
public getHashrate() {
return this.historicSubmissions.reduce((pre, cur, idx, arr) => {
if (idx === 0) {
pre.time = cur.time;
}
pre.difficulty += cur.difficulty;
if (arr.length - 1 === idx) {
const duration = cur.time.getTime() - pre.time.getTime();
const sumDifficulty = pre.difficulty;
return (sumDifficulty * 4294967296) / (duration * 1000000)
}
return pre;
}, {
difficulty: 0,
time: undefined
})
}
}