2828from hathor .feature_activation .feature_service import FeatureService
2929from hathor .feature_activation .utils import is_fee_active , is_nano_active
3030from hathor .profiler import get_cpu_profiler
31- from hathor .pubsub import HathorEvents , PubSubManager
31+ from hathor .pubsub import EventArguments , HathorEvents , PubSubManager
3232from hathor .reactor import ReactorProtocol
3333from hathor .transaction import BaseTransaction , Block , Transaction
3434from hathor .transaction .storage import TransactionStorage
@@ -52,7 +52,6 @@ class VertexHandler:
5252 '_feature_service' ,
5353 '_pubsub' ,
5454 '_execution_manager' ,
55- '_wallet' ,
5655 '_log_vertex_bytes' ,
5756 )
5857
@@ -79,9 +78,21 @@ def __init__(
7978 self ._feature_service = feature_service
8079 self ._pubsub = pubsub
8180 self ._execution_manager = execution_manager
82- self ._wallet = wallet
8381 self ._log_vertex_bytes = log_vertex_bytes
8482
83+ self ._register_wallet (wallet )
84+
85+ def _register_wallet (self , wallet : BaseWallet | None ) -> None :
86+ """Register a wallet on pubsub."""
87+ if wallet is None :
88+ return
89+
90+ def handler (event : HathorEvents , args : EventArguments ) -> None :
91+ assert event == HathorEvents .NETWORK_NEW_TX_PROCESSING
92+ wallet .on_new_tx (args .tx )
93+
94+ self ._pubsub .subscribe (HathorEvents .NETWORK_NEW_TX_PROCESSING , handler )
95+
8596 @cpu .profiler ('on_new_block' )
8697 @inlineCallbacks
8798 def on_new_block (self , block : Block , * , deps : list [Transaction ]) -> Generator [Any , Any , bool ]:
@@ -239,6 +250,7 @@ def _unsafe_save_and_run_consensus(self, vertex: BaseTransaction) -> None:
239250 self ._tx_storage .save_transaction (vertex )
240251 with non_critical_code (self ._log ):
241252 self ._tx_storage .indexes .add_to_non_critical_indexes (vertex )
253+ self ._pubsub .publish (HathorEvents .NETWORK_NEW_TX_PROCESSING , tx = vertex )
242254 self ._consensus .unsafe_update (vertex )
243255
244256 def _post_consensus (
@@ -268,10 +280,6 @@ def _post_consensus(
268280 # Publish to pubsub manager the new tx accepted, now that it's full validated
269281 self ._pubsub .publish (HathorEvents .NETWORK_NEW_TX_ACCEPTED , tx = vertex )
270282
271- if self ._wallet :
272- # TODO Remove it and use pubsub instead.
273- self ._wallet .on_new_tx (vertex )
274-
275283 self ._log_new_object (vertex , 'new {}' , quiet = quiet )
276284
277285 def _log_new_object (self , tx : BaseTransaction , message_fmt : str , * , quiet : bool ) -> None :
0 commit comments