Skip to main content

rustledger_plugin/native/plugins/
no_duplicates.rs

1//! Hash-based duplicate transaction detection.
2//!
3//! Thin wrapper around [`rustledger_ops::dedup::find_structural_duplicates`].
4//! The core hashing and dedup logic lives in `rustledger-ops`; this plugin
5//! adapts it to the `NativePlugin` interface.
6//!
7//! Mirrors Python beancount's `beancount.plugins.noduplicates`.
8
9use crate::types::{PluginInput, PluginOutput};
10
11use super::super::NativePlugin;
12
13/// Plugin that detects duplicate transactions based on structural hash.
14pub struct NoDuplicatesPlugin;
15
16impl NativePlugin for NoDuplicatesPlugin {
17    fn name(&self) -> &'static str {
18        "noduplicates"
19    }
20
21    fn description(&self) -> &'static str {
22        "Hash-based duplicate transaction detection"
23    }
24
25    fn process(&self, input: PluginInput) -> PluginOutput {
26        let duplicates = rustledger_ops::dedup::find_structural_duplicates(&input.directives);
27        let errors = duplicates
28            .iter()
29            .map(rustledger_ops::dedup::StructuralDuplicate::to_plugin_error)
30            .collect();
31
32        PluginOutput {
33            directives: input.directives,
34            errors,
35        }
36    }
37}