Explorar o código

tx: impl_p2p_message for Transaction when "net" feature is defined.

parazyd %!s(int64=2) %!d(string=hai) anos
pai
achega
64e54f933e
Modificáronse 2 ficheiros con 12 adicións e 13 borrados
  1. 6 13
      bin/darkfid2/src/proto/protocol_tx.rs
  2. 6 0
      src/tx/mod.rs

+ 6 - 13
bin/darkfid2/src/proto/protocol_tx.rs

@@ -25,9 +25,8 @@ use tinyjson::JsonValue;
 use url::Url;
 
 use darkfi::{
-    impl_p2p_message,
     net::{
-        ChannelPtr, Message, MessageSubscription, P2pPtr, ProtocolBase, ProtocolBasePtr,
+        ChannelPtr, MessageSubscription, P2pPtr, ProtocolBase, ProtocolBasePtr,
         ProtocolJobsManager, ProtocolJobsManagerPtr,
     },
     rpc::jsonrpc::JsonSubscriber,
@@ -36,16 +35,10 @@ use darkfi::{
     validator::ValidatorPtr,
     Result,
 };
-use darkfi_serial::{serialize, SerialDecodable, SerialEncodable};
-
-/// Auxiliary [`Transaction`] wrapper structure used for messaging.
-#[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
-struct TransactionMessage(Transaction);
-
-impl_p2p_message!(TransactionMessage, "tx");
+use darkfi_serial::serialize;
 
 pub struct ProtocolTx {
-    tx_sub: MessageSubscription<TransactionMessage>,
+    tx_sub: MessageSubscription<Transaction>,
     jobsman: ProtocolJobsManagerPtr,
     validator: ValidatorPtr,
     p2p: P2pPtr,
@@ -65,9 +58,9 @@ impl ProtocolTx {
             "Adding ProtocolTx to the protocol registry"
         );
         let msg_subsystem = channel.message_subsystem();
-        msg_subsystem.add_dispatch::<TransactionMessage>().await;
+        msg_subsystem.add_dispatch::<Transaction>().await;
 
-        let tx_sub = channel.subscribe_msg::<TransactionMessage>().await?;
+        let tx_sub = channel.subscribe_msg::<Transaction>().await?;
 
         Ok(Arc::new(Self {
             tx_sub,
@@ -110,7 +103,7 @@ impl ProtocolTx {
             let tx_copy = (*tx).clone();
 
             // Nodes use unconfirmed_txs vector as seen_txs pool.
-            match self.validator.write().await.append_tx(&tx_copy.0).await {
+            match self.validator.write().await.append_tx(&tx_copy).await {
                 Ok(()) => {
                     self.p2p.broadcast_with_exclude(&tx_copy, &exclude_list).await;
                     let encoded_tx = JsonValue::String(base64::encode(&serialize(&tx_copy)));

+ 6 - 0
src/tx/mod.rs

@@ -162,3 +162,9 @@ impl Transaction {
         Ok(hasher.finalize())
     }
 }
+
+#[cfg(feature = "net")]
+use crate::net::Message;
+
+#[cfg(feature = "net")]
+crate::impl_p2p_message!(Transaction, "tx");