|
|
@@ -4,6 +4,8 @@ class StratumClient { |
|
|
|
constructor(ip, port, miner) { |
|
|
|
this.name = ip+":"+port; |
|
|
|
|
|
|
|
this.queue = []; |
|
|
|
this.working = false; |
|
|
|
this.nounceReady = false; |
|
|
|
this.difficultyReady = false; |
|
|
|
this.miner = miner; |
|
|
@@ -16,16 +18,24 @@ class StratumClient { |
|
|
|
} |
|
|
|
|
|
|
|
async startWork() { |
|
|
|
if (!this.work) |
|
|
|
if (this.working) |
|
|
|
return; |
|
|
|
if (this.queue.length === 0) |
|
|
|
return; |
|
|
|
|
|
|
|
var work = this.queue.shift(); |
|
|
|
|
|
|
|
this.log("Starting work", this.work.id); |
|
|
|
this.log("Starting work", work.id); |
|
|
|
this.working = true; |
|
|
|
var res; |
|
|
|
try { |
|
|
|
res = await this.miner.startWork(this.work); |
|
|
|
res = await this.miner.startWork(work); |
|
|
|
} catch (err) { |
|
|
|
console.trace(err); |
|
|
|
return; |
|
|
|
} finally { |
|
|
|
this.working = false; |
|
|
|
this.startWork(); |
|
|
|
} |
|
|
|
this.log("Work done,", res.toString("hex")); |
|
|
|
} |
|
|
@@ -43,7 +53,7 @@ class StratumClient { |
|
|
|
}; |
|
|
|
this.log("Got work", work.id); |
|
|
|
|
|
|
|
this.work = work; |
|
|
|
this.queue.push(work); |
|
|
|
if (this.difficultyReady && this.nounceReady) |
|
|
|
this.startWork(); |
|
|
|
}); |