@@ -23,7 +23,10 @@ use bcr_ebill_core::{
23
23
util:: BcrKeys ,
24
24
} ;
25
25
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
+ } ;
27
30
28
31
use super :: { BillAction , Result , error:: Error , service:: BillService } ;
29
32
@@ -414,9 +417,10 @@ impl BillService {
414
417
signer_public_data,
415
418
& bill_id,
416
419
& block,
417
- & identity. key_pair ,
420
+ identity,
418
421
signer_keys,
419
422
timestamp,
423
+ None ,
420
424
)
421
425
. await ?;
422
426
@@ -443,19 +447,17 @@ impl BillService {
443
447
signer_public_data : & BillParticipant ,
444
448
bill_id : & BillId ,
445
449
block : & BillBlock ,
446
- identity_keys : & BcrKeys ,
450
+ identity : & IdentityWithAll ,
447
451
signer_keys : & BcrKeys ,
448
452
timestamp : u64 ,
453
+ bill_keys : Option < BillKeys > ,
449
454
) -> Result < ( ) > {
450
455
match signer_public_data {
451
456
BillParticipant :: Ident ( identified) => {
452
457
match identified. t {
453
458
ContactType :: Person | ContactType :: Anon => {
454
459
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,
459
461
)
460
462
. await ?;
461
463
}
@@ -464,20 +466,21 @@ impl BillService {
464
466
& identified. node_id , // company id
465
467
bill_id,
466
468
block,
467
- identity_keys ,
469
+ identity ,
468
470
& CompanyKeys {
469
471
private_key : signer_keys. get_private_key ( ) ,
470
472
public_key : signer_keys. pub_key ( ) ,
471
473
} ,
472
474
timestamp,
475
+ bill_keys,
473
476
)
474
477
. await ?;
475
478
476
479
self . add_block_to_identity_chain_for_signed_company_bill_action (
477
480
& identified. node_id , // company id
478
481
bill_id,
479
482
block,
480
- identity_keys ,
483
+ identity ,
481
484
timestamp,
482
485
)
483
486
. await ?;
@@ -487,10 +490,7 @@ impl BillService {
487
490
// for anon, we only add to our identity chain, since we're no company
488
491
BillParticipant :: Anon ( _) => {
489
492
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,
494
494
)
495
495
. await ?;
496
496
}
@@ -502,8 +502,9 @@ impl BillService {
502
502
& self ,
503
503
bill_id : & BillId ,
504
504
block : & BillBlock ,
505
- keys : & BcrKeys ,
505
+ identity : & IdentityWithAll ,
506
506
timestamp : u64 ,
507
+ bill_keys : Option < BillKeys > ,
507
508
) -> Result < ( ) > {
508
509
let previous_block = self . identity_blockchain_store . get_latest_block ( ) . await ?;
509
510
let new_block = IdentityBlock :: create_block_for_sign_person_bill (
@@ -513,11 +514,19 @@ impl BillService {
513
514
block_id : block. id ,
514
515
block_hash : block. hash . to_owned ( ) ,
515
516
operation : block. op_code . clone ( ) ,
517
+ bill_key : bill_keys. map ( |k| k. private_key . display_secret ( ) . to_string ( ) ) ,
516
518
} ,
517
- keys ,
519
+ & identity . key_pair ,
518
520
timestamp,
519
521
) ?;
520
522
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 ?;
521
530
Ok ( ( ) )
522
531
}
523
532
@@ -526,7 +535,7 @@ impl BillService {
526
535
company_id : & NodeId ,
527
536
bill_id : & BillId ,
528
537
block : & BillBlock ,
529
- keys : & BcrKeys ,
538
+ identity : & IdentityWithAll ,
530
539
timestamp : u64 ,
531
540
) -> Result < ( ) > {
532
541
let previous_block = self . identity_blockchain_store . get_latest_block ( ) . await ?;
@@ -539,10 +548,17 @@ impl BillService {
539
548
company_id : company_id. to_owned ( ) ,
540
549
operation : block. op_code . clone ( ) ,
541
550
} ,
542
- keys ,
551
+ & identity . key_pair ,
543
552
timestamp,
544
553
) ?;
545
554
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 ?;
546
562
Ok ( ( ) )
547
563
}
548
564
@@ -551,9 +567,10 @@ impl BillService {
551
567
company_id : & NodeId ,
552
568
bill_id : & BillId ,
553
569
block : & BillBlock ,
554
- signatory_keys : & BcrKeys ,
570
+ signatory_identity : & IdentityWithAll ,
555
571
company_keys : & CompanyKeys ,
556
572
timestamp : u64 ,
573
+ bill_keys : Option < BillKeys > ,
557
574
) -> Result < ( ) > {
558
575
let previous_block = self
559
576
. company_blockchain_store
@@ -567,14 +584,27 @@ impl BillService {
567
584
block_id : block. id ,
568
585
block_hash : block. hash . to_owned ( ) ,
569
586
operation : block. op_code . clone ( ) ,
587
+ bill_key : bill_keys. map ( |k| k. private_key . display_secret ( ) . to_string ( ) ) ,
570
588
} ,
571
- signatory_keys ,
589
+ & signatory_identity . key_pair ,
572
590
company_keys,
573
591
timestamp,
574
592
) ?;
575
593
self . company_blockchain_store
576
594
. add_block ( company_id, & new_block)
577
595
. 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 ?;
578
608
Ok ( ( ) )
579
609
}
580
610
}
0 commit comments