Skip to content

Commit

Permalink
chore: addres review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Apr 29, 2024
1 parent 08dc06c commit 1cc37d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
5 changes: 4 additions & 1 deletion sn_cli/src/bin/subcommands/wallet/hot_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ use std::{path::Path, str::FromStr};
pub enum WalletCmds {
/// Print the wallet address.
Address {
/// Optional phrase to use for the wallet deriviation from mnemonic entropy.
/// Optional passphrase to protect the mnemonic,
/// it's not the source of the entropy for the mnemonic generation.
/// The mnemonic+passphrase will be the seed. See detail at
/// `<https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki#from-mnemonic-to-seed>`
passphrase: Option<String>,
},
/// Print the wallet balance.
Expand Down
23 changes: 11 additions & 12 deletions sn_faucet/src/faucet_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,20 @@ async fn respond_to_donate_request(
transfer_str: String,
semaphore: Arc<Semaphore>,
) -> std::result::Result<impl Reply, std::convert::Infallible> {
let faucet_root = get_faucet_data_dir();

let permit = semaphore.try_acquire();
info!("Got donate request with: {transfer_str}");

// some rate limiting
if is_wallet_locked() || permit.is_err() {
warn!("Rate limited request due");
let mut response = Response::new("Rate limited".to_string());
*response.status_mut() = StatusCode::TOO_MANY_REQUESTS;

// Either opening the file or locking it failed, indicating rate limiting should occur
return Ok(response);
}

let faucet_root = get_faucet_data_dir();
let mut wallet = match load_account_wallet_or_create_with_mnemonic(&faucet_root, None) {
Ok(wallet) => wallet,
Err(_error) => {
Expand All @@ -146,16 +155,6 @@ async fn respond_to_donate_request(
}
};

// some rate limiting
if is_wallet_locked() || permit.is_err() {
warn!("Rate limited request due");
let mut response = Response::new("Rate limited".to_string());
*response.status_mut() = StatusCode::TOO_MANY_REQUESTS;

// Either opening the file or locking it failed, indicating rate limiting should occur
return Ok(response);
}

if let Err(err) = fund_faucet_from_genesis_wallet(&client, &mut wallet).await {
eprintln!("Failed to load + fund faucet wallet: {err}");
error!("Failed to load + fund faucet wallet: {err}");
Expand Down
1 change: 0 additions & 1 deletion sn_transfers/src/wallet/hot_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ impl HotWallet {

/// reloads the wallet from disk.
fn reload(&mut self) -> Result<()> {
// placeholder random MainSecretKey to take it out
let wallet = Self::load_from_path_and_key(self.watchonly_wallet.wallet_dir(), None)?;

if *wallet.key.secret_key() != *self.key.secret_key() {
Expand Down

0 comments on commit 1cc37d4

Please sign in to comment.