update payment proof validations

This commit is contained in:
creating2morrow 2023-06-11 18:27:53 -04:00
parent bbc817d263
commit 626c0d56f1
2 changed files with 33 additions and 2 deletions

View file

@ -17,6 +17,8 @@ use std::process::Command;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use std::sync::Mutex; use std::sync::Mutex;
pub const INVALID_VERSION: u32 = 0;
// global variable // global variable
lazy_static! { lazy_static! {
/// used to avoid multisig wallet collision /// used to avoid multisig wallet collision
@ -31,6 +33,29 @@ struct RpcLogin {
credential: String, 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 { enum RpcFields {
Address, Address,
Balance, Balance,
@ -306,7 +331,7 @@ pub async fn get_version() -> reqres::XmrRpcVersionResponse {
/// Helper function for checking xmr rpc online during app startup /// Helper function for checking xmr rpc online during app startup
pub async fn check_rpc_connection() -> () { pub async fn check_rpc_connection() -> () {
let res: reqres::XmrRpcVersionResponse = get_version().await; 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"); error!("failed to connect to monero-wallet-rpc");
} }
} }

View file

@ -87,7 +87,8 @@ pub async fn create_jwp(proof: &TxProof) -> String {
info!("creating jwp"); info!("creating jwp");
// validate the proof // validate the proof
let c_txp: TxProof = validate_proof(proof).await; 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(); return utils::empty_string();
} }
let jwp_secret_key = utils::get_jwp_secret_key(); 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) // verify unlock time isn't something funky (e.g. > 20)
let tx: reqres::XmrRpcGetTxByIdResponse = monero::get_transfer_by_txid(&txp.hash).await; let tx: reqres::XmrRpcGetTxByIdResponse = monero::get_transfer_by_txid(&txp.hash).await;
let unlock_time = tx.result.transfer.unlock_time; 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 p = monero::check_tx_proof(txp).await;
let cth = utils::get_conf_threshold(); let cth = utils::get_conf_threshold();
let pth = utils::get_payment_threshold(); let pth = utils::get_payment_threshold();