@@ -23,7 +23,10 @@ use bcr_ebill_core::{
2323 util:: BcrKeys ,
2424} ;
2525
26- use crate :: data:: validate_node_id_network;
26+ use crate :: {
27+ data:: validate_node_id_network,
28+ service:: notification_service:: event:: { CompanyChainEvent , IdentityChainEvent } ,
29+ } ;
2730
2831use super :: { BillAction , Result , error:: Error , service:: BillService } ;
2932
@@ -414,9 +417,10 @@ impl BillService {
414417 signer_public_data,
415418 & bill_id,
416419 & block,
417- & identity. key_pair ,
420+ identity,
418421 signer_keys,
419422 timestamp,
423+ None ,
420424 )
421425 . await ?;
422426
@@ -443,19 +447,17 @@ impl BillService {
443447 signer_public_data : & BillParticipant ,
444448 bill_id : & BillId ,
445449 block : & BillBlock ,
446- identity_keys : & BcrKeys ,
450+ identity : & IdentityWithAll ,
447451 signer_keys : & BcrKeys ,
448452 timestamp : u64 ,
453+ bill_keys : Option < BillKeys > ,
449454 ) -> Result < ( ) > {
450455 match signer_public_data {
451456 BillParticipant :: Ident ( identified) => {
452457 match identified. t {
453458 ContactType :: Person | ContactType :: Anon => {
454459 self . add_block_to_identity_chain_for_signed_bill_action (
455- bill_id,
456- block,
457- identity_keys,
458- timestamp,
460+ bill_id, block, identity, timestamp, bill_keys,
459461 )
460462 . await ?;
461463 }
@@ -464,20 +466,21 @@ impl BillService {
464466 & identified. node_id , // company id
465467 bill_id,
466468 block,
467- identity_keys ,
469+ identity ,
468470 & CompanyKeys {
469471 private_key : signer_keys. get_private_key ( ) ,
470472 public_key : signer_keys. pub_key ( ) ,
471473 } ,
472474 timestamp,
475+ bill_keys,
473476 )
474477 . await ?;
475478
476479 self . add_block_to_identity_chain_for_signed_company_bill_action (
477480 & identified. node_id , // company id
478481 bill_id,
479482 block,
480- identity_keys ,
483+ identity ,
481484 timestamp,
482485 )
483486 . await ?;
@@ -487,10 +490,7 @@ impl BillService {
487490 // for anon, we only add to our identity chain, since we're no company
488491 BillParticipant :: Anon ( _) => {
489492 self . add_block_to_identity_chain_for_signed_bill_action (
490- bill_id,
491- block,
492- identity_keys,
493- timestamp,
493+ bill_id, block, identity, timestamp, bill_keys,
494494 )
495495 . await ?;
496496 }
@@ -502,8 +502,9 @@ impl BillService {
502502 & self ,
503503 bill_id : & BillId ,
504504 block : & BillBlock ,
505- keys : & BcrKeys ,
505+ identity : & IdentityWithAll ,
506506 timestamp : u64 ,
507+ bill_keys : Option < BillKeys > ,
507508 ) -> Result < ( ) > {
508509 let previous_block = self . identity_blockchain_store . get_latest_block ( ) . await ?;
509510 let new_block = IdentityBlock :: create_block_for_sign_person_bill (
@@ -513,11 +514,19 @@ impl BillService {
513514 block_id : block. id ,
514515 block_hash : block. hash . to_owned ( ) ,
515516 operation : block. op_code . clone ( ) ,
517+ bill_key : bill_keys. map ( |k| k. private_key . display_secret ( ) . to_string ( ) ) ,
516518 } ,
517- keys ,
519+ & identity . key_pair ,
518520 timestamp,
519521 ) ?;
520522 self . identity_blockchain_store . add_block ( & new_block) . await ?;
523+ self . notification_service
524+ . send_identity_chain_events ( IdentityChainEvent :: new (
525+ & identity. identity ,
526+ & new_block,
527+ & identity. key_pair ,
528+ ) )
529+ . await ?;
521530 Ok ( ( ) )
522531 }
523532
@@ -526,7 +535,7 @@ impl BillService {
526535 company_id : & NodeId ,
527536 bill_id : & BillId ,
528537 block : & BillBlock ,
529- keys : & BcrKeys ,
538+ identity : & IdentityWithAll ,
530539 timestamp : u64 ,
531540 ) -> Result < ( ) > {
532541 let previous_block = self . identity_blockchain_store . get_latest_block ( ) . await ?;
@@ -539,10 +548,17 @@ impl BillService {
539548 company_id : company_id. to_owned ( ) ,
540549 operation : block. op_code . clone ( ) ,
541550 } ,
542- keys ,
551+ & identity . key_pair ,
543552 timestamp,
544553 ) ?;
545554 self . identity_blockchain_store . add_block ( & new_block) . await ?;
555+ self . notification_service
556+ . send_identity_chain_events ( IdentityChainEvent :: new (
557+ & identity. identity ,
558+ & new_block,
559+ & identity. key_pair ,
560+ ) )
561+ . await ?;
546562 Ok ( ( ) )
547563 }
548564
@@ -551,9 +567,10 @@ impl BillService {
551567 company_id : & NodeId ,
552568 bill_id : & BillId ,
553569 block : & BillBlock ,
554- signatory_keys : & BcrKeys ,
570+ signatory_identity : & IdentityWithAll ,
555571 company_keys : & CompanyKeys ,
556572 timestamp : u64 ,
573+ bill_keys : Option < BillKeys > ,
557574 ) -> Result < ( ) > {
558575 let previous_block = self
559576 . company_blockchain_store
@@ -567,14 +584,27 @@ impl BillService {
567584 block_id : block. id ,
568585 block_hash : block. hash . to_owned ( ) ,
569586 operation : block. op_code . clone ( ) ,
587+ bill_key : bill_keys. map ( |k| k. private_key . display_secret ( ) . to_string ( ) ) ,
570588 } ,
571- signatory_keys ,
589+ & signatory_identity . key_pair ,
572590 company_keys,
573591 timestamp,
574592 ) ?;
575593 self . company_blockchain_store
576594 . add_block ( company_id, & new_block)
577595 . await ?;
596+
597+ let chain = self . company_blockchain_store . get_chain ( company_id) . await ?;
598+ let company = self . company_store . get ( company_id) . await ?;
599+ self . notification_service
600+ . send_company_chain_events ( CompanyChainEvent :: new (
601+ & company,
602+ & chain,
603+ company_keys,
604+ None ,
605+ true ,
606+ ) )
607+ . await ?;
578608 Ok ( ( ) )
579609 }
580610}
0 commit comments