From a68d49b4aeb102ddd482ce9efc085ca32880304b Mon Sep 17 00:00:00 2001
From: librelois <elois@ifee.fr>
Date: Sun, 12 May 2019 00:28:33 +0200
Subject: [PATCH] [ref] message: event: add field event_from

---
 lib/core/message/lib.rs                              | 2 ++
 lib/modules/blockchain/blockchain/src/constants.rs   | 3 +++
 lib/modules/blockchain/blockchain/src/events/sent.rs | 1 +
 lib/modules/blockchain/blockchain/src/lib.rs         | 3 ++-
 lib/modules/ws2p-v1-legacy/src/constants.rs          | 3 +++
 lib/modules/ws2p-v1-legacy/src/events/sent.rs        | 4 +++-
 lib/modules/ws2p-v1-legacy/src/lib.rs                | 2 +-
 7 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/lib/core/message/lib.rs b/lib/core/message/lib.rs
index f8e32160..32fad925 100644
--- a/lib/core/message/lib.rs
+++ b/lib/core/message/lib.rs
@@ -49,6 +49,8 @@ use crate::responses::*;
 pub enum DursMsg {
     /// Durs module event
     Event {
+        /// The module that issued the event
+        event_from: ModuleStaticName,
         /// Event type
         event_type: ModuleEvent,
         /// Event content
diff --git a/lib/modules/blockchain/blockchain/src/constants.rs b/lib/modules/blockchain/blockchain/src/constants.rs
index 6f575d14..9b477e69 100644
--- a/lib/modules/blockchain/blockchain/src/constants.rs
+++ b/lib/modules/blockchain/blockchain/src/constants.rs
@@ -13,6 +13,9 @@
 // You should have received a copy of the GNU Affero General Public License
 // along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
+/// Module name
+pub static MODULE_NAME: &'static str = "blockchain";
+
 /// Default currency
 pub static DEFAULT_CURRENCY: &'static str = "g1";
 
diff --git a/lib/modules/blockchain/blockchain/src/events/sent.rs b/lib/modules/blockchain/blockchain/src/events/sent.rs
index 3f1a996c..d165ba61 100644
--- a/lib/modules/blockchain/blockchain/src/events/sent.rs
+++ b/lib/modules/blockchain/blockchain/src/events/sent.rs
@@ -29,6 +29,7 @@ pub fn send_event(bc: &BlockchainModule, event: &BlockchainEvent) {
     };
     bc.router_sender
         .send(RouterThreadMessage::ModuleMessage(DursMsg::Event {
+            event_from: ModuleStaticName(MODULE_NAME),
             event_type: module_event,
             event_content: DursEvent::BlockchainEvent(Box::new(event.clone())),
         }))
diff --git a/lib/modules/blockchain/blockchain/src/lib.rs b/lib/modules/blockchain/blockchain/src/lib.rs
index f03e474a..daf65f1e 100644
--- a/lib/modules/blockchain/blockchain/src/lib.rs
+++ b/lib/modules/blockchain/blockchain/src/lib.rs
@@ -181,7 +181,7 @@ pub enum VerifyBlockHashsError {
 impl BlockchainModule {
     /// Return module identifier
     pub fn name() -> ModuleStaticName {
-        ModuleStaticName("blockchain")
+        ModuleStaticName(MODULE_NAME)
     }
     /// Loading blockchain configuration
     pub fn load_blockchain_conf<DC: DursConfTrait>(
@@ -279,6 +279,7 @@ impl BlockchainModule {
                         DursMsg::Event {
                             event_type,
                             event_content,
+                            ..
                         } => events::received::receive_event(self, event_type, event_content),
                         DursMsg::Response {
                             req_id,
diff --git a/lib/modules/ws2p-v1-legacy/src/constants.rs b/lib/modules/ws2p-v1-legacy/src/constants.rs
index cdc14af7..f9d92d6a 100644
--- a/lib/modules/ws2p-v1-legacy/src/constants.rs
+++ b/lib/modules/ws2p-v1-legacy/src/constants.rs
@@ -15,6 +15,9 @@
 
 //! WS2Pv1 constants
 
+/// Module name
+pub static MODULE_NAME: &'static str = "ws2p1";
+
 /// API Name
 pub static WS2P_API: &'static str = "WS2P";
 
diff --git a/lib/modules/ws2p-v1-legacy/src/events/sent.rs b/lib/modules/ws2p-v1-legacy/src/events/sent.rs
index 16750ed8..c386d45a 100644
--- a/lib/modules/ws2p-v1-legacy/src/events/sent.rs
+++ b/lib/modules/ws2p-v1-legacy/src/events/sent.rs
@@ -15,10 +15,11 @@
 
 //! Sub-module managing the events emitted by the blockchain module.
 
+use crate::constants;
 use crate::WS2Pv1Module;
 use durs_message::events::DursEvent;
 use durs_message::*;
-use durs_module::{ModuleEvent, RouterThreadMessage};
+use durs_module::{ModuleEvent, ModuleStaticName, RouterThreadMessage};
 use durs_network::documents::BlockchainDocument;
 use durs_network::events::NetworkEvent;
 
@@ -52,6 +53,7 @@ pub fn send_network_event(ws2p_module: &mut WS2Pv1Module, event: NetworkEvent) {
     ws2p_module
         .router_sender
         .send(RouterThreadMessage::ModuleMessage(DursMsg::Event {
+            event_from: ModuleStaticName(constants::MODULE_NAME),
             event_type: module_event,
             event_content: DursEvent::NetworkEvent(event),
         }))
diff --git a/lib/modules/ws2p-v1-legacy/src/lib.rs b/lib/modules/ws2p-v1-legacy/src/lib.rs
index ef00b93a..ed7c9e22 100644
--- a/lib/modules/ws2p-v1-legacy/src/lib.rs
+++ b/lib/modules/ws2p-v1-legacy/src/lib.rs
@@ -360,7 +360,7 @@ impl DursModule<DuRsConf, DursMsg> for WS2Pv1Module {
     type ModuleOpt = WS2POpt;
 
     fn name() -> ModuleStaticName {
-        ModuleStaticName("ws2p1")
+        ModuleStaticName(MODULE_NAME)
     }
     fn priority() -> ModulePriority {
         ModulePriority::Essential()
-- 
GitLab