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:
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;
}

View File

@ -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

View File

@ -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;
}
*/

View File

@ -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

View File

@ -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;