Skip to content

Commit 69db03b

Browse files
authored
Add file urls and accessor methods for shared bill (#570)
1 parent 9c2fae0 commit 69db03b

File tree

7 files changed

+351
-25
lines changed

7 files changed

+351
-25
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ bcr-ebill-core = { path = "./crates/bcr-ebill-core" }
6060
bcr-ebill-persistence = { path = "./crates/bcr-ebill-persistence" }
6161
bcr-ebill-transport = { path = "./crates/bcr-ebill-transport" }
6262
surrealdb = { version = "2.3", default-features = false }
63+
url = {version = "2.5"}

crates/bcr-ebill-api/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bcr-wallet-lib = { git = "https://github.com/BitcreditProtocol/Wallet-Core", rev
3939
cashu = { version = "0.9", default-features = false }
4040
rand = { version = "0.8" }
4141
hex = { version = "0.4" }
42-
url = {version = "2.5"}
42+
url.workspace = true
4343

4444
[target.'cfg(target_arch = "wasm32")'.dependencies]
4545
reqwest = { workspace = true, features = ["json"] }

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ impl BillService {
1818
bill_id: &BillId,
1919
external_party_pub_key: &PublicKey,
2020
sharer_keys: &BcrKeys,
21+
file_urls: &[url::Url],
2122
) -> Result<BillToShareWithExternalParty> {
2223
let chain = self.blockchain_store.get_chain(bill_id).await?;
2324
let bill_keys = self.store.get_keys(bill_id).await?;
@@ -33,8 +34,10 @@ impl BillService {
3334
let result = BillToShareWithExternalParty {
3435
bill_id: bill_id.to_owned(),
3536
data: encoded,
37+
file_urls: file_urls.to_owned(),
3638
hash,
3739
signature,
40+
receiver: external_party_pub_key.to_owned(),
3841
};
3942
Ok(result)
4043
}
@@ -85,13 +88,14 @@ pub mod tests {
8588
let service = get_service(ctx);
8689

8790
let result = service
88-
.share_bill_with_external_party(&bill_id, &external_party_pub_key, &sharer_keys)
91+
.share_bill_with_external_party(&bill_id, &external_party_pub_key, &sharer_keys, &[])
8992
.await;
9093
assert!(result.is_ok());
9194

9295
// Receiver side
9396
let unwrapped = result.unwrap().clone();
9497
assert_eq!(unwrapped.bill_id, bill_id);
98+
assert_eq!(unwrapped.receiver, external_party_pub_key);
9599
let data = unwrapped.data;
96100
let hash = unwrapped.hash;
97101
let signature = unwrapped.signature;

crates/bcr-ebill-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ nostr.workspace = true
2424
secp256k1 = { workspace = true, features = ["global-context"] }
2525
rust_decimal = { version = "1.36.0", default-features = false }
2626
once_cell = "1.21.3"
27+
url.workspace = true
2728

2829
[dev-dependencies]
2930
rstest.workspace = true

crates/bcr-ebill-core/src/bill/mod.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
use std::str::FromStr;
22

3+
use super::{
4+
File, PostalAddress,
5+
contact::{
6+
BillIdentParticipant, LightBillIdentParticipant, LightBillIdentParticipantWithAddress,
7+
},
8+
notification::Notification,
9+
};
310
use crate::{
411
ID_PREFIX, NETWORK_MAINNET, NETWORK_REGTEST, NETWORK_TESTNET, NETWORK_TESTNET4, NodeId,
512
ValidationError,
@@ -8,14 +15,7 @@ use crate::{
815
network_char,
916
util::{self, BcrKeys},
1017
};
11-
12-
use super::{
13-
File, PostalAddress,
14-
contact::{
15-
BillIdentParticipant, LightBillIdentParticipant, LightBillIdentParticipantWithAddress,
16-
},
17-
notification::Notification,
18-
};
18+
use borsh::{BorshDeserialize, BorshSerialize};
1919
use secp256k1::{PublicKey, SecretKey};
2020
use serde::{Deserialize, Serialize};
2121

@@ -110,7 +110,7 @@ impl<'de> serde::Deserialize<'de> for BillId {
110110
where
111111
D: serde::Deserializer<'de>,
112112
{
113-
let s = String::deserialize(d)?;
113+
let s = <std::string::String as serde::Deserialize>::deserialize(d)?;
114114
BillId::from_str(&s).map_err(serde::de::Error::custom)
115115
}
116116
}
@@ -611,14 +611,26 @@ pub struct PastPaymentDataRecourse {
611611
pub status: PastPaymentStatus,
612612
}
613613

614-
#[derive(Serialize, Deserialize, Debug, Clone)]
614+
#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, Debug, Clone)]
615615
pub struct BillToShareWithExternalParty {
616616
/// The bill id
617617
pub bill_id: BillId,
618618
/// The base58 encoded, encrypted BillBlockPlaintextWrapper of the bill
619619
pub data: String,
620+
#[borsh(
621+
serialize_with = "crate::util::borsh::serialize_vec_url",
622+
deserialize_with = "crate::util::borsh::deserialize_vec_url"
623+
)]
624+
/// The file urls of bill files, encrypted with the receiver's key, uploaded to Nostr
625+
pub file_urls: Vec<url::Url>,
620626
/// The hash over the unencrypted data
621627
pub hash: String,
622628
/// The signature over the hash by the sharer of the bill
623629
pub signature: String,
630+
#[borsh(
631+
serialize_with = "crate::util::borsh::serialize_pubkey",
632+
deserialize_with = "crate::util::borsh::deserialize_pubkey"
633+
)]
634+
/// The receiver's pub key
635+
pub receiver: PublicKey,
624636
}

0 commit comments

Comments
 (0)