Skip to content

Commit e9122cf

Browse files
authored
next version, update changelog, fix clippy, expose error,add debug logs, rename upload files function (#454)
1 parent 12b1518 commit e9122cf

File tree

39 files changed

+419
-161
lines changed

39 files changed

+419
-161
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# 0.3.2
22

33
* Fixed `request_to_accept` calling the correct action
4+
* Multi-identity Nostr consumer and currently-active-identity-sending
5+
* Added more thorough logging, especially debug logging
6+
* Expose Error types to TS
7+
* Use string for `log_level` in config
48

59
# 0.3.1
610

crates/bcr-ebill-api/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bcr-ebill-api"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
edition = "2024"
55

66
[lib]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ pub use bcr_ebill_core::GeneralSearchFilterItemType;
99
pub use bcr_ebill_core::GeneralSearchResult;
1010
pub use bcr_ebill_core::OptionalPostalAddress;
1111
pub use bcr_ebill_core::PostalAddress;
12-
pub use bcr_ebill_core::UploadFilesResult;
12+
pub use bcr_ebill_core::UploadFileResult;

crates/bcr-ebill-api/src/external/bitcoin.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{get_config, util};
22
use async_trait::async_trait;
33
use bcr_ebill_core::ServiceTraitBounds;
44
use bitcoin::{Network, secp256k1::Scalar};
5+
use log::debug;
56
use serde::Deserialize;
67
use std::str::FromStr;
78
use thiserror::Error;
@@ -144,6 +145,7 @@ impl BitcoinClientApi for BitcoinClient {
144145
}
145146

146147
async fn check_if_paid(&self, address: &str, sum: u64) -> Result<(bool, u64)> {
148+
debug!("checking if btc address {address} is paid {sum}");
147149
let info_about_address = self.get_address_info(address).await?;
148150

149151
// the received and spent sum need to add up to the sum

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use bcr_ebill_core::{
1111
util::BcrKeys,
1212
};
1313
use bcr_ebill_transport::BillChainEvent;
14-
use log::error;
14+
use log::{debug, error};
1515

1616
impl BillService {
1717
#[allow(clippy::too_many_arguments)]
@@ -34,6 +34,7 @@ impl BillService {
3434
drawer_keys: BcrKeys,
3535
timestamp: u64,
3636
) -> Result<BitcreditBill> {
37+
debug!("issuing bill with type {t}");
3738
let (sum, bill_type) = self.validate_bill_issue(
3839
&sum,
3940
&file_upload_ids,
@@ -98,6 +99,7 @@ impl BillService {
9899
(public_data_drawee, public_data_payee)
99100
}
100101
};
102+
debug!("issuing bill with drawee {public_data_drawee:?} and payee {public_data_payee:?}");
101103

102104
let identity = self.identity_store.get_full().await?;
103105
let keys = BcrKeys::new();
@@ -204,8 +206,11 @@ impl BillService {
204206
error!("Error propagating bill via Nostr {e}");
205207
}
206208

209+
debug!("issued bill with id {bill_id}");
210+
207211
// If we're the drawee, we immediately accept the bill with timestamp increased by 1 sec
208212
if bill.drawer == bill.drawee {
213+
debug!("we are drawer and drawee of bill: {bill_id} - immediately accepting");
209214
self.execute_bill_action(
210215
&bill_id,
211216
BillAction::Accept,

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bcr_ebill_core::{
88
identity::{Identity, IdentityWithAll},
99
util::BcrKeys,
1010
};
11-
use log::info;
11+
use log::{debug, info};
1212
use std::collections::HashMap;
1313

1414
impl BillService {
@@ -38,6 +38,7 @@ impl BillService {
3838
.await
3939
{
4040
if paid && sum > 0 {
41+
debug!("bill {bill_id} is paid - setting to paid and invalidating cache");
4142
self.store.set_to_paid(bill_id, &address_to_pay).await?;
4243
// invalidate bill cache, so payment state is updated on next fetch
4344
self.store.invalidate_bill_in_cache(bill_id).await?;
@@ -70,6 +71,9 @@ impl BillService {
7071
.await
7172
{
7273
if paid && sum > 0 {
74+
debug!(
75+
"bill {bill_id} is recourse-paid - creating recourse block if we're recourser"
76+
);
7377
// If we are the recourser and a bill issuer and it's paid, we add a Recourse block
7478
if payment_info.recourser.node_id == identity.identity.node_id {
7579
if let Some(signer_identity) =
@@ -150,6 +154,7 @@ impl BillService {
150154
.await
151155
{
152156
if paid && sum > 0 {
157+
debug!("bill {bill_id} got bought - creating sell block if we're seller");
153158
// If we are the seller and a bill issuer and it's paid, we add a Sell block
154159
if payment_info.seller.node_id == identity.identity.node_id {
155160
if let Some(signer_identity) =

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ impl BillServiceApi for BillService {
264264
role: &BillsFilterRole,
265265
current_identity_node_id: &str,
266266
) -> Result<Vec<LightBitcreditBillResult>> {
267+
debug!(
268+
"searching bills with {search_term:?} from {date_range_from:?} to {date_range_to:?} and {role:?}"
269+
);
267270
let bills = self.get_bills(current_identity_node_id).await?;
268271
let mut result = vec![];
269272

@@ -361,6 +364,7 @@ impl BillServiceApi for BillService {
361364
for bill_id in bill_ids.iter() {
362365
// if bill was not in cache - recalculate and cache it
363366
if !bills.iter().any(|bill| *bill_id == bill.id) {
367+
debug!("Bill {bill_id} was not in the cache - recalculate");
364368
let calculated_bill = self
365369
.recalculate_and_cache_bill(
366370
bill_id,
@@ -409,6 +413,7 @@ impl BillServiceApi for BillService {
409413
.iter()
410414
.any(|p| p == &caller_public_data.node_id)
411415
{
416+
debug!("caller is not a participant of bill {bill_id}");
412417
return Err(Error::NotFound);
413418
}
414419

@@ -462,6 +467,7 @@ impl BillServiceApi for BillService {
462467
file_name: &str,
463468
bill_private_key: &str,
464469
) -> Result<Vec<u8>> {
470+
debug!("getting file {file_name} for bill with id: {bill_id}");
465471
let read_file = self
466472
.file_upload_store
467473
.open_attached_file(bill_id, file_name)
@@ -537,6 +543,10 @@ impl BillServiceApi for BillService {
537543
signer_keys: &BcrKeys,
538544
timestamp: u64,
539545
) -> Result<BillBlockchain> {
546+
debug!(
547+
"Executing bill action {:?} for bill {bill_id}",
548+
&bill_action
549+
);
540550
// fetch data
541551
let identity = self.identity_store.get_full().await?;
542552
let contacts = self.contact_store.get_map().await?;
@@ -591,6 +601,8 @@ impl BillServiceApi for BillService {
591601
)
592602
.await?;
593603

604+
debug!("Executed bill action {:?} for bill {bill_id}", &bill_action);
605+
594606
Ok(blockchain)
595607
}
596608

@@ -682,6 +694,7 @@ impl BillServiceApi for BillService {
682694
.iter()
683695
.any(|p| p == current_identity_node_id)
684696
{
697+
debug!("caller is not a participant of bill {bill_id}");
685698
return Err(Error::NotFound);
686699
}
687700

@@ -706,6 +719,7 @@ impl BillServiceApi for BillService {
706719
.iter()
707720
.any(|p| p == current_identity_node_id)
708721
{
722+
debug!("caller is not a participant of bill {bill_id}");
709723
return Err(Error::NotFound);
710724
}
711725

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
util,
2424
};
2525
use async_trait::async_trait;
26-
use log::{error, info};
26+
use log::{debug, error, info};
2727
use std::sync::Arc;
2828

2929
#[async_trait]
@@ -145,6 +145,7 @@ impl CompanyService {
145145
public_key: &str,
146146
) -> Result<Option<File>> {
147147
if let Some(upload_id) = upload_id {
148+
debug!("processing upload file for company {id}: {upload_id:?}");
148149
let (file_name, file_bytes) = &self
149150
.file_upload_store
150151
.read_temp_upload_file(upload_id)
@@ -218,6 +219,7 @@ impl CompanyServiceApi for CompanyService {
218219
logo_file_upload_id: Option<String>,
219220
timestamp: u64,
220221
) -> Result<Company> {
222+
debug!("creating company");
221223
let keys = BcrKeys::new();
222224
let private_key = keys.get_private_key_string();
223225
let public_key = keys.get_public_key();
@@ -287,6 +289,7 @@ impl CompanyServiceApi for CompanyService {
287289
.add_block(&id, create_company_block)
288290
.await?;
289291
self.identity_blockchain_store.add_block(&new_block).await?;
292+
debug!("company with id {id} created");
290293

291294
// TODO NOSTR: create company topic and subscribe to it
292295
// TODO NOSTR: upload files to nostr
@@ -322,7 +325,9 @@ impl CompanyServiceApi for CompanyService {
322325
proof_of_registration_file_upload_id: Option<String>,
323326
timestamp: u64,
324327
) -> Result<()> {
328+
debug!("editing company with id: {id}");
325329
if !self.store.exists(id).await {
330+
debug!("company with id {id} does not exist");
326331
return Err(super::Error::NotFound);
327332
}
328333
let full_identity = self.identity_store.get_full().await?;
@@ -446,6 +451,7 @@ impl CompanyServiceApi for CompanyService {
446451
self.company_blockchain_store
447452
.add_block(id, &new_block)
448453
.await?;
454+
debug!("company with id {id} updated");
449455

450456
if let Some(upload_id) = logo_file_upload_id {
451457
if let Err(e) = self
@@ -466,6 +472,10 @@ impl CompanyServiceApi for CompanyService {
466472
signatory_node_id: String,
467473
timestamp: u64,
468474
) -> Result<()> {
475+
debug!(
476+
"adding signatory {} to company with id: {id}",
477+
&signatory_node_id
478+
);
469479
if !self.store.exists(id).await {
470480
return Err(super::Error::Validation(format!(
471481
"No company with id: {id} found.",
@@ -513,7 +523,7 @@ impl CompanyServiceApi for CompanyService {
513523
company_id: id.to_owned(),
514524
block_hash: new_block.hash.clone(),
515525
block_id: new_block.id,
516-
signatory: signatory_node_id,
526+
signatory: signatory_node_id.clone(),
517527
},
518528
&full_identity.key_pair,
519529
timestamp,
@@ -524,6 +534,10 @@ impl CompanyServiceApi for CompanyService {
524534
self.identity_blockchain_store
525535
.add_block(&new_identity_block)
526536
.await?;
537+
debug!(
538+
"added signatory {} to company with id: {id}",
539+
&signatory_node_id
540+
);
527541

528542
// TODO NOSTR: propagate block to company topic
529543
// TODO NOSTR: propagate company and files to new signatory
@@ -537,6 +551,10 @@ impl CompanyServiceApi for CompanyService {
537551
signatory_node_id: String,
538552
timestamp: u64,
539553
) -> Result<()> {
554+
debug!(
555+
"removing signatory {} from company with id: {id}",
556+
&signatory_node_id
557+
);
540558
if !self.store.exists(id).await {
541559
return Err(super::Error::Validation(format!(
542560
"No company with id: {id} found.",
@@ -607,6 +625,10 @@ impl CompanyServiceApi for CompanyService {
607625
error!("Could not delete local company chain for {id}: {e}");
608626
}
609627
}
628+
debug!(
629+
"removed signatory {} to company with id: {id}",
630+
&signatory_node_id
631+
);
610632

611633
Ok(())
612634
}
@@ -636,6 +658,7 @@ impl CompanyServiceApi for CompanyService {
636658
file_name: &str,
637659
private_key: &str,
638660
) -> Result<Vec<u8>> {
661+
debug!("getting file {file_name} for company with id: {id}",);
639662
let read_file = self
640663
.file_upload_store
641664
.open_attached_file(id, file_name)

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
};
1818

1919
use super::Result;
20-
use log::info;
20+
use log::{debug, info};
2121

2222
#[cfg_attr(test, automock)]
2323
#[async_trait]
@@ -108,6 +108,7 @@ impl ContactService {
108108
public_key: &str,
109109
) -> Result<Option<File>> {
110110
if let Some(upload_id) = upload_id {
111+
debug!("processing upload file for contact {id}: {upload_id:?}");
111112
let (file_name, file_bytes) = &self
112113
.file_upload_store
113114
.read_temp_upload_file(upload_id)
@@ -185,6 +186,7 @@ impl ContactServiceApi for ContactService {
185186
avatar_file_upload_id: Option<String>,
186187
proof_document_file_upload_id: Option<String>,
187188
) -> Result<()> {
189+
debug!("updating contact with node_id: {node_id}");
188190
let mut contact = match self.store.get(node_id).await? {
189191
Some(contact) => contact,
190192
None => {
@@ -274,6 +276,7 @@ impl ContactServiceApi for ContactService {
274276
}
275277

276278
self.store.update(node_id, contact).await?;
279+
debug!("updated contact with node_id: {node_id}");
277280

278281
Ok(())
279282
}
@@ -292,6 +295,7 @@ impl ContactServiceApi for ContactService {
292295
avatar_file_upload_id: Option<String>,
293296
proof_document_file_upload_id: Option<String>,
294297
) -> Result<Contact> {
298+
debug!("creating {:?} contact with node_id {node_id}", &t);
295299
if util::crypto::validate_pub_key(node_id).is_err() {
296300
return Err(super::Error::Validation(format!(
297301
"Not a valid secp256k1 key: {node_id}",
@@ -313,7 +317,7 @@ impl ContactServiceApi for ContactService {
313317

314318
let contact = Contact {
315319
node_id: node_id.to_owned(),
316-
t,
320+
t: t.clone(),
317321
name,
318322
email,
319323
postal_address,
@@ -327,6 +331,7 @@ impl ContactServiceApi for ContactService {
327331
};
328332

329333
self.store.insert(node_id, contact.clone()).await?;
334+
debug!("contact {:?} with node_id {node_id} created", &t);
330335
Ok(contact)
331336
}
332337

@@ -343,6 +348,7 @@ impl ContactServiceApi for ContactService {
343348
file_name: &str,
344349
private_key: &str,
345350
) -> Result<Vec<u8>> {
351+
debug!("getting file {file_name} for contact with id: {id}",);
346352
let read_file = self
347353
.file_upload_store
348354
.open_attached_file(id, file_name)

0 commit comments

Comments
 (0)