From 5398a56568b2265cd6754aad6404d112ca8f9e6b Mon Sep 17 00:00:00 2001 From: creating2morrow Date: Sat, 10 Jun 2023 15:34:04 -0400 Subject: [PATCH] migrate to 0-conf jwp --- neveko-core/src/proof.rs | 11 +---------- neveko-gui/src/apps/address_book.rs | 25 +++++++------------------ neveko-gui/src/apps/lock_screen.rs | 5 ++++- neveko-gui/src/login.rs | 5 ++++- 4 files changed, 16 insertions(+), 30 deletions(-) diff --git a/neveko-core/src/proof.rs b/neveko-core/src/proof.rs index 29e21bd..031b9f6 100644 --- a/neveko-core/src/proof.rs +++ b/neveko-core/src/proof.rs @@ -78,7 +78,7 @@ pub async fn create_invoice() -> reqres::Invoice { /// /// 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 /// @@ -218,15 +218,7 @@ impl<'r> FromRequest<'r> for PaymentProof { message: String::from(message), signature: String::from(signature), }; - // TODO(c2m): remove this validation since it was done - // on JWP creation? let c_txp = validate_proof(&txp).await; - if c_txp.confirmations == 0 { - return Outcome::Failure(( - Status::PaymentRequired, - PaymentProofError::Invalid, - )); - } // verify expiration let expire = utils::get_conf_threshold(); // 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 pth = utils::get_payment_threshold(); let lgtm = p.result.good - && !p.result.in_pool && unlock_time < monero::LockTimeLimit::Blocks.value() && p.result.confirmations < cth && p.result.received >= pth; diff --git a/neveko-gui/src/apps/address_book.rs b/neveko-gui/src/apps/address_book.rs index ccfe71d..b43bc2b 100644 --- a/neveko-gui/src/apps/address_book.rs +++ b/neveko-gui/src/apps/address_book.rs @@ -211,7 +211,7 @@ impl eframe::App for AddressBookApp { .show(&ctx, |ui| { if self.is_loading { 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| { @@ -252,7 +252,7 @@ impl eframe::App for AddressBookApp { .show(&ctx, |ui| { if self.is_loading { 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 { 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-jwp"), String::from(&contact)); utils::clear_gui_db(String::from("gui-exp"), String::from(&contact)); - let mut retry_count = 1; tokio::spawn(async move { let ptxp_address = String::from(&d.address); let ftxp_address = String::from(&d.address); @@ -669,21 +668,6 @@ fn send_payment_req( message: utils::empty_string(), 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( String::from("gui-txp"), String::from(&contact), @@ -696,6 +680,11 @@ fn send_payment_req( ); monero::close_wallet(&wallet_name, &wallet_password).await; // 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 { Ok(result) => { utils::write_gui_db( diff --git a/neveko-gui/src/apps/lock_screen.rs b/neveko-gui/src/apps/lock_screen.rs index 5f1cd4d..84c0623 100644 --- a/neveko-gui/src/apps/lock_screen.rs +++ b/neveko-gui/src/apps/lock_screen.rs @@ -60,7 +60,10 @@ impl eframe::App for LockScreenApp { ui.add(egui::TextEdit::singleline(&mut self.lock_screen.credential).password(true)); }); 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 let s = db::Interface::open(); let r = db::Interface::read(&s.env, &s.handle, CREDENTIAL_KEY); diff --git a/neveko-gui/src/login.rs b/neveko-gui/src/login.rs index 2deb755..d3660f8 100644 --- a/neveko-gui/src/login.rs +++ b/neveko-gui/src/login.rs @@ -38,7 +38,10 @@ impl eframe::App for LoginApp { ui.horizontal(|ui| { ui.label("credential: \t"); 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() { self.is_not_showing_password = !self.is_not_showing_password; }