stratum_api: parse the uint32_t values from the mining.notify message

This commit is contained in:
johnny9 2023-05-06 16:22:00 -04:00
parent 83ad62322a
commit 901d2da341
4 changed files with 9 additions and 5 deletions

View File

@ -17,10 +17,8 @@ typedef struct {
uint8_t * merkle_branches;
size_t n_merkle_branches;
uint32_t version;
uint32_t curtime;
uint32_t bits;
uint32_t target;
uint32_t nonce;
uint32_t ntime;
} mining_notify;
typedef enum {

View File

@ -140,6 +140,10 @@ mining_notify parse_mining_notify_message(const char * stratum_json)
hex2bin(cJSON_GetArrayItem(merkle_branch, i)->valuestring, new_work.merkle_branches + HASH_SIZE * i, HASH_SIZE * 2);
}
new_work.version = strtoul(cJSON_GetArrayItem(params, 5)->valuestring, NULL, 16);
new_work.target = strtoul(cJSON_GetArrayItem(params, 6)->valuestring, NULL, 16);
new_work.ntime = strtoul(cJSON_GetArrayItem(params, 7)->valuestring, NULL, 16);
cJSON_Delete(json);
return new_work;
}

View File

@ -41,10 +41,9 @@ TEST_CASE("Validate bm job construction", "[mining]")
{
const char * merkle_root = "adbcbc21e20388422198a55957aedfa0e61be0b8f2b87d7c08510bb9f099a893";
const char * prev_block_hash = "ef4b9a48c7986466de4adc002f7337a6e121bc43000376ea0000000000000000";
char * version = "40000002";
char * version = "20000004";
uint32_t target = 0x39c70517;
uint32_t ntime = 0x22554964;
printf("%lu", ntime);
bm_job job = construct_bm_job(version, prev_block_hash, merkle_root, ntime, target);
TEST_ASSERT_EQUAL_UINT32(job.merkle_root_end, 0x93a899f0);

View File

@ -28,6 +28,9 @@ TEST_CASE("Parse stratum notify params", "[mining.notify]")
TEST_ASSERT_EQUAL_STRING("ef4b9a48c7986466de4adc002f7337a6e121bc43000376ea0000000000000000", params.prev_block_hash);
TEST_ASSERT_EQUAL_STRING("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4b03a5020cfabe6d6d379ae882651f6469f2ed6b8b40a4f9a4b41fd838a3ad6de8cba775f4e8f1d3080100000000000000", params.coinbase_1);
TEST_ASSERT_EQUAL_STRING("41903d4c1b2f736c7573682f0000000003ca890d27000000001976a9147c154ed1dc59609e3d26abb2df2ea3d587cd8c4188ac00000000000000002c6a4c2952534b424c4f434b3a4cb4cb2ddfc37c41baf5ef6b6b4899e3253a8f1dfc7e5dd68a5b5b27005014ef0000000000000000266a24aa21a9ed5caa249f1af9fbf71c986fea8e076ca34ae3514fb2f86400561b28c7b15949bf00000000", params.coinbase_2);
TEST_ASSERT_EQUAL_UINT32(0x20000004, params.version);
TEST_ASSERT_EQUAL_UINT32(0x1705c739, params.target);
TEST_ASSERT_EQUAL_UINT32(0x64495522, params.ntime);
}
TEST_CASE("Test mining.subcribe result parsing", "[mining.subscribe]")