Skip to content

Commit 923a47e

Browse files
authored
Introduce bcr-common (#668)
1 parent fff5c0d commit 923a47e

File tree

24 files changed

+167
-487
lines changed

24 files changed

+167
-487
lines changed

.github/workflows/rust.yml

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,34 @@ jobs:
4848
run: rustup default stable
4949

5050
- name: Update rust
51-
run: rustup update
51+
run: rustup update stable
5252

53-
- name: Cargo update
54-
run: cargo update --verbose
53+
- name: Add rustup components
54+
run: rustup component add clippy rustfmt
5555

56-
- name: Check
57-
run: cargo check --verbose
56+
- name: Activate cache
57+
uses: Swatinem/[email protected]
58+
with:
59+
prefix-key: "ebill-01"
5860

59-
- name: Add fmt
60-
run: rustup component add rustfmt
61+
- name: Install required cargo tools
62+
run: cargo install cargo-deny clippy-sarif sarif-fmt
6163

62-
- name: Add cargo deny
63-
run: cargo install cargo-deny
64+
- name: Check
65+
run: cargo check
6466

6567
- name: Check formatting
6668
run: cargo fmt -- --check
6769

68-
- name: Test
69-
run: cargo test
70+
- name: Clippy
71+
run:
72+
cargo clippy
73+
--all-features
74+
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
75+
continue-on-error: true
76+
77+
- name: Cargo deny
78+
run: cargo deny check
7079
continue-on-error: true
7180

7281
- name: Build
@@ -81,23 +90,6 @@ jobs:
8190
cd crates/bcr-ebill-wasm
8291
wasm-pack build --target web
8392
84-
- name: Install required cargo
85-
run: cargo install clippy-sarif sarif-fmt
86-
87-
- name: Add clippy
88-
run: rustup component add clippy
89-
90-
- name: Clippy
91-
run:
92-
cargo clippy
93-
--all-features
94-
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
95-
continue-on-error: true
96-
97-
- name: Cargo deny
98-
run: cargo deny check
99-
continue-on-error: true
100-
10193
- name: Upload analysis results to GitHub
10294
uses: github/codeql-action/upload-sarif@v3
10395
with:

.github/workflows/test.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,19 @@ jobs:
4949
echo "After cleanup:"
5050
df -h
5151
52-
- name: Install Rust
53-
uses: dtolnay/rust-toolchain@master
54-
with:
55-
toolchain: ${{ matrix.toolchain }}
56-
components: llvm-tools-preview
52+
- name: Switch rust version
53+
run: rustup default stable
54+
55+
- name: Update rust
56+
run: rustup update stable
57+
58+
- name: Install llvm-tools-preview
59+
run: rustup component add llvm-tools-preview
5760

5861
- name: Activate cache
5962
uses: Swatinem/[email protected]
63+
with:
64+
prefix-key: "ebill-01"
6065

6166
- name: Install grcov
6267
uses: taiki-e/install-action@v2

.github/workflows/wasm_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
runs-on: ubuntu-latest
2222

2323
# Restrict execution to specific users
24-
if: contains(fromJson('["mtbitcr", "zupzup", "tompro"]'), github.actor)
24+
if: contains(fromJson('["mtbitcr", "zupzup", "tompro", "cleot"]'), github.actor)
2525

2626
steps:
2727
- name: Checkout repository

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* It's now possible to recourse against the same person again
1515
* The last person in the chain can now reject a recourse (was broken before)
1616
* `get_past_endorsees` is calculated differently now - holders can only recourse against parties before the first block where they became a holder in the bill, even if they have multiple endorsement blocks in the bill
17+
* Cleanup deps, replace `bcr-wdc-*` deps with `bcr-common`, improve Github workflows
18+
* Implement the concept of `logical contacts`, which combine nostr contacts and contacts from the contact book (breaking DB change)
19+
* Added a `contactApi.search` call, where callers can search and filter for contacts from contact book, logical, or both
1720

1821
# 0.4.8
1922

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@ 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.2.1" }
6566
surrealdb = { version = "2.3", default-features = false }
6667
url = { version = "2.5" }

crates/bcr-ebill-api/Cargo.toml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ thiserror.workspace = true
2121
uuid.workspace = true
2222
bitcoin.workspace = true
2323
miniscript.workspace = true
24-
nostr-sdk.workspace = true
2524
nostr.workspace = true
2625
futures.workspace = true
2726
infer = { version = "0.19.0", default-features = false }
@@ -30,13 +29,10 @@ bcr-ebill-persistence.workspace = true
3029
tokio.workspace = true
3130
tokio_with_wasm.workspace = true
3231
secp256k1.workspace = true
33-
bcr-wdc-webapi = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "d121a5abc87c15ec364536c18b71d941fcaaee21" }
34-
bcr-wdc-quote-client = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "d121a5abc87c15ec364536c18b71d941fcaaee21" }
35-
bcr-wdc-key-client = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "d121a5abc87c15ec364536c18b71d941fcaaee21" }
36-
bcr-wdc-swap-client = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "d121a5abc87c15ec364536c18b71d941fcaaee21" }
37-
bcr-wallet-lib = { git = "https://github.com/BitcreditProtocol/Wallet-Core", rev = "f5a1ed4f52f5852bab27ec67996c2f2c8d16c6dd" }
32+
bcr-wallet-lib = { git = "https://github.com/BitcreditProtocol/Wallet-Core", tag = "v0.5.0" }
33+
bcr-common.workspace = true
3834
cashu = { version = "0.11", default-features = false }
39-
rand = { version = "0.8" }
35+
rand = { version = "0.9" }
4036
hex = { version = "0.4" }
4137
url.workspace = true
4238

@@ -48,9 +44,4 @@ reqwest = { workspace = true, features = ["default", "json"] }
4844

4945
[dev-dependencies]
5046
mockall.workspace = true
51-
nostr-relay-builder = "0.42"
5247
tokio.workspace = true
53-
async-broadcast.workspace = true
54-
55-
[features]
56-
embedded-db = ["bcr-ebill-persistence/embedded-db"]

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

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
use std::str::FromStr;
22

33
use async_trait::async_trait;
4+
use bcr_common::KeysClient;
5+
use bcr_common::QuoteClient;
6+
use bcr_common::SwapClient;
7+
use bcr_common::wire::quotes::{ResolveOffer, StatusReply};
48
use bcr_ebill_core::{
59
SecretKey, ServiceTraitBounds,
6-
bill::BillId,
710
blockchain::bill::BillToShareWithExternalParty,
811
util::{BcrKeys, date::DateTimeUtc},
912
};
10-
use bcr_wdc_key_client::KeyClient;
11-
use bcr_wdc_quote_client::QuoteClient;
12-
use bcr_wdc_swap_client::SwapClient;
13-
use bcr_wdc_webapi::quotes::{ResolveOffer, StatusReply};
1413
use cashu::{ProofsMethods, State, nut01 as cdk01, nut02 as cdk02};
1514
use thiserror::Error;
1615

@@ -135,23 +134,20 @@ impl MintClient {
135134
}
136135

137136
pub fn quote_client(&self, mint_url: &str) -> Result<QuoteClient> {
138-
let quote_client = bcr_wdc_quote_client::QuoteClient::new(
139-
reqwest::Url::parse(mint_url).map_err(|_| Error::InvalidMintUrl)?,
140-
);
137+
let quote_client =
138+
QuoteClient::new(reqwest::Url::parse(mint_url).map_err(|_| Error::InvalidMintUrl)?);
141139
Ok(quote_client)
142140
}
143141

144-
pub fn key_client(&self, mint_url: &str) -> Result<KeyClient> {
145-
let key_client = bcr_wdc_key_client::KeyClient::new(
146-
reqwest::Url::parse(mint_url).map_err(|_| Error::InvalidMintUrl)?,
147-
);
142+
pub fn key_client(&self, mint_url: &str) -> Result<KeysClient> {
143+
let key_client =
144+
KeysClient::new(reqwest::Url::parse(mint_url).map_err(|_| Error::InvalidMintUrl)?);
148145
Ok(key_client)
149146
}
150147

151148
pub fn swap_client(&self, mint_url: &str) -> Result<SwapClient> {
152-
let swap_client = bcr_wdc_swap_client::SwapClient::new(
153-
reqwest::Url::parse(mint_url).map_err(|_| Error::InvalidMintUrl)?,
154-
);
149+
let swap_client =
150+
SwapClient::new(reqwest::Url::parse(mint_url).map_err(|_| Error::InvalidMintUrl)?);
155151
Ok(swap_client)
156152
}
157153
}
@@ -321,22 +317,38 @@ impl MintClientApi for MintClient {
321317
quote_id: &str,
322318
resolve: ResolveMintOffer,
323319
) -> Result<()> {
324-
self.quote_client(mint_url)?
325-
.resolve(
326-
uuid::Uuid::from_str(quote_id).map_err(|_| Error::InvalidMintRequestId)?,
327-
resolve.into(),
328-
)
329-
.await
330-
.map_err(|e| {
331-
log::error!("Error resolving request on mint {mint_url}: {e}");
332-
Error::QuoteClient
333-
})?;
320+
match resolve {
321+
ResolveMintOffer::Accept => {
322+
self.quote_client(mint_url)?
323+
.accept_offer(
324+
uuid::Uuid::from_str(quote_id).map_err(|_| Error::InvalidMintRequestId)?,
325+
)
326+
.await
327+
.map_err(|e| {
328+
log::error!("Error accepting request on mint {mint_url}: {e}");
329+
Error::QuoteClient
330+
})?;
331+
}
332+
ResolveMintOffer::Reject => {
333+
self.quote_client(mint_url)?
334+
.reject_offer(
335+
uuid::Uuid::from_str(quote_id).map_err(|_| Error::InvalidMintRequestId)?,
336+
)
337+
.await
338+
.map_err(|e| {
339+
log::error!("Error rejecting request on mint {mint_url}: {e}");
340+
Error::QuoteClient
341+
})?;
342+
}
343+
};
334344
Ok(())
335345
}
336346

337347
async fn cancel_quote_for_mint(&self, mint_url: &str, quote_id: &str) -> Result<()> {
338348
self.quote_client(mint_url)?
339-
.cancel(uuid::Uuid::from_str(quote_id).map_err(|_| Error::InvalidMintRequestId)?)
349+
.cancel_enquiry(
350+
uuid::Uuid::from_str(quote_id).map_err(|_| Error::InvalidMintRequestId)?,
351+
)
340352
.await
341353
.map_err(|e| {
342354
log::error!("Error cancelling request on mint {mint_url}: {e}");
@@ -432,6 +444,7 @@ impl From<StatusReply> for QuoteStatusReply {
432444
keyset_id,
433445
expiration_date,
434446
discounted,
447+
..
435448
} => QuoteStatusReply::Offered {
436449
keyset_id,
437450
expiration_date,
@@ -447,17 +460,13 @@ impl From<StatusReply> for QuoteStatusReply {
447460

448461
fn map_shared_bill(
449462
bill_to_share: BillToShareWithExternalParty,
450-
) -> bcr_wdc_webapi::quotes::SharedBill {
451-
bcr_wdc_webapi::quotes::SharedBill {
452-
bill_id: map_bill_id(bill_to_share.bill_id),
463+
) -> bcr_common::wire::quotes::SharedBill {
464+
bcr_common::wire::quotes::SharedBill {
465+
bill_id: bill_to_share.bill_id,
453466
data: bill_to_share.data,
454467
file_urls: bill_to_share.file_urls,
455468
hash: bill_to_share.hash,
456469
signature: bill_to_share.signature,
457-
receiver: bill_to_share.receiver,
470+
receiver: bill_to_share.receiver.into(),
458471
}
459472
}
460-
461-
fn map_bill_id(bill_id: BillId) -> bcr_wdc_webapi::bill::BillId {
462-
bcr_wdc_webapi::bill::BillId::from_str(&bill_id.to_string()).expect("is a bill id")
463-
}

0 commit comments

Comments
 (0)