Skip to content

Commit 2f172ed

Browse files
committed
fix
1 parent bd48588 commit 2f172ed

2 files changed

Lines changed: 30 additions & 12 deletions

File tree

src/config.rs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use clap::Parser;
22
use lazy_static::lazy_static;
33
use serde::{Deserialize, Serialize};
4+
use serde_json::json;
45
use std::{
56
net::{SocketAddr, ToSocketAddrs},
67
path::PathBuf,
78
};
89
use tracing::{debug, error, info, warn};
910

10-
use crate::{HashUnit, DEFAULT_SV1_HASHPOWER, PRODUCTION_URL, STAGING_URL};
11+
use crate::{shared::error::Error, HashUnit, DEFAULT_SV1_HASHPOWER, PRODUCTION_URL, STAGING_URL};
1112
lazy_static! {
1213
pub static ref CONFIG: Configuration = Configuration::load_config();
1314
}
@@ -110,7 +111,13 @@ impl Configuration {
110111
}
111112

112113
pub async fn pool_address() -> Option<Vec<SocketAddr>> {
113-
fetch_pool_urls().await
114+
match fetch_pool_urls().await {
115+
Ok(addresses) => Some(addresses),
116+
Err(e) => {
117+
error!("Failed to fetch pool addresses: {}", e);
118+
None
119+
}
120+
}
114121
}
115122

116123
pub fn adjustment_interval() -> u64 {
@@ -353,32 +360,43 @@ fn parse_address(addr: String) -> SocketAddr {
353360
}
354361

355362
/// Fetches pool URLs from the server based on the environment.
356-
async fn fetch_pool_urls() -> Option<Vec<SocketAddr>> {
363+
async fn fetch_pool_urls() -> Result<Vec<SocketAddr>, Error> {
357364
if CONFIG.local {
358-
return Some(vec![parse_address("127.0.0.1:20000".to_string())]);
365+
return Ok(vec![parse_address("127.0.0.1:20000".to_string())]);
359366
};
360367

361368
let url = if CONFIG.staging {
369+
info!("Fetching pool URLs from staging server: {}", STAGING_URL);
362370
STAGING_URL
363371
} else {
372+
info!(
373+
"Fetching pool URLs from production server: {}",
374+
PRODUCTION_URL
375+
);
364376
PRODUCTION_URL
365377
};
366-
let endpoint = format!("{}/pool/urls", url);
367-
debug!("Fetching pool URLs from: {}", endpoint);
368-
369-
let response = match reqwest::get(endpoint).await {
378+
let endpoint = format!("{}/api/pool/urls", url);
379+
let token = Configuration::token().expect("TOKEN is not set");
380+
381+
let response = match reqwest::Client::new()
382+
.post(endpoint)
383+
.json(&json!({"token": token}))
384+
.send()
385+
.await
386+
{
370387
Ok(resp) => resp,
371388
Err(e) => {
372389
error!("Failed to fetch pool urls: {}", e);
373-
return None;
390+
return Err(Error::from(e));
374391
}
375392
};
376393

394+
debug!("Response status: {}", response.status());
377395
let addresses: Vec<PoolAddress> = match response.json().await {
378396
Ok(addrs) => addrs,
379397
Err(e) => {
380398
error!("Failed to parse pool urls: {}", e);
381-
return None;
399+
return Err(Error::from(e));
382400
}
383401
};
384402

@@ -391,7 +409,7 @@ async fn fetch_pool_urls() -> Option<Vec<SocketAddr>> {
391409
})
392410
.collect();
393411
debug!("Pool addresses: {:?}", socket_addrs);
394-
Some(socket_addrs)
412+
Ok(socket_addrs)
395413
}
396414

397415
#[derive(Debug, Deserialize)]

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const REPO_NAME: &str = "demand-cli";
4444
const BIN_NAME: &str = "demand-cli";
4545
const STAGING_URL: &str = "https://staging-user-dashboard-server.dmnd.work";
4646
const LOCAL_URL: &str = "http://localhost:8787/api";
47-
const PRODUCTION_URL: &str = "https://user-dashboard-server.dmnd.work";
47+
const PRODUCTION_URL: &str = "https://production-user-dashboard-server.dmnd.work";
4848

4949
lazy_static! {
5050
static ref SV1_DOWN_LISTEN_ADDR: String =

0 commit comments

Comments
 (0)