Add mining sugest dificulty

This commit is contained in:
BitMaker 2023-05-27 23:54:16 +02:00
parent ffd1664b21
commit a8b95f29c3
5 changed files with 29 additions and 26 deletions

View File

@ -61,8 +61,9 @@ void runStratumWorker(void *name) {
} }
//Test vars: //Test vars:
strcpy(poolString, "testServerIP"); strcpy(poolString, "rr");
strcpy(btcString,"mybtcString"); portNumber = 3333;
strcpy(btcString,"rr");
portNumber = 3002; portNumber = 3002;
if (!client.connected()) { if (!client.connected()) {
@ -86,11 +87,15 @@ void runStratumWorker(void *name) {
client.stop(); client.stop();
continue; continue;
} }
//strcpy(mWorker.name, btcString); strcpy(mWorker.wName, btcString);
//strcpy(mWorker.pass, "x"); strcpy(mWorker.wPass, "x");
// STEP 2: Pool authorize work (Block Info) // 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; isMinerSuscribed=true;
} }

View File

@ -5,7 +5,7 @@
// Mining // Mining
#define MAX_NONCE 5000000U #define MAX_NONCE 5000000U
#define TARGET_NONCE 471136297U #define TARGET_NONCE 471136297U
#define DEFAULT_DIFFICULTY 1e-9; #define DEFAULT_DIFFICULTY "1e-9"
#define TARGET_BUFFER_SIZE 64 #define TARGET_BUFFER_SIZE 64

View File

@ -132,6 +132,7 @@ bool tx_mining_auth(WiFiClient& client, const char * user, const char * pass)
return true; return true;
} }
stratum_method parse_mining_method(String line) stratum_method parse_mining_method(String line)
{ {
if(!verifyPayload(&line)) return STRATUM_PARSE_ERROR; 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); id = getNextId(id);
sprintf(payload, "{\"id\": %u, \"method\": \"mining.submit\", \"params\": [\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"]}\n", sprintf(payload, "{\"id\": %u, \"method\": \"mining.submit\", \"params\": [\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"]}\n",
id, id,
"bc1qvv469gmw4zz6qa4u4dsezvrlmqcqszwyfzhgwj", //mWorker.name, mWorker.wName,//"bc1qvv469gmw4zz6qa4u4dsezvrlmqcqszwyfzhgwj", //mWorker.name,
mJob.job_id, mJob.job_id,
mWorker.extranonce2, mWorker.extranonce2,
mJob.ntime, mJob.ntime,
@ -236,20 +237,15 @@ bool parse_mining_set_difficulty(String line, float& difficulty)
return true; return true;
} }
/* bool tx_suggest_difficulty(WiFiClient& client, const char * difficulty)
int suggest_difficulty(int socket, uint32_t difficulty)
{ {
char difficulty_msg[BUFFER_SIZE]; char payload[BUFFER] = {0};
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);
ESP_LOGI(TAG, "Received result %s", line); id = getNextId(id);
sprintf(payload, "{\"id\": %d, \"method\": \"mining.suggest_difficulty\", \"params\": [%s]}\n", id, difficulty);
free(line);
Serial.print(" Sending : "); Serial.print(payload);
return 1; client.print(payload);
return true;
} }
*/

View File

@ -20,8 +20,8 @@ typedef struct {
String extranonce1; String extranonce1;
String extranonce2; String extranonce2;
int extranonce2_size; int extranonce2_size;
String wName; char wName[80];
String wPass; char wPass[20];
} mining_subscribe; } mining_subscribe;
typedef struct { typedef struct {
@ -61,7 +61,9 @@ bool parse_mining_notify(String line, mining_job& mJob);
//Method Mining.submit //Method Mining.submit
bool tx_mining_submit(WiFiClient& client, mining_subscribe mWorker, mining_job mJob, unsigned long nonce); 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); bool parse_mining_set_difficulty(String line, float& difficulty);
#endif // STRATUM_API_H #endif // STRATUM_API_H

View File

@ -155,7 +155,7 @@ miner_data init_miner_data(void){
miner_data newMinerData; miner_data newMinerData;
newMinerData.difficulty = DEFAULT_DIFFICULTY; newMinerData.difficulty = atof(DEFAULT_DIFFICULTY);
newMinerData.inRun = false; newMinerData.inRun = false;
newMinerData.newJob = false; newMinerData.newJob = false;