Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion components/stratum/include/stratum_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define COINBASE2_SIZE 128
#define MAX_REQUEST_IDS 1024
#define MAX_EXTRANONCE_2_LEN 32
#define MAX_POOL_MESSAGE_LEN 256

typedef enum
{
Expand All @@ -26,7 +27,8 @@ typedef enum
STRATUM_RESULT_SETUP,
STRATUM_RESULT_VERSION_MASK,
STRATUM_RESULT_SUBSCRIBE,
CLIENT_RECONNECT
CLIENT_RECONNECT,
CLIENT_SHOW_MESSAGE
} stratum_method;

typedef enum
Expand Down
19 changes: 19 additions & 0 deletions components/stratum/stratum_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ void STRATUM_V1_parse(StratumApiV1Message * message, const char * stratum_json)
result = CLIENT_RECONNECT;
} else if (strcmp("mining.ping", method_json->valuestring) == 0) {
result = MINING_PING;
} else if (strcmp("client.show_message", method_json->valuestring) == 0) {
result = CLIENT_SHOW_MESSAGE;
} else {
ESP_LOGI(TAG, "unhandled method in stratum message: %s", stratum_json);
}
Expand Down Expand Up @@ -401,6 +403,23 @@ void STRATUM_V1_parse(StratumApiV1Message * message, const char * stratum_json)
}
message->extranonce_str = strdup(extranonce_str);
message->extranonce_2_len = extranonce_2_len;
} else if (message->method == CLIENT_SHOW_MESSAGE) {
cJSON * params = cJSON_GetObjectItem(json, "params");
if (params && cJSON_IsArray(params) && cJSON_GetArraySize(params) > 0) {
cJSON * msg_item = cJSON_GetArrayItem(params, 0);
if (msg_item && cJSON_IsString(msg_item)) {
// Cap the pool message length to MAX_POOL_MESSAGE_LEN (256)
size_t msg_len = strlen(msg_item->valuestring);
if (msg_len > MAX_POOL_MESSAGE_LEN) {
char capped_msg[MAX_POOL_MESSAGE_LEN + 1];
strncpy(capped_msg, msg_item->valuestring, MAX_POOL_MESSAGE_LEN);
capped_msg[MAX_POOL_MESSAGE_LEN] = '\0';
ESP_LOGI(TAG, "Pool message: %s...", capped_msg);
} else {
ESP_LOGI(TAG, "Pool message: %s", msg_item->valuestring);
}
}
}
}
done:
cJSON_Delete(json);
Expand Down
Loading