From a8b95f29c3b6bf4ca1b577ad8e30bc170c8cddc1 Mon Sep 17 00:00:00 2001 From: BitMaker Date: Sat, 27 May 2023 23:54:16 +0200 Subject: [PATCH] Add mining sugest dificulty --- src/mining.cpp | 17 +++++++++++------ src/mining.h | 2 +- src/stratum.cpp | 26 +++++++++++--------------- src/stratum.h | 8 +++++--- src/utils.cpp | 2 +- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/mining.cpp b/src/mining.cpp index 65e1dcb..d5a3e67 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -61,8 +61,9 @@ void runStratumWorker(void *name) { } //Test vars: - strcpy(poolString, "testServerIP"); - strcpy(btcString,"mybtcString"); + strcpy(poolString, "rr"); + portNumber = 3333; + strcpy(btcString,"rr"); portNumber = 3002; if (!client.connected()) { @@ -86,11 +87,15 @@ void runStratumWorker(void *name) { client.stop(); continue; } - - //strcpy(mWorker.name, btcString); - //strcpy(mWorker.pass, "x"); + + strcpy(mWorker.wName, btcString); + strcpy(mWorker.wPass, "x"); // STEP 2: Pool authorize work (Block Info) - tx_mining_auth(client, btcString, "x"); //Don't verifies authoritzation, TODO + tx_mining_auth(client, mWorker.wName, mWorker.wPass); //Don't verifies authoritzation, TODO + //tx_mining_auth2(client, mWorker.wName, mWorker.wPass); //Don't verifies authoritzation, TODO + + // STEP 3: Suggest pool difficulty + tx_suggest_difficulty(client, DEFAULT_DIFFICULTY); isMinerSuscribed=true; } diff --git a/src/mining.h b/src/mining.h index 1e1b201..dfbb339 100644 --- a/src/mining.h +++ b/src/mining.h @@ -5,7 +5,7 @@ // Mining #define MAX_NONCE 5000000U #define TARGET_NONCE 471136297U -#define DEFAULT_DIFFICULTY 1e-9; +#define DEFAULT_DIFFICULTY "1e-9" #define TARGET_BUFFER_SIZE 64 diff --git a/src/stratum.cpp b/src/stratum.cpp index 98d9b68..3143210 100644 --- a/src/stratum.cpp +++ b/src/stratum.cpp @@ -132,6 +132,7 @@ bool tx_mining_auth(WiFiClient& client, const char * user, const char * pass) return true; } + stratum_method parse_mining_method(String line) { if(!verifyPayload(&line)) return STRATUM_PARSE_ERROR; @@ -202,7 +203,7 @@ bool tx_mining_submit(WiFiClient& client, mining_subscribe mWorker, mining_job m id = getNextId(id); sprintf(payload, "{\"id\": %u, \"method\": \"mining.submit\", \"params\": [\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"]}\n", id, - "bc1qvv469gmw4zz6qa4u4dsezvrlmqcqszwyfzhgwj", //mWorker.name, + mWorker.wName,//"bc1qvv469gmw4zz6qa4u4dsezvrlmqcqszwyfzhgwj", //mWorker.name, mJob.job_id, mWorker.extranonce2, mJob.ntime, @@ -236,20 +237,15 @@ bool parse_mining_set_difficulty(String line, float& difficulty) return true; } -/* -int suggest_difficulty(int socket, uint32_t difficulty) +bool tx_suggest_difficulty(WiFiClient& client, const char * difficulty) { - char difficulty_msg[BUFFER_SIZE]; - sprintf(difficulty_msg, "{\"id\": %d, \"method\": \"mining.suggest_difficulty\", \"params\": [%d]}\n", send_uid++, difficulty); - ESP_LOGI(TAG, "-> %s", difficulty_msg); - write(socket, difficulty_msg, strlen(difficulty_msg)); - char * line; - line = receive_jsonrpc_line(socket); + char payload[BUFFER] = {0}; - ESP_LOGI(TAG, "Received result %s", line); - - free(line); - - return 1; + id = getNextId(id); + sprintf(payload, "{\"id\": %d, \"method\": \"mining.suggest_difficulty\", \"params\": [%s]}\n", id, difficulty); + + Serial.print(" Sending : "); Serial.print(payload); + client.print(payload); + + return true; } -*/ \ No newline at end of file diff --git a/src/stratum.h b/src/stratum.h index 78573a2..cdd47b3 100644 --- a/src/stratum.h +++ b/src/stratum.h @@ -20,8 +20,8 @@ typedef struct { String extranonce1; String extranonce2; int extranonce2_size; - String wName; - String wPass; + char wName[80]; + char wPass[20]; } mining_subscribe; typedef struct { @@ -61,7 +61,9 @@ bool parse_mining_notify(String line, mining_job& mJob); //Method Mining.submit bool tx_mining_submit(WiFiClient& client, mining_subscribe mWorker, mining_job mJob, unsigned long nonce); -//Method Mining.set_difficulty +//Difficulty Methods +bool tx_suggest_difficulty(WiFiClient& client, const char * difficulty); bool parse_mining_set_difficulty(String line, float& difficulty); + #endif // STRATUM_API_H \ No newline at end of file diff --git a/src/utils.cpp b/src/utils.cpp index e9acdd8..4775362 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -155,7 +155,7 @@ miner_data init_miner_data(void){ miner_data newMinerData; - newMinerData.difficulty = DEFAULT_DIFFICULTY; + newMinerData.difficulty = atof(DEFAULT_DIFFICULTY); newMinerData.inRun = false; newMinerData.newJob = false;