mirror of
https://github.com/creating2morrow/neveko.git
synced 2025-03-23 23:58:55 +00:00
update jwp storage for prove payment api
This commit is contained in:
parent
27993e5a64
commit
6f97ce12b2
4 changed files with 24 additions and 5 deletions
|
@ -3,7 +3,7 @@ use rocket::response::status::Custom;
|
||||||
use rocket::serde::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use rocket::{get, post};
|
use rocket::{get, post};
|
||||||
|
|
||||||
use nevmes_core::{auth, contact, models::*, utils};
|
use nevmes_core::{auth, contact, models::*, proof, utils, reqres};
|
||||||
|
|
||||||
/// Add contact
|
/// Add contact
|
||||||
#[post("/", data="<req_contact>")]
|
#[post("/", data="<req_contact>")]
|
||||||
|
@ -31,3 +31,12 @@ pub async fn trust_contact
|
||||||
contact::trust_gpg(key);
|
contact::trust_gpg(key);
|
||||||
Status::Ok
|
Status::Ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// prove payment
|
||||||
|
#[get("/<contact>", data="<proof_req>")]
|
||||||
|
pub async fn prove_payment
|
||||||
|
(contact: String, proof_req: Json<proof::TxProof>, _token: auth::BearerToken
|
||||||
|
) -> Custom<Json<reqres::Jwp>> {
|
||||||
|
let r_jwp = proof::prove_payment(contact, &proof_req).await;
|
||||||
|
Custom(Status::Ok, Json(r_jwp.unwrap()))
|
||||||
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ async fn rocket() -> _ {
|
||||||
log::info!("nevmes-contact is online");
|
log::info!("nevmes-contact is online");
|
||||||
rocket::custom(&config)
|
rocket::custom(&config)
|
||||||
.mount("/trust", routes![controller::trust_contact])
|
.mount("/trust", routes![controller::trust_contact])
|
||||||
|
.mount("/prove", routes![controller::prove_payment])
|
||||||
.mount("/contact", routes![controller::add_contact])
|
.mount("/contact", routes![controller::add_contact])
|
||||||
.mount("/contacts", routes![controller::get_contacts])
|
.mount("/contacts", routes![controller::get_contacts])
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,11 +257,15 @@ pub async fn retry_fts() {
|
||||||
for m in v {
|
for m in v {
|
||||||
let message: Message = find(&m);
|
let message: Message = find(&m);
|
||||||
if message.mid != utils::empty_string() {
|
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 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);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{monero, reqres, utils};
|
use crate::{db, monero, reqres, utils};
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use rocket::http::Status;
|
use rocket::http::Status;
|
||||||
|
@ -100,6 +100,11 @@ pub async fn prove_payment(contact: String, txp: &TxProof) -> Result<reqres::Jwp
|
||||||
log::debug!("prove payment response: {:?}", res);
|
log::debug!("prove payment response: {:?}", res);
|
||||||
match res {
|
match res {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
|
// 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(r)
|
||||||
},
|
},
|
||||||
_ => Ok(Default::default()),
|
_ => Ok(Default::default()),
|
||||||
|
|
Loading…
Reference in a new issue