From 626c0d56f1fb93dcc3659fc21560ac39d8b63439 Mon Sep 17 00:00:00 2001 From: creating2morrow Date: Sun, 11 Jun 2023 18:27:53 -0400 Subject: [PATCH] update payment proof validations --- neveko-core/src/monero.rs | 27 ++++++++++++++++++++++++++- neveko-core/src/proof.rs | 8 +++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/neveko-core/src/monero.rs b/neveko-core/src/monero.rs index 12f2658..642a1f6 100644 --- a/neveko-core/src/monero.rs +++ b/neveko-core/src/monero.rs @@ -17,6 +17,8 @@ use std::process::Command; use lazy_static::lazy_static; use std::sync::Mutex; +pub const INVALID_VERSION: u32 = 0; + // global variable lazy_static! { /// used to avoid multisig wallet collision @@ -31,6 +33,29 @@ struct RpcLogin { credential: String, } +pub enum TransactionType { + Failed, + In, + Out, + Pending, + Pool, +} + +impl TransactionType { + pub fn value(&self) -> String { + match *self { + Self::Failed => String::from("failed"), + Self::In => String::from("In"), + Self::Out => String::from("Out"), + Self::Pending => String::from("Pending"), + Self::Pool => String::from("Pool"), + } + } + pub fn propogated(tx_type: String) -> bool { + tx_type == Self::In.value() || tx_type == Self::Pool.value() + } +} + enum RpcFields { Address, Balance, @@ -306,7 +331,7 @@ pub async fn get_version() -> reqres::XmrRpcVersionResponse { /// Helper function for checking xmr rpc online during app startup pub async fn check_rpc_connection() -> () { let res: reqres::XmrRpcVersionResponse = get_version().await; - if res.result.version == 0 { + if res.result.version == INVALID_VERSION { error!("failed to connect to monero-wallet-rpc"); } } diff --git a/neveko-core/src/proof.rs b/neveko-core/src/proof.rs index 031b9f6..a143c3c 100644 --- a/neveko-core/src/proof.rs +++ b/neveko-core/src/proof.rs @@ -87,7 +87,8 @@ pub async fn create_jwp(proof: &TxProof) -> String { info!("creating jwp"); // validate the proof let c_txp: TxProof = validate_proof(proof).await; - if c_txp.confirmations == 0 { + if c_txp.hash == utils::empty_string() { + error!("invalid transaction proof"); return utils::empty_string(); } let jwp_secret_key = utils::get_jwp_secret_key(); @@ -255,6 +256,11 @@ async fn validate_proof(txp: &TxProof) -> TxProof { // verify unlock time isn't something funky (e.g. > 20) let tx: reqres::XmrRpcGetTxByIdResponse = monero::get_transfer_by_txid(&txp.hash).await; let unlock_time = tx.result.transfer.unlock_time; + let tx_type = tx.result.transfer.r#type; + let propgated = monero::TransactionType::propogated(tx_type); + if !propgated { + return Default::default(); + } let p = monero::check_tx_proof(txp).await; let cth = utils::get_conf_threshold(); let pth = utils::get_payment_threshold();