mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-07-09 17:40:03 +02:00
stratum_api: add method to check if previous work should be abandoned
This commit is contained in:
@ -45,4 +45,6 @@ int parse_stratum_subscribe_result_message(const char * result_json_str,
|
|||||||
|
|
||||||
int auth_to_stratum(int socket, const char * username);
|
int auth_to_stratum(int socket, const char * username);
|
||||||
|
|
||||||
|
int should_abandon_work(const char * mining_notify_json_str);
|
||||||
|
|
||||||
#endif // STRATUM_API_H
|
#endif // STRATUM_API_H
|
@ -230,3 +230,12 @@ int auth_to_stratum(int socket, const char * username)
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int should_abandon_work(const char * mining_notify_json_str)
|
||||||
|
{
|
||||||
|
cJSON * root = cJSON_Parse(mining_notify_json_str);
|
||||||
|
cJSON * params = cJSON_GetObjectItem(root, "params");
|
||||||
|
int value = cJSON_IsTrue(cJSON_GetArrayItem(params, 8));
|
||||||
|
cJSON_Delete(root);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
@ -48,3 +48,19 @@ TEST_CASE("Test mining.subcribe result parsing", "[mining.subscribe]")
|
|||||||
TEST_ASSERT_EQUAL_STRING(extranonce, "e9695791");
|
TEST_ASSERT_EQUAL_STRING(extranonce, "e9695791");
|
||||||
TEST_ASSERT_EQUAL_INT(extranonce2_len, 4);
|
TEST_ASSERT_EQUAL_INT(extranonce2_len, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Test mining.notify abandon old work", "[mining.notify]")
|
||||||
|
{
|
||||||
|
const char * mining_notify_false = "{\"id\":null,\"method\":\"mining.notify\",\"params\":"
|
||||||
|
"[\"\",\"\",\"\",\"\",[\"\"],\"\",\"\",\"\",false]}";
|
||||||
|
const char * mining_notify_true = "{\"id\":null,\"method\":\"mining.notify\",\"params\":"
|
||||||
|
"[\"\",\"\",\"\",\"\",[\"\"],\"\",\"\",\"\",true]}";
|
||||||
|
const char * mining_notify_invalid = "{\"id\":null,\"method\":\"mining.notify\",\"params\":"
|
||||||
|
"[\"\",\"\",\"\",\"\",[\"\"],\"\",\"\",\"\",3]}";
|
||||||
|
const char * mining_notify_invalid_2 = "{\"id\":null,\"method\":\"mining.notify\",\"params\":"
|
||||||
|
"[\"\",\"\",\"\",\"\",[\"\"],\"\",\"\",\"\"]}";
|
||||||
|
TEST_ASSERT_EQUAL_INT(0, should_abandon_work(mining_notify_false));
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, should_abandon_work(mining_notify_true));
|
||||||
|
TEST_ASSERT_EQUAL_INT(0, should_abandon_work(mining_notify_invalid));
|
||||||
|
TEST_ASSERT_EQUAL_INT(0, should_abandon_work(mining_notify_invalid_2));
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
version = b'\x04\x00\x00\x20' # little-endian encoding of version 1
|
version = b'\x04\x00\x00\x20' # little-endian encoding of version
|
||||||
prev_block_hash = bytes.fromhex('ef4b9a48c7986466de4adc002f7337a6e121bc43000376ea0000000000000000')
|
prev_block_hash = bytes.fromhex('ef4b9a48c7986466de4adc002f7337a6e121bc43000376ea0000000000000000')
|
||||||
merkle_root = bytes.fromhex('adbcbc21e20388422198a55957aedfa0e61be0b8f2b87d7c08510bb9f099a893')
|
merkle_root = bytes.fromhex('adbcbc21e20388422198a55957aedfa0e61be0b8f2b87d7c08510bb9f099a893')
|
||||||
timestamp = b'\x64\x49\x55\x22' # little-endian encoding of Unix timestamp 1683385928
|
timestamp = b'\x64\x49\x55\x22' # little-endian encoding of Unix timestamp 1683385928
|
||||||
|
Reference in New Issue
Block a user