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

Commit fe37d0c

Browse files
authored
faucet: check if pubkey is registered (#1199)
1 parent bf994b0 commit fe37d0c

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

faucet/src/faucet.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use reef::traits::Validator;
3535
use seahorse::{
3636
events::EventIndex,
3737
txn_builder::{RecordInfo, TransactionReceipt, TransactionStatus},
38-
RecordAmount,
38+
RecordAmount, WalletBackend,
3939
};
4040
use serde::{Deserialize, Serialize};
4141
use snafu::Snafu;
@@ -208,6 +208,9 @@ pub enum FaucetError {
208208

209209
#[snafu(display("faucet service temporarily unavailable"))]
210210
Unavailable,
211+
212+
#[snafu(display("Address not found in address book"))]
213+
AddressNotFound,
211214
}
212215

213216
impl net::Error for FaucetError {
@@ -222,6 +225,7 @@ impl net::Error for FaucetError {
222225
Self::QueueFull { .. } => StatusCode::InternalServerError,
223226
Self::Persistence { .. } => StatusCode::InternalServerError,
224227
Self::Unavailable => StatusCode::ServiceUnavailable,
228+
Self::AddressNotFound { .. } => StatusCode::BadRequest,
225229
}
226230
}
227231
}
@@ -521,6 +525,23 @@ async fn request_fee_assets(
521525
) -> Result<tide::Response, tide::Error> {
522526
check_service_available(req.state()).await?;
523527
let pub_key: UserPubKey = net::server::request_body(&mut req).await?;
528+
529+
// Check that this pub key is registered in the address book. Avoid
530+
// transfers failing later if a public key is not registered in the address
531+
// book, and therefore can't be looked up.
532+
{
533+
req.state()
534+
.wallet
535+
.lock()
536+
.await
537+
.lock()
538+
.await
539+
.backend()
540+
.get_public_key(&pub_key.address())
541+
.await
542+
.map_err(|_| faucet_server_error(FaucetError::AddressNotFound))?;
543+
}
544+
524545
response(
525546
&req,
526547
&req.state()

0 commit comments

Comments
 (0)