mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-10 23:27:56 -05:00
drk/txs_history: better handling of records
This commit is contained in:
@@ -392,6 +392,9 @@ pub fn generate_completions(shell: &str) -> Result<()> {
|
||||
.about("Fetch broadcasted transactions history")
|
||||
.args(&vec![tx_hash, encode]);
|
||||
|
||||
let clear_reverted =
|
||||
SubCommand::with_name("clear-reverted").about("Remove reverted transactions from history");
|
||||
|
||||
let height = Arg::with_name("height").help("Fetch specific height record (optional)");
|
||||
|
||||
let scanned_blocks = SubCommand::with_name("scanned-blocks")
|
||||
@@ -400,7 +403,7 @@ pub fn generate_completions(shell: &str) -> Result<()> {
|
||||
|
||||
let explorer = SubCommand::with_name("explorer")
|
||||
.about("Explorer related subcommands")
|
||||
.subcommands(vec![fetch_tx, simulate_tx, txs_history, scanned_blocks]);
|
||||
.subcommands(vec![fetch_tx, simulate_tx, txs_history, clear_reverted, scanned_blocks]);
|
||||
|
||||
// Alias
|
||||
let alias = Arg::with_name("alias").help("Token alias");
|
||||
|
||||
@@ -411,6 +411,9 @@ enum ExplorerSubcmd {
|
||||
encode: bool,
|
||||
},
|
||||
|
||||
/// Remove reverted transactions from history
|
||||
ClearReverted,
|
||||
|
||||
/// Fetch scanned blocks records
|
||||
ScannedBlocks {
|
||||
/// Fetch specific height record (optional)
|
||||
@@ -1967,6 +1970,24 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
ExplorerSubcmd::ClearReverted => {
|
||||
let drk = new_wallet(
|
||||
blockchain_config.wallet_path,
|
||||
blockchain_config.wallet_pass,
|
||||
None,
|
||||
ex,
|
||||
args.fun,
|
||||
)
|
||||
.await;
|
||||
|
||||
if let Err(e) = drk.remove_reverted_txs() {
|
||||
eprintln!("Failed to remove reverted transactions: {e:?}");
|
||||
exit(2);
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
ExplorerSubcmd::ScannedBlocks { height } => {
|
||||
let drk = new_wallet(
|
||||
blockchain_config.wallet_path,
|
||||
|
||||
@@ -53,7 +53,7 @@ impl Drk {
|
||||
|
||||
// Create its inverse query
|
||||
let tx_hash = tx.hash().to_string();
|
||||
// We only need to reverse the transaction status to "Broadcasted"
|
||||
// We only need to set the transaction status to "Reverted"
|
||||
let inverse = self.wallet.create_prepared_statement(
|
||||
&format!(
|
||||
"UPDATE {} SET {} = ?1 WHERE {} = ?2;",
|
||||
@@ -61,7 +61,7 @@ impl Drk {
|
||||
WALLET_TXS_HISTORY_COL_STATUS,
|
||||
WALLET_TXS_HISTORY_COL_TX_HASH
|
||||
),
|
||||
rusqlite::params!["Broadcasted", tx_hash],
|
||||
rusqlite::params!["Reverted", tx_hash],
|
||||
)?;
|
||||
|
||||
// Execute the query
|
||||
@@ -159,4 +159,18 @@ impl Drk {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove the transaction history records in the wallet
|
||||
/// that have been reverted.
|
||||
pub fn remove_reverted_txs(&self) -> WalletDbResult<()> {
|
||||
println!("Removing reverted transactions history records");
|
||||
let query = format!(
|
||||
"DELETE FROM {} WHERE {} = 'Reverted';",
|
||||
WALLET_TXS_HISTORY_TABLE, WALLET_TXS_HISTORY_COL_STATUS
|
||||
);
|
||||
self.wallet.exec_sql(&query, &[])?;
|
||||
println!("Successfully removed reverted transactions history records");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user