Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mining-cli"
version = "1.3.3"
version = "1.3.4"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down Expand Up @@ -46,4 +46,3 @@ serde_with = "3.12.0"
tower = "0.5.2"
serde_qs = "0.15.0"
env_logger = "0.11.8"

12 changes: 7 additions & 5 deletions src/cli/accounts_status.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use alloy::{primitives::{B256, U256}, providers::Provider as _};
use alloy::{
primitives::{B256, U256},
providers::Provider as _,
};

use crate::{
external_api::{
contracts::utils::get_address_from_private_key, intmax::circulation::get_circulation
contracts::utils::get_address_from_private_key, intmax::circulation::get_circulation,
},
services::utils::{is_address_used, pretty_format_u256},
state::{key::Key, state::State},
Expand Down Expand Up @@ -39,7 +42,7 @@ pub async fn accounts_status(
let mut total_long_term_claimable_amount = U256::default();
loop {
let key = Key::new(withdrawal_private_key, key_number);
if !is_address_used(&state.provider,key.deposit_address).await? {
if !is_address_used(&state.provider, key.deposit_address).await? {
println!(
"Total short term claimable amount: {} ITX",
pretty_format_u256(total_short_term_claimable_amount)
Expand All @@ -54,7 +57,7 @@ pub async fn accounts_status(
let is_qualified = !get_circulation(key.deposit_address).await?.is_excluded;
let deposit_balance = state.provider.get_balance(key.deposit_address).await?;
println!(
"Deposit address #{}: {:?} {} ETH. Qualified: {}. Deposits: {}/{}. Claimable Short: {} ITX, Claimable Long: {} ITX",
"Deposit address #{}: {:?} {} ETH. Qualified: {}. Deposits: {}/{}. Claimable Short: {} ITX, Claimable Long: {} ITX",
key_number,
key.deposit_address,
pretty_format_u256(deposit_balance),
Expand All @@ -63,7 +66,6 @@ pub async fn accounts_status(
mining_times,
pretty_format_u256(
assets_status.short_term_claimable_amount

),
pretty_format_u256(
assets_status.long_term_claimable_amount
Expand Down
4 changes: 3 additions & 1 deletion src/cli/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ fn address_duplication_check() -> anyhow::Result<()> {
for network in Network::iter() {
for config_index in EnvConfig::get_existing_indices(network) {
let config = EnvConfig::load_from_file(network, config_index)?;
if let std::collections::hash_map::Entry::Vacant(e) = address_to_network.entry(config.withdrawal_address) {
if let std::collections::hash_map::Entry::Vacant(e) =
address_to_network.entry(config.withdrawal_address)
{
e.insert((network, config_index));
} else {
let (duplicated_network, duplicated_index) =
Expand Down
10 changes: 10 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
services::{claim_loop, exit_loop, legacy_claim_loop, mining_loop},
state::{mode::RunMode, state::State},
utils::{
cache::clear_github_cache,
env_config::EnvConfig,
env_validation::validate_env_config,
network::{get_network, is_legacy, Network},
Expand Down Expand Up @@ -127,6 +128,15 @@ async fn mode_loop(
update::update()?;
press_enter_to_continue();
}
RunMode::ClearCache => {
let cache_removed = clear_github_cache()?;
if cache_removed {
println!("GitHub cache directory removed.");
} else {
println!("GitHub cache directory does not exist.");
}
press_enter_to_continue();
}
};
if !is_interactive {
// if not in interactive mode, we only run once
Expand Down
6 changes: 6 additions & 0 deletions src/cli/mode_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ pub fn legacy_select_mode() -> anyhow::Result<RunMode> {
style("Check Update:").bold(),
style("check for updates of this CLI").dim()
),
format!(
"{} {}",
style("Clear Cache:").bold(),
style("remove cached GitHub responses for tree data").dim()
),
];
let term = Term::stdout();
term.clear_screen()?;
Expand All @@ -38,6 +43,7 @@ pub fn legacy_select_mode() -> anyhow::Result<RunMode> {
1 => RunMode::Exit,
2 => RunMode::Export,
3 => RunMode::CheckUpdate,
4 => RunMode::ClearCache,
_ => unreachable!(),
};
Ok(mode)
Expand Down
7 changes: 4 additions & 3 deletions src/external_api/intmax/circulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ pub async fn get_circulation(address: Address) -> Result<CirculationSuccessRespo
})
.await
.map_err(|_| IntmaxError::NetworkError("failed to request circulation server".to_string()))?;
let response_json: CirculationResponse = response.json().await.map_err(|e| {
IntmaxError::SerializeError(format!("failed to parse response: {}", e))
})?;
let response_json: CirculationResponse = response
.json()
.await
.map_err(|e| IntmaxError::SerializeError(format!("failed to parse response: {}", e)))?;
match response_json {
CirculationResponse::Success(success) => Ok(success),
CirculationResponse::Error(error) => Err(IntmaxError::ServerError(error)),
Expand Down
14 changes: 8 additions & 6 deletions src/external_api/intmax/gnark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ pub async fn gnark_start_prove(
})
.await
.map_err(|_| IntmaxError::NetworkError("failed to request gnark server".to_string()))?;
let output: GnarkStartProofResponse = response.json().await.map_err(|e| {
IntmaxError::SerializeError(format!("failed to parse response: {}", e))
})?;
let output: GnarkStartProofResponse = response
.json()
.await
.map_err(|e| IntmaxError::SerializeError(format!("failed to parse response: {}", e)))?;
match output {
GnarkStartProofResponse::Success(success) => Ok(success),
GnarkStartProofResponse::Error(error) => Err(IntmaxError::ServerError(error)),
Expand All @@ -120,9 +121,10 @@ pub async fn gnark_get_proof(
})
.await
.map_err(|_| IntmaxError::NetworkError("failed to request gnark server".to_string()))?;
let output: GnarkGetProofResponse = response.json().await.map_err(|e| {
IntmaxError::SerializeError(format!("failed to parse response: {}", e))
})?;
let output: GnarkGetProofResponse = response
.json()
.await
.map_err(|e| IntmaxError::SerializeError(format!("failed to parse response: {}", e)))?;
match output {
GnarkGetProofResponse::Success(success) => Ok(success),
GnarkGetProofResponse::Error(error) => Err(IntmaxError::ServerError(error)),
Expand Down
10 changes: 2 additions & 8 deletions src/external_api/intmax/withdrawal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ async fn start_withdrawal(
.await
.map_err(|_| IntmaxError::NetworkError("failed to request withdrawal server".to_string()))?;
let response: Value = response.json().await.map_err(|e| {
IntmaxError::SerializeError(format!(
"failed to parse response as json: {}",
e
))
IntmaxError::SerializeError(format!("failed to parse response as json: {}", e))
})?;
let response: SubmitWithdrawalResponse =
serde_json::from_value(response.clone()).map_err(|_| {
Expand Down Expand Up @@ -105,10 +102,7 @@ async fn query_withdrawal(withdrawal_id: &str) -> Result<QueryWithdrawalSuccess,
.await
.map_err(|_| IntmaxError::NetworkError("failed to query withdrawal server".to_string()))?;
let response: Value = response.json().await.map_err(|e| {
IntmaxError::SerializeError(format!(
"failed to parse response as json: {}",
e
))
IntmaxError::SerializeError(format!("failed to parse response as json: {}", e))
})?;
let response: QueryWithdrawalResponse =
serde_json::from_value(response.clone()).map_err(|_| {
Expand Down
2 changes: 2 additions & 0 deletions src/state/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub enum RunMode {
Exit, // only withdraw or cancel pending deposits
Export, // export the deposit addresses
CheckUpdate, // check for updates
ClearCache, // clear cached responses
}

impl Display for RunMode {
Expand All @@ -19,6 +20,7 @@ impl Display for RunMode {
RunMode::Exit => write!(f, "Exit"),
RunMode::Export => write!(f, "Export"),
RunMode::CheckUpdate => write!(f, "CheckUpdate"),
RunMode::ClearCache => write!(f, "ClearCache"),
}
}
}
18 changes: 18 additions & 0 deletions src/utils/cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::fs;

use anyhow::Context as _;

use super::file::get_data_path;

/// Removes the cached GitHub responses stored under `~/.mining-cli/github_cache`.
/// Returns `Ok(true)` when the cache directory existed and was removed.
pub fn clear_github_cache() -> anyhow::Result<bool> {
let cache_dir = get_data_path()?.join("github_cache");
if cache_dir.exists() {
fs::remove_dir_all(&cache_dir)
.with_context(|| format!("failed to remove cache directory: {:?}", cache_dir))?;
Ok(true)
} else {
Ok(false)
}
}
1 change: 1 addition & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod bin_parser;
pub mod cache;
pub mod config;
pub mod deposit_hash_tree;
pub mod derive_key;
Expand Down
Loading