From 46c765b4afaf670d5a4fa7ca5f68f89b6c879492 Mon Sep 17 00:00:00 2001 From: bitcoinafterlife Date: Sun, 30 Mar 2025 12:51:12 -0400 Subject: [PATCH] added push error to database --- src/main.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 082e392..eb3de99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ use log::{info,debug,warn,error}; use zmq::{Context, Socket}; use std::str; use std::{thread, time::Duration}; +use std::collections::HashMap; //use byteorder::{LittleEndian, ReadBytesExt}; //use std::io::Cursor; use hex; @@ -205,7 +206,7 @@ fn main_result(cfg: &MyConfig, network_params: &NetworkParams) -> Result<(), Err let query_tx = db.prepare("SELECT * FROM tbl_tx WHERE network = :network AND status = :status AND ( locktime < :bestblock_height OR locktime > :locktime_threshold AND locktime < :bestblock_time);").unwrap().into_iter(); //let query_tx = db.prepare("SELECT * FROM tbl_tx where status = :status").unwrap().into_iter(); let mut pushed_txs:Vec = Vec::new(); - let mut invalid_txs:Vec = Vec::new(); + let mut invalid_txs: std::collections::HashMap = HashMap::new(); for row in query_tx.bind::<&[(_, Value)]>(&[ (":locktime_threshold", (LOCKTIME_THRESHOLD as i64).into()), (":bestblock_time", (average_time as i64).into()), @@ -242,7 +243,9 @@ fn main_result(cfg: &MyConfig, network_params: &NetworkParams) -> Result<(), Err file.write_all(data.as_bytes())?; drop(file); warn!("Error: {}\n{}",err,txid); - invalid_txs.push(txid.to_string()); + //store err in invalid_txs + invalid_txs.insert(txid.to_string(), err.to_string()); + }, }; } @@ -251,7 +254,10 @@ fn main_result(cfg: &MyConfig, network_params: &NetworkParams) -> Result<(), Err let _ = db.execute(format!("UPDATE tbl_tx SET status = 1 WHERE txid in ('{}');",pushed_txs.join("','"))); } if invalid_txs.len() > 0 { - let _ = db.execute(format!("UPDATE tbl_tx SET status = 2 WHERE txid in ('{}');",invalid_txs.join("','"))); + for (txid,txerr) in &invalid_txs{ + //let _ = db.execute(format!("UPDATE tbl_tx SET status = 2 WHERE txid in ('{}'Yp);",invalid_txs.join("','"))); + let _ = db.execute(format!("UPDATE tbl_tx SET status = 2, error='{txerr}' WHERE txid = '{txid}'")); + } } } Err(_)=>{ @@ -413,4 +419,3 @@ fn main(){ thread::sleep(Duration::from_millis(100)); // Sleep for 100ms } } -