Change stratum message_id to 64bit

This commit is contained in:
mutatrum 2024-06-25 15:34:15 +02:00
parent 336ed3aaa9
commit e3edb87b6c
3 changed files with 22 additions and 2 deletions

View File

@ -45,7 +45,7 @@ typedef struct
char * extranonce_str;
int extranonce_2_len;
int16_t message_id;
int64_t message_id;
// Indicates the type of request the message represents.
stratum_method method;

View File

@ -111,7 +111,7 @@ void STRATUM_V1_parse(StratumApiV1Message * message, const char * stratum_json)
cJSON * json = cJSON_Parse(stratum_json);
cJSON * id_json = cJSON_GetObjectItem(json, "id");
int16_t parsed_id = -1;
int64_t parsed_id = -1;
if (id_json != NULL && cJSON_IsNumber(id_json)) {
parsed_id = id_json->valueint;
}

View File

@ -125,6 +125,26 @@ TEST_CASE("Parse stratum result success", "[stratum]")
TEST_ASSERT_TRUE(stratum_api_v1_message.response_success);
}
TEST_CASE("Parse stratum result success with large id", "[stratum]")
{
StratumApiV1Message stratum_api_v1_message = {};
const char *json_string = "{\"id\":32769,\"error\":null,\"result\":true}";
STRATUM_V1_parse(&stratum_api_v1_message, json_string);
TEST_ASSERT_EQUAL(32768, stratum_api_v1_message.message_id);
TEST_ASSERT_EQUAL(STRATUM_RESULT, stratum_api_v1_message.method);
TEST_ASSERT_TRUE(stratum_api_v1_message.response_success);
}
TEST_CASE("Parse stratum result success with larger id", "[stratum]")
{
StratumApiV1Message stratum_api_v1_message = {};
const char *json_string = "{\"id\":65536,\"error\":null,\"result\":true}";
STRATUM_V1_parse(&stratum_api_v1_message, json_string);
TEST_ASSERT_EQUAL(65536, stratum_api_v1_message.message_id);
TEST_ASSERT_EQUAL(STRATUM_RESULT, stratum_api_v1_message.method);
TEST_ASSERT_TRUE(stratum_api_v1_message.response_success);
}
TEST_CASE("Parse stratum result error", "[stratum]")
{
StratumApiV1Message stratum_api_v1_message = {};