migrate to 0-conf jwp

This commit is contained in:
creating2morrow 2023-06-10 15:34:04 -04:00
parent f01449c8bf
commit 5398a56568
4 changed files with 16 additions and 30 deletions

View file

@ -78,7 +78,7 @@ pub async fn create_invoice() -> reqres::Invoice {
/// ///
/// necessary to verify the payment. Confirmations cannot /// necessary to verify the payment. Confirmations cannot
/// ///
/// be zero or above some specified threshold. Setting higher /// be above some specified threshold. Setting higher
/// ///
/// payment values and lower confirmations works as a spam /// payment values and lower confirmations works as a spam
/// ///
@ -218,15 +218,7 @@ impl<'r> FromRequest<'r> for PaymentProof {
message: String::from(message), message: String::from(message),
signature: String::from(signature), signature: String::from(signature),
}; };
// TODO(c2m): remove this validation since it was done
// on JWP creation?
let c_txp = validate_proof(&txp).await; let c_txp = validate_proof(&txp).await;
if c_txp.confirmations == 0 {
return Outcome::Failure((
Status::PaymentRequired,
PaymentProofError::Invalid,
));
}
// verify expiration // verify expiration
let expire = utils::get_conf_threshold(); let expire = utils::get_conf_threshold();
// TODO(c2m): offline verification from created and expire fields // TODO(c2m): offline verification from created and expire fields
@ -267,7 +259,6 @@ async fn validate_proof(txp: &TxProof) -> TxProof {
let cth = utils::get_conf_threshold(); let cth = utils::get_conf_threshold();
let pth = utils::get_payment_threshold(); let pth = utils::get_payment_threshold();
let lgtm = p.result.good let lgtm = p.result.good
&& !p.result.in_pool
&& unlock_time < monero::LockTimeLimit::Blocks.value() && unlock_time < monero::LockTimeLimit::Blocks.value()
&& p.result.confirmations < cth && p.result.confirmations < cth
&& p.result.received >= pth; && p.result.received >= pth;

View file

@ -211,7 +211,7 @@ impl eframe::App for AddressBookApp {
.show(&ctx, |ui| { .show(&ctx, |ui| {
if self.is_loading { if self.is_loading {
ui.add(egui::Spinner::new()); ui.add(egui::Spinner::new());
ui.label("sending neveko..."); ui.label("sending message...");
} }
ui.horizontal(|ui| ui.label(format!("to: {}", self.status.i2p))); ui.horizontal(|ui| ui.label(format!("to: {}", self.status.i2p)));
ui.horizontal(|ui| { ui.horizontal(|ui| {
@ -252,7 +252,7 @@ impl eframe::App for AddressBookApp {
.show(&ctx, |ui| { .show(&ctx, |ui| {
if self.is_loading { if self.is_loading {
ui.add(egui::Spinner::new()); ui.add(egui::Spinner::new());
ui.label("creating jwp may take a few minutes..."); ui.label("creating jwp. please wait...");
} }
if self.is_estimating_fee { if self.is_estimating_fee {
ui.add(egui::Spinner::new()); ui.add(egui::Spinner::new());
@ -636,7 +636,6 @@ fn send_payment_req(
utils::clear_gui_db(String::from("gui-txp"), String::from(&contact)); utils::clear_gui_db(String::from("gui-txp"), String::from(&contact));
utils::clear_gui_db(String::from("gui-jwp"), String::from(&contact)); utils::clear_gui_db(String::from("gui-jwp"), String::from(&contact));
utils::clear_gui_db(String::from("gui-exp"), String::from(&contact)); utils::clear_gui_db(String::from("gui-exp"), String::from(&contact));
let mut retry_count = 1;
tokio::spawn(async move { tokio::spawn(async move {
let ptxp_address = String::from(&d.address); let ptxp_address = String::from(&d.address);
let ftxp_address = String::from(&d.address); let ftxp_address = String::from(&d.address);
@ -669,21 +668,6 @@ fn send_payment_req(
message: utils::empty_string(), message: utils::empty_string(),
signature: get_txp.result.signature, signature: get_txp.result.signature,
}; };
// we will poll for 6 minutes MAX because jwp cannot be created without at least ONE conf
loop {
if retry_count > 3 {
break;
}
let check_txp: reqres::XmrRpcCheckTxProofResponse = monero::check_tx_proof(&ftxp).await;
if check_txp.result.good && check_txp.result.confirmations > 0 {
break;
}
tokio::time::sleep(std::time::Duration::from_secs(
BLOCK_TIME_IN_SECS_EST as u64,
))
.await;
retry_count += 1;
}
utils::write_gui_db( utils::write_gui_db(
String::from("gui-txp"), String::from("gui-txp"),
String::from(&contact), String::from(&contact),
@ -696,6 +680,11 @@ fn send_payment_req(
); );
monero::close_wallet(&wallet_name, &wallet_password).await; monero::close_wallet(&wallet_name, &wallet_password).await;
// if we made it this far we can now request a JWP from our friend // if we made it this far we can now request a JWP from our friend
// wait a bit for the tx to propogate
tokio::time::sleep(std::time::Duration::from_secs(
crate::BLOCK_TIME_IN_SECS_EST,
))
.await;
match proof::prove_payment(String::from(&contact), &ftxp).await { match proof::prove_payment(String::from(&contact), &ftxp).await {
Ok(result) => { Ok(result) => {
utils::write_gui_db( utils::write_gui_db(

View file

@ -60,7 +60,10 @@ impl eframe::App for LockScreenApp {
ui.add(egui::TextEdit::singleline(&mut self.lock_screen.credential).password(true)); ui.add(egui::TextEdit::singleline(&mut self.lock_screen.credential).password(true));
}); });
if ui.button("Login").clicked() { if ui.button("Login").clicked() {
std::env::set_var(neveko_core::MONERO_WALLET_PASSWORD, self.lock_screen.credential.clone()); std::env::set_var(
neveko_core::MONERO_WALLET_PASSWORD,
self.lock_screen.credential.clone(),
);
// Get the credential hash from lmdb // Get the credential hash from lmdb
let s = db::Interface::open(); let s = db::Interface::open();
let r = db::Interface::read(&s.env, &s.handle, CREDENTIAL_KEY); let r = db::Interface::read(&s.env, &s.handle, CREDENTIAL_KEY);

View file

@ -38,7 +38,10 @@ impl eframe::App for LoginApp {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label("credential: \t"); ui.label("credential: \t");
let mut show_password = self.is_not_showing_password; let mut show_password = self.is_not_showing_password;
ui.add(egui::TextEdit::singleline(&mut self.credential).password(self.is_not_showing_password)); ui.add(
egui::TextEdit::singleline(&mut self.credential)
.password(self.is_not_showing_password),
);
if ui.checkbox(&mut show_password, "show password").changed() { if ui.checkbox(&mut show_password, "show password").changed() {
self.is_not_showing_password = !self.is_not_showing_password; self.is_not_showing_password = !self.is_not_showing_password;
} }