@@ -14,7 +14,7 @@ use crate::data::{
14
14
identity:: Identity ,
15
15
} ;
16
16
use crate :: external:: bitcoin:: BitcoinClientApi ;
17
- use crate :: external:: file_storage:: FileStorageClientApi ;
17
+ use crate :: external:: file_storage:: { self , FileStorageClientApi } ;
18
18
use crate :: external:: mint:: { MintClientApi , QuoteStatusReply , ResolveMintOffer } ;
19
19
use crate :: get_config;
20
20
use crate :: persistence:: bill:: BillChainStoreApi ;
@@ -44,7 +44,7 @@ use bcr_ebill_core::util::currency;
44
44
use bcr_ebill_core:: { File , ServiceTraitBounds , Validate , ValidationError } ;
45
45
use bcr_ebill_persistence:: mint:: MintStoreApi ;
46
46
use bcr_ebill_transport:: NotificationServiceApi ;
47
- use log:: { debug, error, info} ;
47
+ use log:: { debug, error, info, warn } ;
48
48
use std:: collections:: { HashMap , HashSet } ;
49
49
use std:: sync:: Arc ;
50
50
@@ -622,6 +622,38 @@ impl BillService {
622
622
nostr_relays : relays,
623
623
} )
624
624
}
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
+ }
625
657
}
626
658
627
659
#[ cfg_attr( target_arch = "wasm32" , async_trait( ?Send ) ) ]
@@ -1411,11 +1443,38 @@ impl BillServiceApi for BillService {
1411
1443
) ) ;
1412
1444
}
1413
1445
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
+
1414
1467
// Send request to mint to mint
1415
1468
let endorsees = blockchain. get_endorsees_for_bill ( & bill_keys) ;
1416
1469
let mint_request_id = self
1417
1470
. 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
+ )
1419
1478
. await ?;
1420
1479
1421
1480
// Store request to mint
0 commit comments