@@ -35,7 +35,7 @@ use reef::traits::Validator;
35
35
use seahorse:: {
36
36
events:: EventIndex ,
37
37
txn_builder:: { RecordInfo , TransactionReceipt , TransactionStatus } ,
38
- RecordAmount ,
38
+ RecordAmount , WalletBackend ,
39
39
} ;
40
40
use serde:: { Deserialize , Serialize } ;
41
41
use snafu:: Snafu ;
@@ -208,6 +208,9 @@ pub enum FaucetError {
208
208
209
209
#[ snafu( display( "faucet service temporarily unavailable" ) ) ]
210
210
Unavailable ,
211
+
212
+ #[ snafu( display( "Address not found in address book" ) ) ]
213
+ AddressNotFound ,
211
214
}
212
215
213
216
impl net:: Error for FaucetError {
@@ -222,6 +225,7 @@ impl net::Error for FaucetError {
222
225
Self :: QueueFull { .. } => StatusCode :: InternalServerError ,
223
226
Self :: Persistence { .. } => StatusCode :: InternalServerError ,
224
227
Self :: Unavailable => StatusCode :: ServiceUnavailable ,
228
+ Self :: AddressNotFound { .. } => StatusCode :: BadRequest ,
225
229
}
226
230
}
227
231
}
@@ -521,6 +525,23 @@ async fn request_fee_assets(
521
525
) -> Result < tide:: Response , tide:: Error > {
522
526
check_service_available ( req. state ( ) ) . await ?;
523
527
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
+
524
545
response (
525
546
& req,
526
547
& req. state ( )
0 commit comments