Skip to content

Commit

Permalink
Update worker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sys-256 authored Jul 8, 2021
1 parent 18987fe commit c801790
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ onmessage = function (event)
var username = event.data.username;
//gets the rigid out of the send data and puts it in the variable "rigid"
var rigid = event.data.rigid;
//gets the workerVer out of the send data and puts it in the variable "workerVer"
var workerVer = event.data.workerVer;

//makes a connection with the server
var socket = new WebSocket("wss://server.duinocoin.com:14808/");
Expand All @@ -18,37 +20,37 @@ onmessage = function (event)
if (event.data.includes("2."))
{
//shows the server version in console
console.log("The server is on version " + event.data);
console.log("CPU" + workerVer + ": The server is on version " + event.data);
//shows in the console that it's requesting a new job
console.log("Requesting a new job...\n");
console.log("CPU" + workerVer + ": Requesting a new job...\n");
//asks for a new job
socket.send("JOB," + username + ",LOW")
}
//this gets executed when the server sends something including "GOOD", which means the share was correct
else if (event.data.includes("GOOD"))
{
//shows in the console that the share was correct
console.log(" and the share was correct!\n");
console.log("CPU" + workerVer + ": and the share was correct!\n");
//shows in the console that it's requesting a new job
console.log("Requesting a new job...\n");
console.log("CPU" + workerVer + ": Requesting a new job...\n");
//asks for a new job
socket.send("JOB," + username + ",LOW")
}
//this gets executed when the server sends something including "BAD", which means the share was wrong
else if (event.data.includes("BAD"))
{
//shows in the console that the share was wrong
console.log(" and the share was wrong...\n");
console.log("CPU" + workerVer + ": and the share was wrong...\n");
//shows in the console that it's requesting a new job
console.log("Requesting a new job...\n");
console.log("CPU" + workerVer + ": Requesting a new job...\n");
//asks for a new job
socket.send("JOB," + username + ",LOW")
}
//this gets executed when the server sends something which doesn't agree with the one's above, which means it's probably a job
else
{
//shows in console that it recieved a new job, and shows the contents
console.log("New job recieved! It contains: " + event.data);
console.log("CPU" + workerVer + ": New job recieved! It contains: " + event.data);
//splits the job in multiple pieces
var job = event.data.split(",");
//the difficulty is piece number 2 (counting from 0), and gets selected as a variable
Expand All @@ -70,7 +72,7 @@ onmessage = function (event)
//calculates the hashrate with max 2 decimals
var hashrate = (result / timeDifference).toFixed(2);
//shows the hashrate in the console
console.log("The hashrate is " + hashrate + " H/s. Sending the result back to the server...");
console.log("CPU" + workerVer + ": The hashrate is " + hashrate + " H/s. Sending the result back to the server...");
//sends the result to the server
socket.send(result + "," + hashrate + ",Duino-JS v2.1 by Hoiboy19," + rigid)
}
Expand Down

0 comments on commit c801790

Please sign in to comment.