@@ -3,12 +3,11 @@ use std::str::FromStr;
3
3
use crate :: util;
4
4
use async_trait:: async_trait;
5
5
use bcr_ebill_core:: {
6
- PostalAddress , SecretKey , ServiceTraitBounds ,
7
- bill:: BitcreditBill ,
6
+ NodeId , PostalAddress , SecretKey , ServiceTraitBounds ,
7
+ bill:: { BillId , BitcreditBill } ,
8
8
contact:: { BillAnonParticipant , BillIdentParticipant , BillParticipant , ContactType } ,
9
9
util:: { BcrKeys , date:: DateTimeUtc } ,
10
10
} ;
11
- use bcr_wallet_lib:: wallet:: TokenOperations ;
12
11
use bcr_wdc_key_client:: KeyClient ;
13
12
use bcr_wdc_quote_client:: QuoteClient ;
14
13
use bcr_wdc_swap_client:: SwapClient ;
@@ -81,7 +80,12 @@ use mockall::automock;
81
80
#[ cfg_attr( not( target_arch = "wasm32" ) , async_trait) ]
82
81
pub trait MintClientApi : ServiceTraitBounds {
83
82
/// Check if the given proofs were already spent
84
- async fn check_if_proofs_are_spent ( & self , mint_url : & str , proofs : & str ) -> Result < bool > ;
83
+ async fn check_if_proofs_are_spent (
84
+ & self ,
85
+ mint_url : & str ,
86
+ proofs : & str ,
87
+ keyset_id : & str ,
88
+ ) -> Result < bool > ;
85
89
/// Mint and return encoded token
86
90
async fn mint (
87
91
& self ,
@@ -159,7 +163,12 @@ impl MintClient {
159
163
#[ cfg_attr( target_arch = "wasm32" , async_trait( ?Send ) ) ]
160
164
#[ cfg_attr( not( target_arch = "wasm32" ) , async_trait) ]
161
165
impl MintClientApi for MintClient {
162
- async fn check_if_proofs_are_spent ( & self , mint_url : & str , proofs : & str ) -> Result < bool > {
166
+ async fn check_if_proofs_are_spent (
167
+ & self ,
168
+ mint_url : & str ,
169
+ proofs : & str ,
170
+ keyset_id : & str ,
171
+ ) -> Result < bool > {
163
172
let token_mint_url =
164
173
cashu:: MintUrl :: from_str ( mint_url) . map_err ( |_| Error :: InvalidMintUrl ) ?;
165
174
let token =
@@ -169,7 +178,25 @@ impl MintClientApi for MintClient {
169
178
return Err ( Error :: InvalidToken . into ( ) ) ;
170
179
}
171
180
172
- let ys = token. proofs ( ) . ys ( ) . map_err ( |_| Error :: PubKey ) ?;
181
+ let keyset_id_parsed = cdk02:: Id :: from_str ( keyset_id) . map_err ( |e| {
182
+ log:: error!( "Error parsing keyset id {keyset_id} for {mint_url}: {e}" ) ;
183
+ Error :: InvalidKeySetId
184
+ } ) ?;
185
+
186
+ let keyset_info = self
187
+ . key_client ( mint_url) ?
188
+ . keyset_info ( keyset_id_parsed)
189
+ . await
190
+ . map_err ( |e| {
191
+ log:: error!( "Error getting keyset info from {mint_url}: {e}" ) ;
192
+ Error :: KeyClient
193
+ } ) ?;
194
+
195
+ let ys = token
196
+ . proofs ( & [ keyset_info] )
197
+ . map_err ( |_| Error :: InvalidToken ) ?
198
+ . ys ( )
199
+ . map_err ( |_| Error :: PubKey ) ?;
173
200
174
201
let proof_states = self
175
202
. swap_client ( mint_url) ?
@@ -230,7 +257,7 @@ impl MintClientApi for MintClient {
230
257
231
258
// generate token from proofs
232
259
let token =
233
- bcr_wallet_lib:: wallet:: Token :: new_credit ( token_mint_url, currency , None , proofs ) ;
260
+ bcr_wallet_lib:: wallet:: Token :: new_bitcr ( token_mint_url, proofs , None , currency ) ;
234
261
235
262
Ok ( token. to_string ( ) )
236
263
}
@@ -263,7 +290,7 @@ impl MintClientApi for MintClient {
263
290
files : & [ Url ] ,
264
291
) -> Result < String > {
265
292
let bill_info = BillInfo {
266
- id : bill. id . clone ( ) . to_string ( ) ,
293
+ id : map_bill_id ( bill. id . clone ( ) ) ,
267
294
drawee : map_bill_ident_participant ( bill. drawee . to_owned ( ) ) ,
268
295
drawer : map_bill_ident_participant ( bill. drawer . to_owned ( ) ) ,
269
296
payee : map_bill_participant ( bill. payee . to_owned ( ) ) ,
@@ -454,7 +481,7 @@ fn map_bill_anon_participant(
454
481
ident : BillAnonParticipant ,
455
482
) -> bcr_wdc_webapi:: bill:: BillAnonParticipant {
456
483
bcr_wdc_webapi:: bill:: BillAnonParticipant {
457
- node_id : ident. node_id . to_string ( ) ,
484
+ node_id : map_node_id ( ident. node_id ) ,
458
485
email : ident. email ,
459
486
nostr_relays : ident. nostr_relays ,
460
487
}
@@ -465,7 +492,7 @@ fn map_bill_ident_participant(
465
492
) -> bcr_wdc_webapi:: bill:: BillIdentParticipant {
466
493
bcr_wdc_webapi:: bill:: BillIdentParticipant {
467
494
t : map_contact_type ( ident. t ) ,
468
- node_id : ident. node_id . to_string ( ) ,
495
+ node_id : map_node_id ( ident. node_id ) ,
469
496
name : ident. name ,
470
497
postal_address : map_postal_address ( ident. postal_address ) ,
471
498
email : ident. email ,
@@ -489,3 +516,11 @@ fn map_postal_address(pa: PostalAddress) -> bcr_wdc_webapi::identity::PostalAddr
489
516
address : pa. address ,
490
517
}
491
518
}
519
+
520
+ fn map_bill_id ( bill_id : BillId ) -> bcr_wdc_webapi:: bill:: BillId {
521
+ bcr_wdc_webapi:: bill:: BillId :: from_str ( & bill_id. to_string ( ) ) . expect ( "is a bill id" )
522
+ }
523
+
524
+ fn map_node_id ( node_id : NodeId ) -> bcr_wdc_webapi:: bill:: NodeId {
525
+ bcr_wdc_webapi:: bill:: NodeId :: from_str ( & node_id. to_string ( ) ) . expect ( "is a node id" )
526
+ }
0 commit comments