Skip to content

Commit 35b15d7

Browse files
authored
add verify signer baseline, fix payment deadline, add tests for verify (#459)
signer, add logic and tests to chain event handler
1 parent 033996f commit 35b15d7

File tree

11 files changed

+1276
-111
lines changed

11 files changed

+1276
-111
lines changed

crates/bcr-ebill-api/src/service/bill_service/data_fetching.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::util;
22

33
use super::service::BillService;
44
use super::{Error, Result};
5+
use bcr_ebill_core::bill::validation::get_deadline_base_for_req_to_pay;
56
use bcr_ebill_core::constants::RECOURSE_DEADLINE_SECONDS;
67
use bcr_ebill_core::contact::Contact;
78
use bcr_ebill_core::{
@@ -236,10 +237,12 @@ impl BillService {
236237
if chain.block_with_operation_code_exists(BillOpCode::RejectToPay) {
237238
rejected_to_pay = true;
238239
}
240+
let deadline_base =
241+
get_deadline_base_for_req_to_pay(req_to_pay_block.timestamp, &bill.maturity_date)?;
239242
if !paid
240243
&& !rejected_to_pay
241244
&& util::date::check_if_deadline_has_passed(
242-
req_to_pay_block.timestamp,
245+
deadline_base,
243246
current_timestamp,
244247
PAYMENT_DEADLINE_SECONDS,
245248
)
@@ -409,14 +412,8 @@ impl BillService {
409412
if paid {
410413
// it's paid - we're not waiting anymore
411414
None
412-
} else if util::date::check_if_deadline_has_passed(
413-
last_block.timestamp,
414-
current_timestamp,
415-
PAYMENT_DEADLINE_SECONDS,
416-
) {
415+
} else if request_to_pay_timed_out {
417416
// it timed out, we're not waiting anymore
418-
request_to_pay_timed_out = true;
419-
requested_to_pay = true;
420417
None
421418
} else {
422419
// we're waiting, collect data
@@ -579,7 +576,7 @@ impl BillService {
579576
&self,
580577
bill: &BitcreditBillResult,
581578
current_timestamp: u64,
582-
) -> bool {
579+
) -> Result<bool> {
583580
let mut invalidate_and_recalculate = false;
584581
let acceptance = &bill.status.acceptance;
585582
if acceptance.requested_to_accept && !acceptance.accepted && !acceptance.rejected_to_accept
@@ -598,8 +595,12 @@ impl BillService {
598595
let payment = &bill.status.payment;
599596
if payment.requested_to_pay && !payment.paid && !payment.rejected_to_pay {
600597
if let Some(time_of_request_to_pay) = payment.time_of_request_to_pay {
601-
if util::date::check_if_deadline_has_passed(
598+
let deadline_base = get_deadline_base_for_req_to_pay(
602599
time_of_request_to_pay,
600+
&bill.data.maturity_date,
601+
)?;
602+
if util::date::check_if_deadline_has_passed(
603+
deadline_base,
603604
current_timestamp,
604605
PAYMENT_DEADLINE_SECONDS,
605606
) {
@@ -638,7 +639,7 @@ impl BillService {
638639
}
639640
}
640641
}
641-
invalidate_and_recalculate
642+
Ok(invalidate_and_recalculate)
642643
}
643644

644645
pub(super) async fn extend_bill_identities_from_contacts_or_identity(
@@ -787,7 +788,7 @@ impl BillService {
787788

788789
// check requests for being expired - if an active req to
789790
// accept/pay/recourse/sell is expired, we need to recalculate the bill
790-
if self.check_requests_for_expiration(&bill, current_timestamp) {
791+
if self.check_requests_for_expiration(&bill, current_timestamp)? {
791792
debug!(
792793
"Bill cache hit, but needs to recalculate because of request deadline {bill_id} - recalculating"
793794
);

0 commit comments

Comments
 (0)