use crate::blocks::rewards::RewardsTransaction; use crate::common::network_paths_and_settings::block_extension_and_paths; use crate::decode; use crate::records::balance_sheet::operations::balance_sheet_operation_with_db; use crate::records::record_chain::rewards_tx::{remove_reward_credit_marker, reward_credit_applied}; use crate::sled::Db; pub async fn undo_rewards_transaction( transaction: RewardsTransaction, mining_receiver: &str, db: &Db, block_height: u32, ) { // remove the miner reward and delete the reward txid // when the block that minted it is rolled back let operand = "subtraction"; let ( _network_name, _padded_base_coin, type_str, _torrentpath, _wallet_path, _blockpath, _db_path, _balance_path, _log_path, ) = block_extension_and_paths(); let value = transaction.unsigned.value; // Rewards are only spendable after finalization, so rollback subtracts // them only when that delayed credit has actually been applied. if reward_credit_applied(db, block_height) { let _ = balance_sheet_operation_with_db(db, mining_receiver, value, &type_str, operand); remove_reward_credit_marker(db, block_height); } let hash = decode(transaction.unsigned.hash().await).unwrap(); // Remove the reward transaction lookup from the txid tree. let tree = db.open_tree("txid").unwrap(); let key = hash; tree.remove(key).unwrap(); }