mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-06-25 14:11:07 +02:00
stratum: add mining.set_difficulty message parse
This commit is contained in:
parent
24010c3fe8
commit
e246a84c86
@ -37,6 +37,8 @@ stratum_method parse_stratum_method(const char * stratum_json);
|
|||||||
|
|
||||||
mining_notify parse_mining_notify_message(const char * stratum_json);
|
mining_notify parse_mining_notify_message(const char * stratum_json);
|
||||||
|
|
||||||
|
uint32_t parse_mining_set_difficulty_message(const char * stratum_json);
|
||||||
|
|
||||||
void free_mining_notify(mining_notify params);
|
void free_mining_notify(mining_notify params);
|
||||||
|
|
||||||
int parse_stratum_subscribe_result_message(const char * result_json_str,
|
int parse_stratum_subscribe_result_message(const char * result_json_str,
|
||||||
|
@ -114,6 +114,21 @@ stratum_method parse_stratum_method(const char * stratum_json)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t parse_mining_set_difficulty_message(const char * stratum_json)
|
||||||
|
{
|
||||||
|
cJSON * json = cJSON_Parse(stratum_json);
|
||||||
|
cJSON * method = cJSON_GetObjectItem(json, "method");
|
||||||
|
if (method != NULL && cJSON_IsString(method)) {
|
||||||
|
assert(strcmp("mining.set_difficulty", method->valuestring) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON * params = cJSON_GetObjectItem(json, "params");
|
||||||
|
uint32_t difficulty = cJSON_GetArrayItem(params, 0)->valueint;
|
||||||
|
|
||||||
|
cJSON_Delete(json);
|
||||||
|
return difficulty;
|
||||||
|
}
|
||||||
|
|
||||||
mining_notify parse_mining_notify_message(const char * stratum_json)
|
mining_notify parse_mining_notify_message(const char * stratum_json)
|
||||||
{
|
{
|
||||||
cJSON * json = cJSON_Parse(stratum_json);
|
cJSON * json = cJSON_Parse(stratum_json);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "stratum_api.h"
|
#include "stratum_api.h"
|
||||||
|
|
||||||
TEST_CASE("Parse stratum method", "[mining.notify]")
|
TEST_CASE("Parse stratum method", "[stratum]")
|
||||||
{
|
{
|
||||||
const char * json_string = "{\"id\":null,\"method\":\"mining.notify\",\"params\":"
|
const char * json_string = "{\"id\":null,\"method\":\"mining.notify\",\"params\":"
|
||||||
"[\"1b4c3d9041\","
|
"[\"1b4c3d9041\","
|
||||||
@ -12,6 +12,17 @@ TEST_CASE("Parse stratum method", "[mining.notify]")
|
|||||||
"\"20000004\",\"1705c739\",\"64495522\",false]}";
|
"\"20000004\",\"1705c739\",\"64495522\",false]}";
|
||||||
stratum_method method = parse_stratum_method(json_string);
|
stratum_method method = parse_stratum_method(json_string);
|
||||||
TEST_ASSERT_EQUAL(MINING_NOTIFY, method);
|
TEST_ASSERT_EQUAL(MINING_NOTIFY, method);
|
||||||
|
|
||||||
|
const char * json_string_2 = "{\"id\":null,\"method\":\"mining.set_difficulty\",\"params\":[1638]}";
|
||||||
|
stratum_method method_2 = parse_stratum_method(json_string_2);
|
||||||
|
TEST_ASSERT_EQUAL(MINING_SET_DIFFICULTY, method_2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Parse stratum set_difficulty params", "[mining.set_difficulty]")
|
||||||
|
{
|
||||||
|
const char * json_string = "{\"id\":null,\"method\":\"mining.set_difficulty\",\"params\":[1638]}";
|
||||||
|
uint32_t difficulty = parse_mining_set_difficulty_message(json_string);
|
||||||
|
TEST_ASSERT_EQUAL(1638, difficulty);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse stratum notify params", "[mining.notify]")
|
TEST_CASE("Parse stratum notify params", "[mining.notify]")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user