From 6f97ce12b260040b12181f796f90cfe1e385beb3 Mon Sep 17 00:00:00 2001 From: creating2morrow Date: Sun, 7 May 2023 01:06:08 -0400 Subject: [PATCH] update jwp storage for prove payment api --- nevmes-contact/src/controller.rs | 11 ++++++++++- nevmes-contact/src/main.rs | 1 + nevmes-core/src/message.rs | 10 +++++++--- nevmes-core/src/proof.rs | 7 ++++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/nevmes-contact/src/controller.rs b/nevmes-contact/src/controller.rs index e705570..a98afe9 100644 --- a/nevmes-contact/src/controller.rs +++ b/nevmes-contact/src/controller.rs @@ -3,7 +3,7 @@ use rocket::response::status::Custom; use rocket::serde::json::Json; use rocket::{get, post}; -use nevmes_core::{auth, contact, models::*, utils}; +use nevmes_core::{auth, contact, models::*, proof, utils, reqres}; /// Add contact #[post("/", data="")] @@ -31,3 +31,12 @@ pub async fn trust_contact contact::trust_gpg(key); Status::Ok } + +/// prove payment +#[get("/", data="")] +pub async fn prove_payment +(contact: String, proof_req: Json, _token: auth::BearerToken +) -> Custom> { + let r_jwp = proof::prove_payment(contact, &proof_req).await; + Custom(Status::Ok, Json(r_jwp.unwrap())) +} diff --git a/nevmes-contact/src/main.rs b/nevmes-contact/src/main.rs index 23e4ea1..78f1f3b 100644 --- a/nevmes-contact/src/main.rs +++ b/nevmes-contact/src/main.rs @@ -16,6 +16,7 @@ async fn rocket() -> _ { log::info!("nevmes-contact is online"); rocket::custom(&config) .mount("/trust", routes![controller::trust_contact]) + .mount("/prove", routes![controller::prove_payment]) .mount("/contact", routes![controller::add_contact]) .mount("/contacts", routes![controller::get_contacts]) } diff --git a/nevmes-core/src/message.rs b/nevmes-core/src/message.rs index 517532f..067f800 100644 --- a/nevmes-core/src/message.rs +++ b/nevmes-core/src/message.rs @@ -257,11 +257,15 @@ pub async fn retry_fts() { for m in v { let message: Message = find(&m); if message.mid != utils::empty_string() { - // fetch the jwp which just so happens to be cached by the client let s = db::Interface::open(); - let k = format!("{}-{}", "gui-jwp", message.to); + // get jwp from db + let k = format!("{}-{}", "fts-jwp", &message.to); let jwp = db::Interface::read(&s.env, &s.handle, &k); - send_message(&message, &jwp).await.unwrap(); + if jwp != utils::empty_string() { + send_message(&message, &jwp).await.unwrap(); + } else { + error!("not jwp found for fts id: {}", &message.mid); + } } } } diff --git a/nevmes-core/src/proof.rs b/nevmes-core/src/proof.rs index b66e90b..c9a80b3 100644 --- a/nevmes-core/src/proof.rs +++ b/nevmes-core/src/proof.rs @@ -1,4 +1,4 @@ -use crate::{monero, reqres, utils}; +use crate::{db, monero, reqres, utils}; use log::{error, info}; use std::error::Error; use rocket::http::Status; @@ -100,6 +100,11 @@ pub async fn prove_payment(contact: String, txp: &TxProof) -> Result { + // cache the jwp for for fts + let s = db::Interface::open(); + let k = format!("{}-{}", "fts-jwp", &contact); + db::Interface::delete(&s.env, &s.handle, &k); + db::Interface::write(&s.env, &s.handle, &k, &r.jwp); Ok(r) }, _ => Ok(Default::default()),