From eb45dec556c937a3f5d48d4c373e1c82d3f8ee6e Mon Sep 17 00:00:00 2001
From: Benoit Lavenier <benoit.lavenier@e-is.pro>
Date: Wed, 17 May 2023 16:40:02 +0200
Subject: [PATCH] enh] add `get_written_transactions_for_bma()` and
 `get_pending_transactions_for_bma()` in DuniterModule trait - close #2

---
 module/src/lib.rs | 62 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 58 insertions(+), 4 deletions(-)

diff --git a/module/src/lib.rs b/module/src/lib.rs
index 7ef782f..b0bf725 100644
--- a/module/src/lib.rs
+++ b/module/src/lib.rs
@@ -85,7 +85,7 @@ pub trait DuniterModule: 'static + Sized {
 
     async fn start(self) -> anyhow::Result<()>;
 
-    // Needed for BMA only, will be removed when the migration is complete.
+    // Needed for BMA only
     #[doc(hidden)]
     fn get_transactions_history_for_bma(
         _dbs_pool: &fast_threadpool::ThreadPoolSyncHandler<SharedDbs<FileBackend>>,
@@ -94,7 +94,28 @@ pub trait DuniterModule: 'static + Sized {
     ) -> KvResult<Option<TxsHistoryForBma>> {
         Ok(None)
     }
-    // Needed for BMA only, will be removed when the migration is complete.
+
+    // Needed for BMA only
+    #[doc(hidden)]
+    fn get_written_transactions_for_bma(
+        _profile_path_opt: Option<&Path>,
+        _pubkey: PublicKey,
+        _start_block: u32,
+        _end_block: u32,
+    ) -> KvResult<Option<TxsHistoryForBma>> {
+        Ok(None)
+    }
+
+    // Needed for BMA only
+    #[doc(hidden)]
+    fn get_pending_transactions_for_bma(
+        _dbs_pool: &fast_threadpool::ThreadPoolSyncHandler<SharedDbs<FileBackend>>,
+        _pubkey: PublicKey,
+    ) -> KvResult<Option<TxsHistoryForBma>> {
+        Ok(None)
+    }
+
+    // Needed for BMA only
     #[doc(hidden)]
     fn get_tx_by_hash(
         _dbs_pool: &fast_threadpool::ThreadPoolSyncHandler<SharedDbs<FileBackend>>,
@@ -269,7 +290,7 @@ macro_rules! plug_duniter_modules {
                 Ok(())
             }
 
-            // Needed for BMA only, will be removed when the migration is complete.
+            // Needed for BMA only
             #[allow(dead_code)]
             #[doc(hidden)]
             fn get_transactions_history_for_bma(
@@ -284,7 +305,40 @@ macro_rules! plug_duniter_modules {
                 )*
                 Ok(TxsHistoryForBma::default())
             }
-            // Needed for BMA only, will be removed when the migration is complete.
+
+            // Needed for BMA only
+            #[allow(dead_code)]
+            #[doc(hidden)]
+            fn get_written_transactions_for_bma(
+                profile_path_opt: Option<&Path>,
+                pubkey: PublicKey,
+                start_block: u32,
+                end_block: u32,
+            ) -> KvResult<TxsHistoryForBma> {
+                $(
+                    if let Some(txs_history) = <$M>::get_written_transactions_for_bma(profile_path_opt, pubkey, start_block, end_block)? {
+                        return Ok(txs_history);
+                    }
+                )*
+                Ok(TxsHistoryForBma::default())
+            }
+
+            // Needed for BMA only
+            #[allow(dead_code)]
+            #[doc(hidden)]
+            fn get_pending_transactions_for_bma(
+                dbs_pool: &fast_threadpool::ThreadPoolSyncHandler<SharedDbs<FileBackend>>,
+                pubkey: PublicKey,
+            ) -> KvResult<TxsHistoryForBma> {
+                $(
+                    if let Some(txs_history) = <$M>::get_pending_transactions_for_bma(dbs_pool, pubkey)? {
+                        return Ok(txs_history);
+                    }
+                )*
+                Ok(TxsHistoryForBma::default())
+            }
+
+            // Needed for BMA only
             #[allow(dead_code)]
             #[doc(hidden)]
             fn get_tx_by_hash(
-- 
GitLab