diff --git a/src/lib/defaults.hpp b/src/lib/defaults.hpp index 3d28829..7ca89fb 100644 --- a/src/lib/defaults.hpp +++ b/src/lib/defaults.hpp @@ -58,11 +58,8 @@ #define DEFAULT_BITAXE_ENABLED false #define DEFAULT_BITAXE_HOSTNAME "bitaxe1" -#define MINING_POOL_NAME_OCEAN "ocean" -#define MINING_POOL_NAME_BRAIINS "braiins" - #define DEFAULT_MINING_POOL_STATS_ENABLED false -#define DEFAULT_MINING_POOL_NAME MINING_POOL_NAME_OCEAN +#define DEFAULT_MINING_POOL_NAME "ocean" #define DEFAULT_MINING_POOL_USER "38Qkkei3SuF1Eo45BaYmRHUneRD54yyTFy" // Random actual Ocean hasher #define DEFAULT_ZAP_NOTIFY_ENABLED false diff --git a/src/lib/mining_pool_stats_fetch.cpp b/src/lib/mining_pool_stats_fetch.cpp index 9de1cd7..3d440af 100644 --- a/src/lib/mining_pool_stats_fetch.cpp +++ b/src/lib/mining_pool_stats_fetch.cpp @@ -2,6 +2,7 @@ TaskHandle_t miningPoolStatsFetchTaskHandle; +std::string miningPoolName; std::string miningPoolStatsHashrate; int miningPoolStatsDailyEarnings; @@ -25,19 +26,21 @@ void taskMiningPoolStatsFetch(void *pvParameters) http.setUserAgent(USER_AGENT); String miningPoolStatsApiUrl; + miningPoolName = preferences.getString("miningPoolName", DEFAULT_MINING_POOL_NAME).c_str(); + std::string httpHeaderKey = ""; std::string httpHeaderValue; - if (preferences.getString("miningPoolName", DEFAULT_MINING_POOL_NAME) == MINING_POOL_NAME_OCEAN) { + if (miningPoolName == "ocean") { miningPoolStatsApiUrl = "https://api.ocean.xyz/v1/statsnap/" + preferences.getString("miningPoolUser", DEFAULT_MINING_POOL_USER); } - else if (preferences.getString("miningPoolName", DEFAULT_MINING_POOL_NAME) == MINING_POOL_NAME_BRAIINS) { + else if (miningPoolName == "braiins") { miningPoolStatsApiUrl = "https://pool.braiins.com/accounts/profile/json/btc/"; httpHeaderKey = "Pool-Auth-Token"; httpHeaderValue = preferences.getString("miningPoolUser", DEFAULT_MINING_POOL_USER).c_str(); } else { - Serial.println("Unknown mining pool: \"" + preferences.getString("miningPoolName", DEFAULT_MINING_POOL_NAME) + "\""); + // Unknown mining pool / missing implementation continue; } @@ -55,13 +58,11 @@ void taskMiningPoolStatsFetch(void *pvParameters) JsonDocument doc; deserializeJson(doc, payload); - Serial.println(doc.as()); - - if (preferences.getString("miningPoolName", DEFAULT_MINING_POOL_NAME) == MINING_POOL_NAME_OCEAN) { + if (miningPoolName == "ocean") { miningPoolStatsHashrate = doc["result"]["hashrate_300s"].as(); miningPoolStatsDailyEarnings = int(doc["result"]["estimated_earn_next_block"].as() * 100000000); } - else if (preferences.getString("miningPoolName", DEFAULT_MINING_POOL_NAME) == MINING_POOL_NAME_BRAIINS) { + else if (miningPoolName == "braiins") { // Reports hashrate in specific hashrate units (e.g. Gh/s); we want raw total hashes per second. std::string hashrateUnit = doc["btc"]["hash_rate_unit"].as(); int multiplier = 0;