Skip to content

Commit

Permalink
Update worker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
revoxhere authored Sep 17, 2021
1 parent 8253fe5 commit 1091ab9
Showing 1 changed file with 20 additions and 39 deletions.
59 changes: 20 additions & 39 deletions js/webminer/worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
importScripts("hashes.js");
importScripts("hashes.js");

function getTime()
{
function getTime() {
let date = new Date();
let h = date.getHours();
let m = date.getMinutes();
Expand All @@ -14,63 +13,48 @@ function getTime()
return h + ":" + m + ":" + s;
}

onmessage = function (event)
{
if (event.data.startsWith("Start"))
{
onmessage = function (event) {
if (event.data.startsWith("Start")) {
let getData = event.data.split(",");

let username = getData[1];
let rigid = getData[2];
let workerVer = getData[3];

if (rigid === "")
{
let wallet_id = getData[4];

if (rigid === "") {
rigid = "None";
}

function connect()
{
function connect() {
var socket = new WebSocket("wss://server.duinocoin.com:14808");

socket.onmessage = function(event)
{
socket.onmessage = function (event) {
var serverMessage = event.data;
if (serverMessage.includes("2."))
{
if (serverMessage.includes("2.")) {
console.log(`${getTime()} | ` + "CPU" + workerVer + ": Connected to node. Server is on version " + serverMessage);
socket.send("JOB," + username + ",LOW");
}
else if (serverMessage.includes("GOOD"))
{
} else if (serverMessage.includes("GOOD")) {
console.log(`${getTime()} | ` + "CPU" + workerVer + ": Share accepted:" + result);
postMessage("GoodShare");
socket.send("JOB," + username + ",LOW");
}
else if (serverMessage.includes("BAD"))
{
} else if (serverMessage.includes("BAD")) {
console.log(`${getTime()} | ` + "CPU" + workerVer + ": Share rejected: " + result);
postMessage("BadShare");
socket.send("JOB," + username + ",LOW");
}
else if (serverMessage.includes("This user doesn't exist"))
{
} else if (serverMessage.includes("This user doesn't exist")) {
console.log(`${getTime()} | ` + "CPU" + workerVer + ": User not found!");
postMessage("Error");
}
else if (serverMessage.length > 40)
{
} else if (serverMessage.length > 40) {
console.log(`${getTime()} | ` + "CPU" + workerVer + ": Job received: " + serverMessage);
job = serverMessage.split(",");
difficulty = job[2];
postMessage("UpdateDiff," + difficulty + "," + workerVer);

startingTime = performance.now();
for (result = 0; result < 100 * difficulty + 1; result++)
{
for (result = 0; result < 100 * difficulty + 1; result++) {
var ducos1 = new Hashes.SHA1().hex(job[0] + result);
if (job[1] === ducos1)
{
if (job[1] === ducos1) {
endingTime = performance.now();
timeDifference = (endingTime - startingTime) / 1000;
hashrate = (result / timeDifference).toFixed(2);
Expand All @@ -79,23 +63,20 @@ onmessage = function (event)
console.log(`${getTime()} | ` + "CPU" + workerVer + ": Share found: " + result + " Time: " + timeDifference + " Hashrate: " + hashrate + "H/s");
postMessage("UpdateHashrate," + timeDifference + "," + hashrate + "," + workerVer);

socket.send(result + "," + hashrate + ",Official Webminer v2.6.5," + rigid);
socket.send(result + "," + hashrate + ",Official Web Miner 2.73," + rigid + ",," + wallet_id);
}
}
}
}

socket.onerror = function(event)
{
socket.onerror = function (event) {
console.error("CPU" + workerVer + "WebSocket error observed, trying to reconnect: ", event);
socket.close("Reason: Error occured in WebWorker.");
}

socket.onclose = function(event)
{
socket.onclose = function (event) {
console.error("CPU" + workerVer + ": WebSocket close observed, trying to reconnect: ", event);
setTimeout(function()
{
setTimeout(function () {
connect();
}, 5000);
}
Expand Down

6 comments on commit 1091ab9

@sys-256
Copy link
Contributor

@sys-256 sys-256 commented on 1091ab9 Sep 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lmk if you want js-sha1 to calculate the hashes. It's about the same size (my compressed version), but hashes up to 3 times faster.

@revoxhere
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What for?

@sys-256
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for faster hashrate

@sys-256
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

higher*

@revoxhere
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Higher hashrate does NOT equal higher income.

@IdotMaster1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rock

Please sign in to comment.