@@ -14,7 +14,7 @@ use crate::data::{
1414 identity:: Identity ,
1515} ;
1616use crate :: external:: bitcoin:: BitcoinClientApi ;
17- use crate :: external:: file_storage:: FileStorageClientApi ;
17+ use crate :: external:: file_storage:: { self , FileStorageClientApi } ;
1818use crate :: external:: mint:: { MintClientApi , QuoteStatusReply , ResolveMintOffer } ;
1919use crate :: get_config;
2020use crate :: persistence:: bill:: BillChainStoreApi ;
@@ -44,7 +44,7 @@ use bcr_ebill_core::util::currency;
4444use bcr_ebill_core:: { File , ServiceTraitBounds , Validate , ValidationError } ;
4545use bcr_ebill_persistence:: mint:: MintStoreApi ;
4646use bcr_ebill_transport:: NotificationServiceApi ;
47- use log:: { debug, error, info} ;
47+ use log:: { debug, error, info, warn } ;
4848use std:: collections:: { HashMap , HashSet } ;
4949use std:: sync:: Arc ;
5050
@@ -622,6 +622,38 @@ impl BillService {
622622 nostr_relays : relays,
623623 } )
624624 }
625+
626+ /// Download the files, decrypt them, encrypt and upload them for the given node id
627+ /// and relay url and return a list of urls to the uploaded files
628+ async fn upload_bill_files_for_node_id (
629+ & self ,
630+ bill_id : & str ,
631+ bill_private_key : & str ,
632+ node_id : & str ,
633+ relay_url : & str ,
634+ files : & [ File ] ,
635+ ) -> Result < Vec < url:: Url > > {
636+ if files. is_empty ( ) {
637+ return Ok ( vec ! [ ] ) ;
638+ }
639+ let mut result = Vec :: with_capacity ( files. len ( ) ) ;
640+ for file in files {
641+ let decrypted_file = self
642+ . open_and_decrypt_attached_file ( bill_id, file, bill_private_key)
643+ . await ?;
644+ let uploaded_file = self
645+ . encrypt_and_save_uploaded_file (
646+ & file. name ,
647+ & decrypted_file,
648+ bill_id,
649+ node_id,
650+ relay_url,
651+ )
652+ . await ?;
653+ result. push ( file_storage:: to_url ( relay_url, & uploaded_file. nostr_hash ) ?) ;
654+ }
655+ Ok ( result)
656+ }
625657}
626658
627659#[ cfg_attr( target_arch = "wasm32" , async_trait( ?Send ) ) ]
@@ -1411,11 +1443,38 @@ impl BillServiceApi for BillService {
14111443 ) ) ;
14121444 }
14131445
1446+ // Upload existing files for the mint
1447+ let file_urls_for_mint = match mint_anon_participant. nostr_relays ( ) . first ( ) {
1448+ Some ( relay_url) => {
1449+ self . upload_bill_files_for_node_id (
1450+ bill_id,
1451+ & bill_keys. private_key ,
1452+ & mint_anon_participant. node_id ( ) ,
1453+ relay_url,
1454+ & bill. files ,
1455+ )
1456+ . await ?
1457+ }
1458+ None => {
1459+ warn ! (
1460+ "mint {} does not have a nostr relay" ,
1461+ & mint_anon_participant. node_id( )
1462+ ) ;
1463+ vec ! [ ]
1464+ }
1465+ } ;
1466+
14141467 // Send request to mint to mint
14151468 let endorsees = blockchain. get_endorsees_for_bill ( & bill_keys) ;
14161469 let mint_request_id = self
14171470 . mint_client
1418- . enquire_mint_quote ( & mint_cfg. default_mint_url , signer_keys, & bill, & endorsees)
1471+ . enquire_mint_quote (
1472+ & mint_cfg. default_mint_url ,
1473+ signer_keys,
1474+ & bill,
1475+ & endorsees,
1476+ & file_urls_for_mint,
1477+ )
14191478 . await ?;
14201479
14211480 // Store request to mint
0 commit comments