Skip to content

Commit 1f0a757

Browse files
authored
Add IdentityType to blocks, Remove empty validations, Add validation for (#718)
Identity Blocks, remove BackupService, remove File Based File Storage, Move Bill Tests, Remove Cross-Crate-Re-Exports
1 parent 63d2f1b commit 1f0a757

File tree

127 files changed

+8088
-8971
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+8088
-8971
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
* Add strong types for `SchnorrSignature`, `Sha256Hash`, `BlockId`, `File` types, `Mint` types and use `PublicKey` and `SecretKey` in protocol types (breaking DB change)
88
* Use bytes without encoding for bill data (breaking DB change)
99
* Fix plaintext-chain rendering - the nesting of `data` now works properly and one `JSON.parse` call is enough (breaking API change)
10+
* Add `IdentityType` to `IdentityCreateBlockData` and `IdentityUpdateBlockData`
11+
* Remove `BackupService` and `BackupStore` since it's unused
12+
* Remove file-based `FileUpload` - we use surreal/nostr-based everywhere
13+
* Refactoring & Restructuring, removing cross-crate exports (breaking for Library dependents)
1014

1115
# 0.4.12
1216

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bcr-ebill-core = { path = "./crates/bcr-ebill-core" }
6262
bcr-ebill-api = { path = "./crates/bcr-ebill-api" }
6363
bcr-ebill-persistence = { path = "./crates/bcr-ebill-persistence" }
6464
bcr-ebill-transport = { path = "./crates/bcr-ebill-transport" }
65-
bcr-common = { git = "https://github.com/BitcreditProtocol/bcr-common", tag = "v0.5.0" }
65+
bcr-common = { git = "https://github.com/BitcreditProtocol/bcr-common", tag = "v0.6.0" }
6666
surrealdb = { version = "2.3", default-features = false }
6767
strum = { version = "0.27", features = ["derive"] }
6868
url = { version = "2.5" }

crates/bcr-ebill-api/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ futures.workspace = true
2626
infer = { version = "0.19.0", default-features = false }
2727
bcr-ebill-core.workspace = true
2828
bcr-ebill-persistence.workspace = true
29+
bcr-common.workspace = true
2930
tokio.workspace = true
3031
tokio_with_wasm.workspace = true
3132
secp256k1.workspace = true
3233
bcr-wallet-lib = { git = "https://github.com/BitcreditProtocol/Wallet-Core", tag = "v0.6.0" }
33-
bcr-common.workspace = true
3434
cashu = { version = "0.13", default-features = false }
3535
rand = { version = "0.9" }
3636
strum.workspace = true

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

Lines changed: 0 additions & 7 deletions
This file was deleted.

crates/bcr-ebill-api/src/constants.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ pub const VALID_FILE_MIME_TYPES: [&str; 3] = ["image/jpeg", "image/png", "applic
88
// When subscribing events we subtract this from the last received event time
99
pub const NOSTR_EVENT_TIME_SLACK: u64 = 3600 * 24 * 7; // 1 week
1010
pub const DEFAULT_INITIAL_SUBSCRIPTION_DELAY_SECONDS: u32 = 1;
11-
pub use bcr_ebill_core::constants::CURRENCY_SAT;

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

Lines changed: 0 additions & 54 deletions
This file was deleted.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use async_trait::async_trait;
2+
use bcr_common::core::{BillId, NodeId};
23
use bcr_ebill_core::email::Email;
3-
use bcr_ebill_core::{NodeId, ServiceTraitBounds, bill::BillId, notification::BillEventType};
4+
use bcr_ebill_core::{ServiceTraitBounds, notification::BillEventType};
45
use borsh_derive::BorshSerialize;
56
use nostr::hashes::Hash;
67
use nostr::util::SECP256K1;

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use async_trait::async_trait;
22
use bcr_ebill_core::{
3-
ServiceTraitBounds,
3+
ServiceTraitBounds, ValidationError,
44
identity_proof::{IdentityProofStamp, IdentityProofStatus},
5+
util::crypto,
56
};
67
use borsh_derive::BorshSerialize;
78
use log::error;
@@ -15,7 +16,7 @@ use url::Url;
1516
#[cfg(test)]
1617
use mockall::automock;
1718

18-
use crate::{external::file_storage::to_url, util};
19+
use crate::external::file_storage::to_url;
1920

2021
/// Generic result type
2122
pub type Result<T> = std::result::Result<T, super::Error>;
@@ -31,10 +32,10 @@ pub enum Error {
3132
Api(#[from] reqwest::Error),
3233
/// all errors originating from interacting with cryptography
3334
#[error("External Identity Proof Crypto error: {0}")]
34-
Crypto(#[from] util::crypto::Error),
35+
Crypto(#[from] crypto::Error),
3536
/// all errors originating from interacting with base58
3637
#[error("External Identity Proof Validation error: {0}")]
37-
Validation(#[from] util::ValidationError),
38+
Validation(#[from] ValidationError),
3839
/// all nostr key errors
3940
#[error("External Identity Proof Nostr Key Error")]
4041
NostrKey,

crates/bcr-ebill-api/src/lib.rs

Lines changed: 125 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
11
use anyhow::{Result, anyhow};
2-
use bcr_ebill_core::NodeId;
2+
use bcr_common::core::NodeId;
3+
use bcr_ebill_persistence::db::surreal::SurrealWrapper;
4+
#[cfg(not(target_arch = "wasm32"))]
5+
use bcr_ebill_persistence::get_surreal_db;
6+
use bcr_ebill_persistence::{
7+
ContactStoreApi, NostrChainEventStoreApi, NostrEventOffsetStoreApi, NotificationStoreApi,
8+
SurrealBillChainStore, SurrealBillStore, SurrealCompanyChainStore, SurrealCompanyStore,
9+
SurrealContactStore, SurrealDbConfig, SurrealIdentityChainStore, SurrealIdentityStore,
10+
SurrealNostrChainEventStore, SurrealNostrEventOffsetStore, SurrealNotificationStore,
11+
bill::{BillChainStoreApi, BillStoreApi},
12+
company::{CompanyChainStoreApi, CompanyStoreApi},
13+
db::{
14+
email_notification::SurrealEmailNotificationStore,
15+
identity_proof::SurrealIdentityProofStore, mint::SurrealMintStore,
16+
nostr_contact_store::SurrealNostrContactStore,
17+
nostr_send_queue::SurrealNostrEventQueueStore,
18+
},
19+
file_upload::FileUploadStoreApi,
20+
identity::{IdentityChainStoreApi, IdentityStoreApi},
21+
identity_proof::IdentityProofStoreApi,
22+
mint::MintStoreApi,
23+
nostr::{NostrContactStoreApi, NostrQueuedMessageStoreApi},
24+
notification::EmailNotificationStoreApi,
25+
};
326
use bitcoin::Network;
4-
use std::sync::OnceLock;
27+
use log::error;
28+
use std::sync::{Arc, OnceLock};
529

6-
mod blockchain;
730
pub mod constants;
8-
pub mod data;
931
pub mod external;
10-
pub mod persistence;
1132
pub mod service;
1233
#[cfg(test)]
1334
mod tests;
1435
pub mod util;
1536

16-
pub use blockchain::Block;
17-
pub use blockchain::Blockchain;
18-
pub use blockchain::bill::BillOpCode;
19-
pub use persistence::DbContext;
20-
pub use persistence::Error as PersistenceError;
21-
pub use persistence::db::SurrealDbConfig;
22-
pub use persistence::get_db_context;
23-
pub use persistence::notification::NotificationFilter;
24-
2537
#[derive(Debug, Clone)]
2638
pub struct Config {
2739
pub app_url: url::Url,
2840
pub bitcoin_network: String,
2941
pub esplora_base_url: url::Url,
3042
pub db_config: SurrealDbConfig,
31-
pub data_dir: String,
43+
pub files_db_config: SurrealDbConfig,
3244
pub nostr_config: NostrConfig,
3345
pub mint_config: MintConfig,
3446
pub payment_config: PaymentConfig,
@@ -110,3 +122,101 @@ pub fn init(conf: Config) -> Result<()> {
110122
pub fn get_config() -> &'static Config {
111123
CONFIG.get().expect("E-Bill API is not initialized")
112124
}
125+
126+
/// A container for all persistence related dependencies.
127+
#[derive(Clone)]
128+
pub struct DbContext {
129+
pub contact_store: Arc<dyn ContactStoreApi>,
130+
pub bill_store: Arc<dyn BillStoreApi>,
131+
pub bill_blockchain_store: Arc<dyn BillChainStoreApi>,
132+
pub identity_store: Arc<dyn IdentityStoreApi>,
133+
pub identity_chain_store: Arc<dyn IdentityChainStoreApi>,
134+
pub company_chain_store: Arc<dyn CompanyChainStoreApi>,
135+
pub company_store: Arc<dyn CompanyStoreApi>,
136+
pub file_upload_store: Arc<dyn FileUploadStoreApi>,
137+
pub nostr_event_offset_store: Arc<dyn NostrEventOffsetStoreApi>,
138+
pub notification_store: Arc<dyn NotificationStoreApi>,
139+
pub email_notification_store: Arc<dyn EmailNotificationStoreApi>,
140+
pub queued_message_store: Arc<dyn NostrQueuedMessageStoreApi>,
141+
pub nostr_contact_store: Arc<dyn NostrContactStoreApi>,
142+
pub mint_store: Arc<dyn MintStoreApi>,
143+
pub nostr_chain_event_store: Arc<dyn NostrChainEventStoreApi>,
144+
pub identity_proof_store: Arc<dyn IdentityProofStoreApi>,
145+
}
146+
147+
/// Creates a new instance of the DbContext with the given SurrealDB configuration.
148+
pub async fn get_db_context(
149+
#[allow(unused)] conf: &Config,
150+
) -> bcr_ebill_persistence::Result<DbContext> {
151+
#[cfg(not(target_arch = "wasm32"))]
152+
let db = get_surreal_db(&conf.db_config).await?;
153+
#[cfg(not(target_arch = "wasm32"))]
154+
let files_db = get_surreal_db(&conf.files_db_config).await?;
155+
#[cfg(not(target_arch = "wasm32"))]
156+
let surreal_wrapper = SurrealWrapper {
157+
db: db.clone(),
158+
files: false,
159+
};
160+
161+
#[cfg(not(target_arch = "wasm32"))]
162+
let files_surreal_wrapper = SurrealWrapper {
163+
db: files_db.clone(),
164+
files: true,
165+
};
166+
167+
#[cfg(target_arch = "wasm32")]
168+
let surreal_wrapper = SurrealWrapper { files: false };
169+
170+
#[cfg(target_arch = "wasm32")]
171+
let files_surreal_wrapper = SurrealWrapper { files: true };
172+
173+
let company_store = Arc::new(SurrealCompanyStore::new(surreal_wrapper.clone()));
174+
let file_upload_store = Arc::new(
175+
bcr_ebill_persistence::db::file_upload::FileUploadStore::new(files_surreal_wrapper),
176+
);
177+
178+
if let Err(e) = file_upload_store.cleanup_temp_uploads().await {
179+
error!("Error cleaning up temp uploads: {e}");
180+
}
181+
182+
let contact_store = Arc::new(SurrealContactStore::new(surreal_wrapper.clone()));
183+
184+
let bill_store = Arc::new(SurrealBillStore::new(surreal_wrapper.clone()));
185+
let bill_blockchain_store = Arc::new(SurrealBillChainStore::new(surreal_wrapper.clone()));
186+
187+
let identity_store = Arc::new(SurrealIdentityStore::new(surreal_wrapper.clone()));
188+
let identity_chain_store = Arc::new(SurrealIdentityChainStore::new(surreal_wrapper.clone()));
189+
let identity_proof_store = Arc::new(SurrealIdentityProofStore::new(surreal_wrapper.clone()));
190+
let company_chain_store = Arc::new(SurrealCompanyChainStore::new(surreal_wrapper.clone()));
191+
192+
let nostr_event_offset_store =
193+
Arc::new(SurrealNostrEventOffsetStore::new(surreal_wrapper.clone()));
194+
let notification_store = Arc::new(SurrealNotificationStore::new(surreal_wrapper.clone()));
195+
let email_notification_store =
196+
Arc::new(SurrealEmailNotificationStore::new(surreal_wrapper.clone()));
197+
198+
let queued_message_store = Arc::new(SurrealNostrEventQueueStore::new(surreal_wrapper.clone()));
199+
let nostr_contact_store = Arc::new(SurrealNostrContactStore::new(surreal_wrapper.clone()));
200+
let mint_store = Arc::new(SurrealMintStore::new(surreal_wrapper.clone()));
201+
let nostr_chain_event_store =
202+
Arc::new(SurrealNostrChainEventStore::new(surreal_wrapper.clone()));
203+
204+
Ok(DbContext {
205+
contact_store,
206+
bill_store,
207+
bill_blockchain_store,
208+
identity_store,
209+
identity_chain_store,
210+
company_chain_store,
211+
company_store,
212+
file_upload_store,
213+
nostr_event_offset_store,
214+
notification_store,
215+
email_notification_store,
216+
queued_message_store,
217+
nostr_contact_store,
218+
mint_store,
219+
nostr_chain_event_store,
220+
identity_proof_store,
221+
})
222+
}

0 commit comments

Comments
 (0)