@@ -14,7 +14,7 @@ use iroha_crypto::HashOf;
14
14
use iroha_data_model:: { prelude:: * , small:: SmallVec } ;
15
15
use iroha_logger:: prelude:: * ;
16
16
use iroha_telemetry:: metrics:: Metrics ;
17
- use tokio:: task;
17
+ use tokio:: { sync :: broadcast , task} ;
18
18
19
19
use crate :: {
20
20
block:: Chain ,
@@ -86,7 +86,7 @@ pub struct WorldStateView {
86
86
/// Notifies subscribers when new block is applied
87
87
new_block_notifier : Arc < NewBlockNotificationSender > ,
88
88
/// Transmitter to broadcast [`WorldStateView`]-related events.
89
- events_sender : Option < EventsSender > ,
89
+ events_sender : EventsSender ,
90
90
}
91
91
92
92
impl Default for WorldStateView {
@@ -117,14 +117,9 @@ impl WorldStateView {
117
117
#[ must_use]
118
118
#[ inline]
119
119
pub fn new ( world : World ) -> Self {
120
- Self :: from_configuration ( Configuration :: default ( ) , world)
121
- }
122
-
123
- /// Add the ability of emitting events to [`WorldStateView`].
124
- #[ must_use]
125
- pub fn with_events ( mut self , events_sender : EventsSender ) -> Self {
126
- self . events_sender = Some ( events_sender) ;
127
- self
120
+ // Added to remain backward compatible with other code primary in tests
121
+ let ( events_sender, _) = broadcast:: channel ( 1 ) ;
122
+ Self :: from_configuration ( Configuration :: default ( ) , world, events_sender)
128
123
}
129
124
130
125
/// Get `Account`'s `Asset`s
@@ -277,14 +272,7 @@ impl WorldStateView {
277
272
278
273
/// Send [`Event`]s to known subscribers.
279
274
fn produce_event ( & self , event : impl Into < Event > ) {
280
- self . events_sender . as_ref ( ) . map_or_else (
281
- || {
282
- warn ! ( "wsv does not equip an events sender" ) ;
283
- } ,
284
- |events_sender| {
285
- drop ( events_sender. send ( event. into ( ) ) ) ;
286
- } ,
287
- )
275
+ let _result = self . events_sender . send ( event. into ( ) ) ;
288
276
}
289
277
290
278
/// Tries to get asset or inserts new with `default_asset_value`.
@@ -497,7 +485,11 @@ impl WorldStateView {
497
485
498
486
/// Construct [`WorldStateView`] with specific [`Configuration`].
499
487
#[ inline]
500
- pub fn from_configuration ( config : Configuration , world : World ) -> Self {
488
+ pub fn from_configuration (
489
+ config : Configuration ,
490
+ world : World ,
491
+ events_sender : EventsSender ,
492
+ ) -> Self {
501
493
let ( new_block_notifier, _) = tokio:: sync:: watch:: channel ( ( ) ) ;
502
494
503
495
Self {
@@ -507,7 +499,7 @@ impl WorldStateView {
507
499
blocks : Arc :: new ( Chain :: new ( ) ) ,
508
500
metrics : Arc :: new ( Metrics :: default ( ) ) ,
509
501
new_block_notifier : Arc :: new ( new_block_notifier) ,
510
- events_sender : None ,
502
+ events_sender,
511
503
}
512
504
}
513
505
0 commit comments