From 2abddad76748c73443ef10cc8e1634fef5a1d1a5 Mon Sep 17 00:00:00 2001 From: Bram <84628826+sys-256@users.noreply.github.com> Date: Mon, 5 Jul 2021 13:05:22 +0200 Subject: [PATCH 1/3] Update worker.js --- worker.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 9 deletions(-) diff --git a/worker.js b/worker.js index ac49c12..ed45b16 100644 --- a/worker.js +++ b/worker.js @@ -1,18 +1,79 @@ importScripts("hashes.js"); -onmessage = function (job) +onmessage = function (event) { - console.log("Worker: Job recieved!"); - var job = job.data.split(","); - var difficulty = job[2]; + var username = event.data.username; + var usernameRecieved = true; + var rigid = event.data.rigid; + var rigidRecieved = true; - for (result=0; result < 100 * difficulty + 1; result++) + if (usernameRecieved && rigidRecieved) { - ducos1 = new Hashes.SHA1().hex(job[0] + result) - if (job[1] === ducos1) + //makes a connection with the server + var socket = new WebSocket("wss://server.duinocoin.com:14808/"); + //executes when the server sends a message + socket.onmessage = function (event) { - console.log("Share found! Sending the result (" + result + ") back to the main script!") - postMessage(result); + //this gets executed when the server sends something including "2.", which is the server version which it automattically sends + if (event.data.includes("2.")) + { + //shows the server version in console + console.log("The server is on version " + event.data); + //asks for a 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"); + //shows in the console that it's requesting a new job + console.log("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"); + //shows in the console that it's requesting a new job + console.log("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); + //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 + var difficulty = job[2]; + //looks at the time in milliseconds, and puts it in a variable + var startingTime = performance.now(); + //it starts hashing + for (result=0; result < 100 * difficulty + 1; result++) + { + //makes a variable called "ducos1", and it contains a calculated SHA1 hash for job[0] + the result + ducos1 = new Hashes.SHA1().hex(job[0] + result) + //executes if the given job is the same as the calculated hash + if (job[1] === ducos1) + { + //looks at the time in milliseconds, and puts it in a variable + var endingTime = performance.now(); + //calculates the time it took to generate the hash, and divides it by 1000 (to convert it from milliseconds to seconds) + var timeDifference = (endingTime - startingTime) / 1000; + //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..."); + //sends the result to the server + socket.send(result + "," + hashrate + ",Duino-JS v1.0 by Hoiboy19," + rigid) + } + } + } } } } From 4e3be9ad9c45686c11d410ecfcb9d3e3bbb5d925 Mon Sep 17 00:00:00 2001 From: Bram <84628826+sys-256@users.noreply.github.com> Date: Mon, 5 Jul 2021 13:06:05 +0200 Subject: [PATCH 2/3] Update duino-js.js --- duino-js.js | 67 ++++------------------------------------------------- 1 file changed, 5 insertions(+), 62 deletions(-) diff --git a/duino-js.js b/duino-js.js index 3adb8c0..63ff3f9 100644 --- a/duino-js.js +++ b/duino-js.js @@ -8,66 +8,9 @@ function startMiner () { //creates the worker worker = new Worker("worker.js"); - //makes a connection with the server - var socket = new WebSocket("wss://server.duinocoin.com:14808/"); - //executes when the server sends a message - socket.onmessage = function (event) - { - //this gets executed when the server sends something including "2.", which is the server version which it automattically sends - if (event.data.includes("2.")) - { - //shows the server version in console - console.log("The server is on version " + event.data); - //asks for a 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"); - //shows in the console that it's requesting a new job - console.log("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"); - //shows in the console that it's requesting a new job - console.log("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 + ", sending the result to the worker."); - //sends the data to the worker - worker.postMessage(event.data) - //looks at the time in milliseconds, and puts it in a variable - var startingTime = performance.now(); - //executes when the worker gives the result - worker.onmessage = function(event) - { - //shows in console that it recieved the workers message - console.log("Result recieved!") - //takes the data from the message and puts in the variable "result" - var result = event.data; - //looks at the time in milliseconds, and puts it in a variable - var endingTime = performance.now(); - //calculates the time it took to generate the hash, and divides it by 1000 (to convert it from milliseconds to seconds) - var timeDifference = (endingTime - startingTime) / 1000; - //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..."); - //sends the result to the server - socket.send(result + "," + hashrate + ",Duino-JS v1.0 by Hoiboy19," + rigid); - } - } - } + //passes the username and rigid to the worker + worker.postMessage({ + username: username, + rigid: rigid + }); } From 6081e5a571f6b361f8863e4920b0e6e5379ee658 Mon Sep 17 00:00:00 2001 From: Bram <84628826+sys-256@users.noreply.github.com> Date: Mon, 5 Jul 2021 13:12:29 +0200 Subject: [PATCH 3/3] Update worker.js --- worker.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/worker.js b/worker.js index ed45b16..ec0825b 100644 --- a/worker.js +++ b/worker.js @@ -1,12 +1,19 @@ +//imports the sha1 hex library importScripts("hashes.js"); +//when the main script send a message (it passes the username and rigid), this will get executed onmessage = function (event) { + //gets the username out of the send data and puts it in the variable "username" var username = event.data.username; + //sets usernameRecieved to true var usernameRecieved = true; + //gets the rigid out of the send data and puts it in the variable "rigid" var rigid = event.data.rigid; + //sets rigedRecieved to true var rigidRecieved = true; + //if usernameRecieved and rigidRecieved are both true, this will get executed aka it makes a connection with the server and starts mining if (usernameRecieved && rigidRecieved) { //makes a connection with the server