Skip to content

Commit bc540e2

Browse files
authored
Fix reject to accept state without req to accept (#480)
1 parent c43d734 commit bc540e2

File tree

11 files changed

+37
-5
lines changed

11 files changed

+37
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* Add validation for maturity date
44
* Add docs for testing
5+
* Fix reject to accept not showing correctly without req to accept
6+
* Add endpoint `clear_bill_cache` to clear the bill cache
57

68
# 0.3.5
79

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ impl BillService {
151151
requested_to_pay = true;
152152
time_of_request_to_pay = Some(req_to_pay_block.timestamp);
153153
paid = self.store.is_paid(&bill.id).await?;
154-
if chain.block_with_operation_code_exists(BillOpCode::RejectToPay) {
155-
rejected_to_pay = true;
156-
}
154+
rejected_to_pay = chain.block_with_operation_code_exists(BillOpCode::RejectToPay);
157155
let deadline_base =
158156
get_deadline_base_for_req_to_pay(req_to_pay_block.timestamp, &bill.maturity_date)?;
159157
if !paid
@@ -252,7 +250,7 @@ impl BillService {
252250
}
253251

254252
let mut request_to_accept_timed_out = false;
255-
let mut rejected_to_accept = false;
253+
let rejected_to_accept = chain.block_with_operation_code_exists(BillOpCode::RejectToAccept);
256254
let accepted = chain.block_with_operation_code_exists(BillOpCode::Accept);
257255
let mut time_of_request_to_accept = None;
258256
let mut requested_to_accept = false;
@@ -261,7 +259,6 @@ impl BillService {
261259
{
262260
requested_to_accept = true;
263261
time_of_request_to_accept = Some(req_to_accept_block.timestamp);
264-
rejected_to_accept = chain.block_with_operation_code_exists(BillOpCode::RejectToAccept);
265262

266263
if !accepted
267264
&& !rejected_to_accept

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ pub trait BillServiceApi: ServiceTraitBounds {
148148
bill_id: &str,
149149
current_identity_node_id: &str,
150150
) -> Result<Vec<Endorsement>>;
151+
152+
async fn clear_bill_cache(&self) -> Result<()>;
151153
}
152154

153155
#[cfg(test)]

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,4 +883,9 @@ impl BillServiceApi for BillService {
883883

884884
Ok(result)
885885
}
886+
887+
async fn clear_bill_cache(&self) -> Result<()> {
888+
self.store.clear_bill_cache().await?;
889+
Ok(())
890+
}
886891
}

crates/bcr-ebill-api/src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub mod tests {
6666
async fn get_bill_from_cache(&self, id: &str) -> Result<Option<BitcreditBillResult>>;
6767
async fn save_bill_to_cache(&self, id: &str, bill: &BitcreditBillResult) -> Result<()>;
6868
async fn invalidate_bill_in_cache(&self, id: &str) -> Result<()>;
69+
async fn clear_bill_cache(&self) -> Result<()>;
6970
async fn exists(&self, id: &str) -> bool;
7071
async fn get_ids(&self) -> Result<Vec<String>>;
7172
async fn save_keys(&self, id: &str, keys: &BillKeys) -> Result<()>;

crates/bcr-ebill-persistence/src/bill.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub trait BillStoreApi: Send + Sync {
1919
async fn save_bill_to_cache(&self, id: &str, bill: &BitcreditBillResult) -> Result<()>;
2020
/// Invalidates the cached bill
2121
async fn invalidate_bill_in_cache(&self, id: &str) -> Result<()>;
22+
/// clear the bill cache
23+
async fn clear_bill_cache(&self) -> Result<()>;
2224
/// Checks if the given bill exists
2325
async fn exists(&self, id: &str) -> bool;
2426
/// Gets all bill ids

crates/bcr-ebill-persistence/src/db/bill.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ impl BillStoreApi for SurrealBillStore {
9090
Ok(())
9191
}
9292

93+
async fn clear_bill_cache(&self) -> Result<()> {
94+
let _: Vec<BitcreditBillResultDb> = self.db().await?.delete(Self::CACHE_TABLE).await?;
95+
Ok(())
96+
}
97+
9398
async fn exists(&self, id: &str) -> bool {
9499
let db_con = match self.db().await {
95100
Ok(con) => con,

crates/bcr-ebill-transport/src/handler/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ mod test_utils {
236236
async fn get_bill_from_cache(&self, id: &str) -> Result<Option<BitcreditBillResult>>;
237237
async fn save_bill_to_cache(&self, id: &str, bill: &BitcreditBillResult) -> Result<()>;
238238
async fn invalidate_bill_in_cache(&self, id: &str) -> Result<()>;
239+
async fn clear_bill_cache(&self) -> Result<()>;
239240
async fn exists(&self, id: &str) -> bool;
240241
async fn get_ids(&self) -> Result<Vec<String>>;
241242
async fn save_keys(&self, id: &str, keys: &BillKeys) -> Result<()>;

crates/bcr-ebill-wasm/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ <h2>Company Testing</h2>
4545
<div>
4646
<h2>Bill Testing</h2>
4747
<div>
48+
<button type="button" id="clear_bill_cache">Clear Bill Cache</button>
49+
<br />
50+
<br />
4851
Contact Id: <input type="text" id="node_id_bill"/>
4952
<button type="button" id="contact_test">Create Contact for node id</button>
5053
<button type="button" id="bill_test">Create bill with contact for node id</button>

crates/bcr-ebill-wasm/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ document.getElementById("reject_pay").addEventListener("click", rejectPayBill);
2525
document.getElementById("reject_buying").addEventListener("click", rejectBuyingBill);
2626
document.getElementById("reject_recourse").addEventListener("click", rejectRecourseBill);
2727
document.getElementById("bill_test").addEventListener("click", triggerBill);
28+
document.getElementById("clear_bill_cache").addEventListener("click", clearBillCache);
2829

2930
async function start() {
3031
let config = {
@@ -410,6 +411,13 @@ async function fetchBillSearch() {
410411
await measured();
411412
}
412413

414+
async function clearBillCache() {
415+
let measured = measure(async () => {
416+
return await billApi.clear_bill_cache();
417+
});
418+
await measured();
419+
}
420+
413421
function measure(promiseFunction) {
414422
return async function (...args) {
415423
const startTime = performance.now();

0 commit comments

Comments
 (0)