Skip to content

Commit

Permalink
Add support for fallback user/password
Browse files Browse the repository at this point in the history
  • Loading branch information
eandersson committed Sep 27, 2024
1 parent 28891a8 commit ba66e35
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 10 deletions.
12 changes: 12 additions & 0 deletions main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ menu "Stratum Configuration"
help
Stratum password to use with pool

config FALLBACK_STRATUM_USER
string "Fallback Stratum username"
default "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa.bitaxe"
help
Fallback Stratum user to use with pool

config FALLBACK_STRATUM_PW
string "Fallback Stratum password"
default "x"
help
Fallback Stratum password to use with pool

config STRATUM_DIFFICULTY
int "Stratum default difficulty"
range 0 4294967296
Expand Down
1 change: 1 addition & 0 deletions main/global_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "work_queue.h"

#define STRATUM_USER CONFIG_STRATUM_USER
#define FALLBACK_STRATUM_USER CONFIG_FALLBACK_STRATUM_USER

#define HISTORY_LENGTH 100
#define DIFF_STRING_SIZE 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
<input pInputText id="stratumPort" formControlName="stratumPort" type="number" />
</div>
</div>
<div class="field grid p-fluid">
<label htmlFor="stratumUser" class="col-12 mb-2 md:col-2 md:mb-0">Stratum User:</label>
<div class="col-12 md:col-10">
<input pInputText id="stratumUser" formControlName="stratumUser" type="text" />
</div>
</div>
<div class="field grid p-fluid">
<label htmlFor="stratumPassword" class="col-12 mb-2 md:col-2 md:mb-0">Stratum Password:</label>
<div class="col-12 md:col-10">
<input pInputText id="stratumPassword" formControlName="stratumPassword" type="password" />
</div>
</div>
<div class="field grid p-fluid">
<label htmlFor="stratumURL" class="col-12 mb-2 md:col-2 md:mb-0">Fallback Stratum URL:</label>
<div class="col-12 md:col-10">
Expand All @@ -52,20 +64,18 @@
</div>
</div>
<div class="field grid p-fluid">
<label htmlFor="stratumUser" class="col-12 mb-2 md:col-2 md:mb-0">Stratum User:</label>
<label htmlFor="fallbackStratumUser" class="col-12 mb-2 md:col-2 md:mb-0">Fallback Stratum User:</label>
<div class="col-12 md:col-10">
<input pInputText id="stratumUser" formControlName="stratumUser" type="text" />
<input pInputText id="fallbackStratumUser" formControlName="fallbackStratumUser" type="text" />
</div>
</div>
<div class="field grid p-fluid">
<label htmlFor="stratumPassword" class="col-12 mb-2 md:col-2 md:mb-0">Stratum Password:</label>
<label htmlFor="fallbackStratumPassword" class="col-12 mb-2 md:col-2 md:mb-0">Fallback Stratum Password:</label>
<div class="col-12 md:col-10">
<input pInputText id="stratumPassword" formControlName="stratumPassword" type="password" />
<input pInputText id="fallbackStratumPassword" formControlName="fallbackStratumPassword" type="password" />
</div>
</div>



<ng-container *ngIf="!devToolsOpen && ASICModel == eASICModel.BM1366">

<div class="field grid p-fluid">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ export class EditComponent implements OnInit {
]],
stratumUser: [info.stratumUser, [Validators.required]],
stratumPassword: ['*****', [Validators.required]],
stratumPassword: ['password', [Validators.required]],
fallbackStratumUser: [info.fallbackStratumUser, [Validators.required]],
fallbackStratumPassword: ['password', [Validators.required]],
hostname: [info.hostname, [Validators.required]],
ssid: [info.ssid, [Validators.required]],
wifiPass: ['*****'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ <h5>Pool Information</h5>
<td>Port:</td>
<td style="word-break: break-all;">{{info.stratumPort}}</td>
</tr>
<tr>
<td>User:</td>
<td style="word-break: break-all;">{{info.stratumUser}}</td>
</tr>
<tr>
<td>Fallback URL:</td>
<td style="word-break: break-all;">{{info.fallbackStratumURL}}</td>
Expand All @@ -218,8 +222,8 @@ <h5>Pool Information</h5>
<td style="word-break: break-all;">{{info.fallbackStratumPort}}</td>
</tr>
<tr>
<td>User:</td>
<td style="word-break: break-all;">{{info.stratumUser}}</td>
<td>Fallback User:</td>
<td style="word-break: break-all;">{{info.fallbackStratumUser}}</td>
</tr>
</table>
</div>
Expand Down
1 change: 1 addition & 0 deletions main/http_server/axe-os/src/app/services/system.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class SystemService {
fallbackStratumURL: "test.public-pool.io",
fallbackStratumPort: 21497,
stratumUser: "bc1q99n3pu025yyu0jlywpmwzalyhm36tg5u37w20d.bitaxe-U1",
fallbackStratumUser: "bc1q99n3pu025yyu0jlywpmwzalyhm36tg5u37w20d.bitaxe-U1",
frequency: 485,
version: "2.0",
boardVersion: "204",
Expand Down
1 change: 1 addition & 0 deletions main/http_server/axe-os/src/models/ISystemInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ISystemInfo {
fallbackStratumURL: string,
fallbackStratumPort: number,
stratumUser: string,
fallbackStratumUser: string,
frequency: number,
version: string,
boardVersion: string,
Expand Down
8 changes: 8 additions & 0 deletions main/http_server/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ static esp_err_t PATCH_update_settings(httpd_req_t * req)
if ((item = cJSON_GetObjectItem(root, "stratumPassword")) != NULL) {
nvs_config_set_string(NVS_CONFIG_STRATUM_PASS, item->valuestring);
}
if ((item = cJSON_GetObjectItem(root, "fallbackStratumUser")) != NULL) {
nvs_config_set_string(NVS_CONFIG_FALLBACK_STRATUM_USER, item->valuestring);
}
if ((item = cJSON_GetObjectItem(root, "fallbackStratumPassword")) != NULL) {
nvs_config_set_string(NVS_CONFIG_FALLBACK_STRATUM_PASS, item->valuestring);
}
if ((item = cJSON_GetObjectItem(root, "stratumPort")) != NULL) {
nvs_config_set_u16(NVS_CONFIG_STRATUM_PORT, item->valueint);
}
Expand Down Expand Up @@ -376,6 +382,7 @@ static esp_err_t GET_system_info(httpd_req_t * req)
char * stratumURL = nvs_config_get_string(NVS_CONFIG_STRATUM_URL, CONFIG_STRATUM_URL);
char * fallbackStratumURL = nvs_config_get_string(NVS_CONFIG_FALLBACK_STRATUM_URL, CONFIG_FALLBACK_STRATUM_URL);
char * stratumUser = nvs_config_get_string(NVS_CONFIG_STRATUM_USER, CONFIG_STRATUM_USER);
char * fallbackStratumUser = nvs_config_get_string(NVS_CONFIG_FALLBACK_STRATUM_USER, CONFIG_FALLBACK_STRATUM_USER);
char * board_version = nvs_config_get_string(NVS_CONFIG_BOARD_VERSION, "unknown");

cJSON * root = cJSON_CreateObject();
Expand Down Expand Up @@ -425,6 +432,7 @@ static esp_err_t GET_system_info(httpd_req_t * req)
cJSON_AddNumberToObject(root, "stratumPort", nvs_config_get_u16(NVS_CONFIG_STRATUM_PORT, CONFIG_STRATUM_PORT));
cJSON_AddNumberToObject(root, "fallbackStratumPort", nvs_config_get_u16(NVS_CONFIG_FALLBACK_STRATUM_PORT, CONFIG_FALLBACK_STRATUM_PORT));
cJSON_AddStringToObject(root, "stratumUser", stratumUser);
cJSON_AddStringToObject(root, "fallbackStratumUser", fallbackStratumUser);

cJSON_AddStringToObject(root, "version", esp_app_get_description()->version);
cJSON_AddStringToObject(root, "boardVersion", board_version);
Expand Down
2 changes: 2 additions & 0 deletions main/nvs_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#define NVS_CONFIG_FALLBACK_STRATUM_PORT "fbstratumport"
#define NVS_CONFIG_STRATUM_USER "stratumuser"
#define NVS_CONFIG_STRATUM_PASS "stratumpass"
#define NVS_CONFIG_FALLBACK_STRATUM_USER "fbstratumuser"
#define NVS_CONFIG_FALLBACK_STRATUM_PASS "fbstratumpass"
#define NVS_CONFIG_ASIC_FREQ "asicfrequency"
#define NVS_CONFIG_ASIC_VOLTAGE "asicvoltage"
#define NVS_CONFIG_ASIC_MODEL "asicmodel"
Expand Down
5 changes: 3 additions & 2 deletions main/tasks/stratum_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define FALLBACK_STRATUM_URL CONFIG_FALLBACK_STRATUM_URL

#define STRATUM_PW CONFIG_STRATUM_PW
#define FALLBACK_STRATUM_PW CONFIG_FALLBACK_STRATUM_PW
#define STRATUM_DIFFICULTY CONFIG_STRATUM_DIFFICULTY

#define MAX_RETRY_ATTEMPTS 3
Expand Down Expand Up @@ -244,8 +245,8 @@ void stratum_task(void * pvParameters)
//mining.suggest_difficulty - ID: 3
STRATUM_V1_suggest_difficulty(GLOBAL_STATE->sock, STRATUM_DIFFICULTY);

char * username = nvs_config_get_string(NVS_CONFIG_STRATUM_USER, STRATUM_USER);
char * password = nvs_config_get_string(NVS_CONFIG_STRATUM_PASS, STRATUM_PW);
char * username = GLOBAL_STATE->SYSTEM_MODULE.is_using_fallback ? nvs_config_get_string(NVS_CONFIG_FALLBACK_STRATUM_USER, FALLBACK_STRATUM_USER) : nvs_config_get_string(NVS_CONFIG_STRATUM_USER, STRATUM_USER);
char * password = GLOBAL_STATE->SYSTEM_MODULE.is_using_fallback ? nvs_config_get_string(NVS_CONFIG_FALLBACK_STRATUM_PASS, FALLBACK_STRATUM_PW) : nvs_config_get_string(NVS_CONFIG_STRATUM_PASS, STRATUM_PW);

//mining.authorize - ID: 4
STRATUM_V1_authenticate(GLOBAL_STATE->sock, username, password);
Expand Down

0 comments on commit ba66e35

Please sign in to comment.