@@ -16,6 +16,8 @@ use async_trait::async_trait;
16
16
use bcr_ebill_core:: identity:: validation:: { validate_create_identity, validate_update_identity} ;
17
17
use bcr_ebill_core:: identity:: { ActiveIdentityState , IdentityType } ;
18
18
use bcr_ebill_core:: { NodeId , ServiceTraitBounds , ValidationError } ;
19
+ use bcr_ebill_transport:: NotificationServiceApi ;
20
+ use bcr_ebill_transport:: event:: identity_events:: IdentityChainEvent ;
19
21
use log:: { debug, error, info} ;
20
22
use std:: sync:: Arc ;
21
23
@@ -102,6 +104,7 @@ pub struct IdentityService {
102
104
file_upload_store : Arc < dyn FileUploadStoreApi > ,
103
105
file_upload_client : Arc < dyn FileStorageClientApi > ,
104
106
blockchain_store : Arc < dyn IdentityChainStoreApi > ,
107
+ notification_service : Arc < dyn NotificationServiceApi > ,
105
108
}
106
109
107
110
impl IdentityService {
@@ -110,12 +113,14 @@ impl IdentityService {
110
113
file_upload_store : Arc < dyn FileUploadStoreApi > ,
111
114
file_upload_client : Arc < dyn FileStorageClientApi > ,
112
115
blockchain_store : Arc < dyn IdentityChainStoreApi > ,
116
+ notification_service : Arc < dyn NotificationServiceApi > ,
113
117
) -> Self {
114
118
Self {
115
119
store,
116
120
file_upload_store,
117
121
file_upload_client,
118
122
blockchain_store,
123
+ notification_service,
119
124
}
120
125
}
121
126
@@ -159,6 +164,18 @@ impl IdentityService {
159
164
nostr_hash : nostr_hash. to_string ( ) ,
160
165
} )
161
166
}
167
+
168
+ async fn populate_block (
169
+ & self ,
170
+ identity : & Identity ,
171
+ block : & IdentityBlock ,
172
+ keys : & BcrKeys ,
173
+ ) -> Result < ( ) > {
174
+ self . notification_service
175
+ . send_identity_chain_events ( IdentityChainEvent :: new ( identity, block, keys) )
176
+ . await ?;
177
+ Ok ( ( ) )
178
+ }
162
179
}
163
180
164
181
impl ServiceTraitBounds for IdentityService { }
@@ -315,8 +332,8 @@ impl IdentityServiceApi for IdentityService {
315
332
timestamp,
316
333
) ?;
317
334
self . blockchain_store . add_block ( & new_block) . await ?;
318
-
319
335
self . store . save ( & identity) . await ?;
336
+ self . populate_block ( & identity, & new_block, & keys) . await ?;
320
337
debug ! ( "updated identity" ) ;
321
338
Ok ( ( ) )
322
339
}
@@ -421,6 +438,8 @@ impl IdentityServiceApi for IdentityService {
421
438
422
439
// persist the identity in the DB
423
440
self . store . save ( & identity) . await ?;
441
+ self . populate_block ( & identity, first_block, & keys) . await ?;
442
+
424
443
debug ! ( "created identity" ) ;
425
444
Ok ( ( ) )
426
445
}
@@ -524,8 +543,8 @@ impl IdentityServiceApi for IdentityService {
524
543
timestamp,
525
544
) ?;
526
545
self . blockchain_store . add_block ( & new_block) . await ?;
527
-
528
546
self . store . save ( & identity) . await ?;
547
+ self . populate_block ( & identity, & new_block, & keys) . await ?;
529
548
debug ! ( "deanonymized identity" ) ;
530
549
Ok ( ( ) )
531
550
}
@@ -627,7 +646,7 @@ mod tests {
627
646
external:: file_storage:: MockFileStorageClientApi ,
628
647
tests:: tests:: {
629
648
MockFileUploadStoreApiMock , MockIdentityChainStoreApiMock , MockIdentityStoreApiMock ,
630
- empty_identity, empty_optional_address, init_test_cfg,
649
+ MockNotificationService , empty_identity, empty_optional_address, init_test_cfg,
631
650
} ,
632
651
} ;
633
652
use mockall:: predicate:: eq;
@@ -638,18 +657,21 @@ mod tests {
638
657
Arc :: new ( MockFileUploadStoreApiMock :: new ( ) ) ,
639
658
Arc :: new ( MockFileStorageClientApi :: new ( ) ) ,
640
659
Arc :: new ( MockIdentityChainStoreApiMock :: new ( ) ) ,
660
+ Arc :: new ( MockNotificationService :: new ( ) ) ,
641
661
)
642
662
}
643
663
644
664
fn get_service_with_chain_storage (
645
665
mock_storage : MockIdentityStoreApiMock ,
646
666
mock_chain_storage : MockIdentityChainStoreApiMock ,
667
+ notification : MockNotificationService ,
647
668
) -> IdentityService {
648
669
IdentityService :: new (
649
670
Arc :: new ( mock_storage) ,
650
671
Arc :: new ( MockFileUploadStoreApiMock :: new ( ) ) ,
651
672
Arc :: new ( MockFileStorageClientApi :: new ( ) ) ,
652
673
Arc :: new ( mock_chain_storage) ,
674
+ Arc :: new ( notification) ,
653
675
)
654
676
}
655
677
@@ -666,8 +688,13 @@ mod tests {
666
688
. returning ( || Ok ( BcrKeys :: new ( ) ) ) ;
667
689
let mut chain_storage = MockIdentityChainStoreApiMock :: new ( ) ;
668
690
chain_storage. expect_add_block ( ) . returning ( |_| Ok ( ( ) ) ) ;
691
+ let mut notification = MockNotificationService :: new ( ) ;
692
+ notification
693
+ . expect_send_identity_chain_events ( )
694
+ . returning ( |_| Ok ( ( ) ) )
695
+ . once ( ) ;
669
696
670
- let service = get_service_with_chain_storage ( storage, chain_storage) ;
697
+ let service = get_service_with_chain_storage ( storage, chain_storage, notification ) ;
671
698
let res = service
672
699
. create_identity (
673
700
IdentityType :: Ident ,
@@ -691,6 +718,7 @@ mod tests {
691
718
async fn create_anon_identity_baseline ( ) {
692
719
init_test_cfg ( ) ;
693
720
let mut storage = MockIdentityStoreApiMock :: new ( ) ;
721
+
694
722
storage
695
723
. expect_get_or_create_key_pair ( )
696
724
. returning ( || Ok ( BcrKeys :: new ( ) ) ) ;
@@ -700,8 +728,13 @@ mod tests {
700
728
. returning ( || Ok ( BcrKeys :: new ( ) ) ) ;
701
729
let mut chain_storage = MockIdentityChainStoreApiMock :: new ( ) ;
702
730
chain_storage. expect_add_block ( ) . returning ( |_| Ok ( ( ) ) ) ;
731
+ let mut notification = MockNotificationService :: new ( ) ;
732
+ notification
733
+ . expect_send_identity_chain_events ( )
734
+ . returning ( |_| Ok ( ( ) ) )
735
+ . once ( ) ;
703
736
704
- let service = get_service_with_chain_storage ( storage, chain_storage) ;
737
+ let service = get_service_with_chain_storage ( storage, chain_storage, notification ) ;
705
738
let res = service
706
739
. create_identity (
707
740
IdentityType :: Anon ,
@@ -749,8 +782,13 @@ mod tests {
749
782
. clone ( ) ,
750
783
)
751
784
} ) ;
785
+ let mut notification = MockNotificationService :: new ( ) ;
786
+ notification
787
+ . expect_send_identity_chain_events ( )
788
+ . returning ( |_| Ok ( ( ) ) )
789
+ . once ( ) ;
752
790
753
- let service = get_service_with_chain_storage ( storage, chain_storage) ;
791
+ let service = get_service_with_chain_storage ( storage, chain_storage, notification ) ;
754
792
let res = service
755
793
. deanonymize_identity (
756
794
IdentityType :: Ident ,
@@ -789,8 +827,10 @@ mod tests {
789
827
} ) ;
790
828
let mut chain_storage = MockIdentityChainStoreApiMock :: new ( ) ;
791
829
chain_storage. expect_add_block ( ) . returning ( |_| Ok ( ( ) ) ) ;
830
+ let mut notification = MockNotificationService :: new ( ) ;
831
+ notification. expect_send_identity_chain_events ( ) . never ( ) ;
792
832
793
- let service = get_service_with_chain_storage ( storage, chain_storage) ;
833
+ let service = get_service_with_chain_storage ( storage, chain_storage, notification ) ;
794
834
let res = service
795
835
. deanonymize_identity (
796
836
IdentityType :: Anon ,
@@ -832,8 +872,10 @@ mod tests {
832
872
} ) ;
833
873
let mut chain_storage = MockIdentityChainStoreApiMock :: new ( ) ;
834
874
chain_storage. expect_add_block ( ) . returning ( |_| Ok ( ( ) ) ) ;
875
+ let mut notification = MockNotificationService :: new ( ) ;
876
+ notification. expect_send_identity_chain_events ( ) . never ( ) ;
835
877
836
- let service = get_service_with_chain_storage ( storage, chain_storage) ;
878
+ let service = get_service_with_chain_storage ( storage, chain_storage, notification ) ;
837
879
let res = service
838
880
. deanonymize_identity (
839
881
IdentityType :: Ident ,
@@ -880,8 +922,13 @@ mod tests {
880
922
)
881
923
} ) ;
882
924
chain_storage. expect_add_block ( ) . returning ( |_| Ok ( ( ) ) ) ;
925
+ let mut notification = MockNotificationService :: new ( ) ;
926
+ notification
927
+ . expect_send_identity_chain_events ( )
928
+ . returning ( |_| Ok ( ( ) ) )
929
+ . once ( ) ;
883
930
884
- let service = get_service_with_chain_storage ( storage, chain_storage) ;
931
+ let service = get_service_with_chain_storage ( storage, chain_storage, notification ) ;
885
932
let res = service
886
933
. update_identity (
887
934
Some ( "new_name" . to_string ( ) ) ,
@@ -957,9 +1004,14 @@ mod tests {
957
1004
. clone ( ) ,
958
1005
)
959
1006
} ) ;
960
- chain_storage. expect_add_block ( ) . returning ( |_| Ok ( ( ) ) ) ;
961
-
962
- let service = get_service_with_chain_storage ( storage, chain_storage) ;
1007
+ chain_storage
1008
+ . expect_add_block ( )
1009
+ . returning ( |_| Ok ( ( ) ) )
1010
+ . once ( ) ;
1011
+ let mut notification = MockNotificationService :: new ( ) ;
1012
+ notification. expect_send_identity_chain_events ( ) . never ( ) ;
1013
+
1014
+ let service = get_service_with_chain_storage ( storage, chain_storage, notification) ;
963
1015
let res = service
964
1016
. update_identity (
965
1017
Some ( "new_name" . to_string ( ) ) ,
0 commit comments