Skip to content

Commit 7ba1b32

Browse files
authored
Add bill amount to bill notifications (#395)
1 parent 85f7141 commit 7ba1b32

File tree

4 files changed

+99
-34
lines changed

4 files changed

+99
-34
lines changed

src/service/bill_service.rs

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,9 +1400,14 @@ impl BillService {
14001400
.await?;
14011401

14021402
if !sent {
1403-
let current_identity = IdentityPublicData::new(self.identity_store.get().await?);
1403+
let identity = self.identity_store.get().await?;
1404+
let current_identity = IdentityPublicData::new(identity.clone());
14041405
let participants = chain.get_all_nodes_from_bill(&bill_keys)?;
14051406
let mut recipient_options = vec![current_identity];
1407+
let bill = self
1408+
.get_last_version_bill(&chain, &bill_keys, &identity)
1409+
.await?;
1410+
14061411
for node_id in participants {
14071412
let contact: Option<IdentityPublicData> =
14081413
self.contact_store.get(&node_id).await?.map(|c| c.into());
@@ -1415,7 +1420,12 @@ impl BillService {
14151420
.collect::<Vec<IdentityPublicData>>();
14161421

14171422
self.notification_service
1418-
.send_request_to_action_timed_out_event(bill_id, action.to_owned(), recipients)
1423+
.send_request_to_action_timed_out_event(
1424+
bill_id,
1425+
Some(bill.sum),
1426+
action.to_owned(),
1427+
recipients,
1428+
)
14191429
.await?;
14201430

14211431
// remember we have sent the notification
@@ -1709,25 +1719,37 @@ impl BillService {
17091719
self.notification_service
17101720
.send_request_to_action_rejected_event(
17111721
bill_id,
1722+
Some(bill.sum),
17121723
ActionType::AcceptBill,
17131724
recipients,
17141725
)
17151726
.await?;
17161727
}
17171728
BillOpCode::RejectToBuy => {
17181729
self.notification_service
1719-
.send_request_to_action_rejected_event(bill_id, ActionType::BuyBill, recipients)
1730+
.send_request_to_action_rejected_event(
1731+
bill_id,
1732+
Some(bill.sum),
1733+
ActionType::BuyBill,
1734+
recipients,
1735+
)
17201736
.await?;
17211737
}
17221738
BillOpCode::RejectToPay => {
17231739
self.notification_service
1724-
.send_request_to_action_rejected_event(bill_id, ActionType::PayBill, recipients)
1740+
.send_request_to_action_rejected_event(
1741+
bill_id,
1742+
Some(bill.sum),
1743+
ActionType::PayBill,
1744+
recipients,
1745+
)
17251746
.await?;
17261747
}
17271748
BillOpCode::RejectToPayRecourse => {
17281749
self.notification_service
17291750
.send_request_to_action_rejected_event(
17301751
bill_id,
1752+
Some(bill.sum),
17311753
ActionType::RecourseBill,
17321754
recipients,
17331755
)
@@ -2525,7 +2547,7 @@ impl BillServiceApi for BillService {
25252547
RecourseReason::Pay(_, _) => ActionType::PayBill,
25262548
};
25272549
self.notification_service
2528-
.send_recourse_action_event(bill_id, action_type, recoursee)
2550+
.send_recourse_action_event(bill_id, Some(sum), action_type, recoursee)
25292551
.await?;
25302552

25312553
Ok(blockchain)
@@ -2605,7 +2627,7 @@ impl BillServiceApi for BillService {
26052627
.await?;
26062628

26072629
self.notification_service
2608-
.send_bill_recourse_paid_event(bill_id, &recoursee)
2630+
.send_bill_recourse_paid_event(bill_id, Some(payment_info.sum), &recoursee)
26092631
.await?;
26102632

26112633
return Ok(blockchain);
@@ -2765,7 +2787,7 @@ impl BillServiceApi for BillService {
27652787
.await?;
27662788

27672789
self.notification_service
2768-
.send_offer_to_sell_event(bill_id, &buyer)
2790+
.send_offer_to_sell_event(bill_id, Some(sum), &buyer)
27692791
.await?;
27702792

27712793
return Ok(blockchain);
@@ -2849,7 +2871,7 @@ impl BillServiceApi for BillService {
28492871
.await?;
28502872

28512873
self.notification_service
2852-
.send_bill_is_sold_event(bill_id, &buyer)
2874+
.send_bill_is_sold_event(bill_id, Some(payment_info.sum), &buyer)
28532875
.await?;
28542876

28552877
return Ok(blockchain);
@@ -5417,7 +5439,7 @@ pub mod tests {
54175439
// Request to sell event should be sent
54185440
notification_service
54195441
.expect_send_offer_to_sell_event()
5420-
.returning(|_, _| Ok(()));
5442+
.returning(|_, _, _| Ok(()));
54215443

54225444
let service = get_service_base(
54235445
storage,
@@ -5558,7 +5580,7 @@ pub mod tests {
55585580
// Request to sell event should be sent
55595581
notification_service
55605582
.expect_send_bill_is_sold_event()
5561-
.returning(|_, _| Ok(()));
5583+
.returning(|_, _, _| Ok(()));
55625584

55635585
let service = get_service_base(
55645586
storage,
@@ -5647,7 +5669,7 @@ pub mod tests {
56475669
// Sold event should be sent
56485670
notification_service
56495671
.expect_send_bill_is_sold_event()
5650-
.returning(|_, _| Ok(()));
5672+
.returning(|_, _, _| Ok(()));
56515673

56525674
let service = get_service_base(
56535675
storage,
@@ -5711,7 +5733,7 @@ pub mod tests {
57115733
// Request to sell event should be sent
57125734
notification_service
57135735
.expect_send_bill_is_sold_event()
5714-
.returning(|_, _| Ok(()));
5736+
.returning(|_, _, _| Ok(()));
57155737

57165738
let service = get_service_base(
57175739
storage,
@@ -6197,7 +6219,7 @@ pub mod tests {
61976219
let mut notification_service = MockNotificationServiceApi::new();
61986220
notification_service
61996221
.expect_send_bill_is_sold_event()
6200-
.returning(|_, _| Ok(()));
6222+
.returning(|_, _, _| Ok(()));
62016223

62026224
let service = get_service_base(
62036225
storage,
@@ -6293,7 +6315,7 @@ pub mod tests {
62936315
let mut notification_service = MockNotificationServiceApi::new();
62946316
notification_service
62956317
.expect_send_bill_is_sold_event()
6296-
.returning(|_, _| Ok(()));
6318+
.returning(|_, _, _| Ok(()));
62976319

62986320
let service = get_service_base(
62996321
storage,
@@ -6559,16 +6581,22 @@ pub mod tests {
65596581
.expect_send_request_to_action_timed_out_event()
65606582
.with(
65616583
eq("1234"),
6584+
always(),
65626585
eq(ActionType::AcceptBill),
65636586
recipient_check.clone(),
65646587
)
6565-
.returning(|_, _, _| Ok(()));
6588+
.returning(|_, _, _, _| Ok(()));
65666589

65676590
// send pay timeout notification
65686591
notification_service
65696592
.expect_send_request_to_action_timed_out_event()
6570-
.with(eq("4321"), eq(ActionType::PayBill), recipient_check)
6571-
.returning(|_, _, _| Ok(()));
6593+
.with(
6594+
eq("4321"),
6595+
always(),
6596+
eq(ActionType::PayBill),
6597+
recipient_check,
6598+
)
6599+
.returning(|_, _, _, _| Ok(()));
65726600

65736601
// marks accept bill timeout as sent
65746602
notification_service
@@ -7224,8 +7252,8 @@ pub mod tests {
72247252
let mut notification_service = MockNotificationServiceApi::new();
72257253
notification_service
72267254
.expect_send_request_to_action_rejected_event()
7227-
.with(eq("1234"), eq(ActionType::AcceptBill), always())
7228-
.returning(|_, _, _| Ok(()));
7255+
.with(eq("1234"), always(), eq(ActionType::AcceptBill), always())
7256+
.returning(|_, _, _, _| Ok(()));
72297257

72307258
let service = get_service_base(
72317259
storage,
@@ -7314,8 +7342,8 @@ pub mod tests {
73147342
let mut notification_service = MockNotificationServiceApi::new();
73157343
notification_service
73167344
.expect_send_request_to_action_rejected_event()
7317-
.with(eq("1234"), eq(ActionType::BuyBill), always())
7318-
.returning(|_, _, _| Ok(()));
7345+
.with(eq("1234"), always(), eq(ActionType::BuyBill), always())
7346+
.returning(|_, _, _, _| Ok(()));
73197347

73207348
let service = get_service_base(
73217349
storage,
@@ -7400,8 +7428,8 @@ pub mod tests {
74007428
let mut notification_service = MockNotificationServiceApi::new();
74017429
notification_service
74027430
.expect_send_request_to_action_rejected_event()
7403-
.with(eq("1234"), eq(ActionType::PayBill), always())
7404-
.returning(|_, _, _| Ok(()));
7431+
.with(eq("1234"), always(), eq(ActionType::PayBill), always())
7432+
.returning(|_, _, _, _| Ok(()));
74057433

74067434
let service = get_service_base(
74077435
storage,
@@ -7489,8 +7517,8 @@ pub mod tests {
74897517
let mut notification_service = MockNotificationServiceApi::new();
74907518
notification_service
74917519
.expect_send_request_to_action_rejected_event()
7492-
.with(eq("1234"), eq(ActionType::RecourseBill), always())
7493-
.returning(|_, _, _| Ok(()));
7520+
.with(eq("1234"), always(), eq(ActionType::RecourseBill), always())
7521+
.returning(|_, _, _, _| Ok(()));
74947522

74957523
let service = get_service_base(
74967524
storage,
@@ -7582,7 +7610,7 @@ pub mod tests {
75827610
let mut notification_service = MockNotificationServiceApi::new();
75837611
notification_service
75847612
.expect_send_bill_recourse_paid_event()
7585-
.returning(|_, _| Ok(()));
7613+
.returning(|_, _, _| Ok(()));
75867614

75877615
let service = get_service_base(
75887616
storage,
@@ -7677,7 +7705,7 @@ pub mod tests {
76777705
let mut notification_service = MockNotificationServiceApi::new();
76787706
notification_service
76797707
.expect_send_bill_recourse_paid_event()
7680-
.returning(|_, _| Ok(()));
7708+
.returning(|_, _, _| Ok(()));
76817709

76827710
let service = get_service_base(
76837711
storage,
@@ -7784,7 +7812,7 @@ pub mod tests {
77847812
// Request to recourse event should be sent
77857813
notification_service
77867814
.expect_send_recourse_action_event()
7787-
.returning(|_, _, _| Ok(()));
7815+
.returning(|_, _, _, _| Ok(()));
77887816

77897817
let service = get_service_base(
77907818
storage,
@@ -7904,7 +7932,7 @@ pub mod tests {
79047932
// Request to recourse event should be sent
79057933
notification_service
79067934
.expect_send_recourse_action_event()
7907-
.returning(|_, _, _| Ok(()));
7935+
.returning(|_, _, _, _| Ok(()));
79087936

79097937
let service = get_service_base(
79107938
storage,
@@ -7996,7 +8024,7 @@ pub mod tests {
79968024
// Recourse paid event should be sent
79978025
notification_service
79988026
.expect_send_bill_recourse_paid_event()
7999-
.returning(|_, _| Ok(()));
8027+
.returning(|_, _, _| Ok(()));
80008028

80018029
let service = get_service_base(
80028030
storage,

0 commit comments

Comments
 (0)