Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
faucet: check if pubkey is registered (#1199)
Browse files Browse the repository at this point in the history
  • Loading branch information
sveitser authored Jul 16, 2022
1 parent bf994b0 commit fe37d0c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion faucet/src/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use reef::traits::Validator;
use seahorse::{
events::EventIndex,
txn_builder::{RecordInfo, TransactionReceipt, TransactionStatus},
RecordAmount,
RecordAmount, WalletBackend,
};
use serde::{Deserialize, Serialize};
use snafu::Snafu;
Expand Down Expand Up @@ -208,6 +208,9 @@ pub enum FaucetError {

#[snafu(display("faucet service temporarily unavailable"))]
Unavailable,

#[snafu(display("Address not found in address book"))]
AddressNotFound,
}

impl net::Error for FaucetError {
Expand All @@ -222,6 +225,7 @@ impl net::Error for FaucetError {
Self::QueueFull { .. } => StatusCode::InternalServerError,
Self::Persistence { .. } => StatusCode::InternalServerError,
Self::Unavailable => StatusCode::ServiceUnavailable,
Self::AddressNotFound { .. } => StatusCode::BadRequest,
}
}
}
Expand Down Expand Up @@ -521,6 +525,23 @@ async fn request_fee_assets(
) -> Result<tide::Response, tide::Error> {
check_service_available(req.state()).await?;
let pub_key: UserPubKey = net::server::request_body(&mut req).await?;

// Check that this pub key is registered in the address book. Avoid
// transfers failing later if a public key is not registered in the address
// book, and therefore can't be looked up.
{
req.state()
.wallet
.lock()
.await
.lock()
.await
.backend()
.get_public_key(&pub_key.address())
.await
.map_err(|_| faucet_server_error(FaucetError::AddressNotFound))?;
}

response(
&req,
&req.state()
Expand Down

0 comments on commit fe37d0c

Please sign in to comment.