Better error message on invalid payment req

This commit is contained in:
Bogdan-Ștefan Neacșu
2023-08-24 13:54:06 +03:00
parent 14a9991fa4
commit c0cb98fee0
4 changed files with 11 additions and 4 deletions
+3
View File
@@ -22,6 +22,9 @@ pub enum Error {
#[error("NyxdError - {0}")]
NyxdError(#[from] nym_validator_client::nyxd::error::NyxdError),
#[error("Invalid payment requested")]
InvalidPaymentRequest,
#[error("Bad deposit address")]
BadAddress,
@@ -30,7 +30,8 @@ pub async fn claim_payment(
.storage
.manager
.get_payment(&claim_payment_request_body.serial_number)
.await?;
.await?
.ok_or(Error::InvalidPaymentRequest)?;
let recipient = AccountId::from_str(&claim_payment_request_body.deposit_address)
.map_err(|_| Error::BadAddress)?;
+1 -1
View File
@@ -25,7 +25,7 @@ pub struct State {
}
impl State {
pub(crate) async fn new(storage: Storage, client: Client, config: Config) -> Self {
pub(crate) fn new(storage: Storage, client: Client, config: Config) -> Self {
State {
storage,
client,
@@ -10,7 +10,10 @@ pub(crate) struct StorageManager {
// all SQL goes here
impl StorageManager {
pub(crate) async fn get_payment(&self, serial_number: &str) -> Result<Payment, sqlx::Error> {
pub(crate) async fn get_payment(
&self,
serial_number: &str,
) -> Result<Option<Payment>, sqlx::Error> {
sqlx::query_as!(
Payment,
r#"
@@ -20,7 +23,7 @@ impl StorageManager {
"#,
serial_number
)
.fetch_one(&self.connection_pool)
.fetch_optional(&self.connection_pool)
.await
}