@@ -3,12 +3,11 @@ use std::str::FromStr;
33use crate :: util;
44use async_trait:: async_trait;
55use bcr_ebill_core:: {
6- PostalAddress , SecretKey , ServiceTraitBounds ,
7- bill:: BitcreditBill ,
6+ NodeId , PostalAddress , SecretKey , ServiceTraitBounds ,
7+ bill:: { BillId , BitcreditBill } ,
88 contact:: { BillAnonParticipant , BillIdentParticipant , BillParticipant , ContactType } ,
99 util:: { BcrKeys , date:: DateTimeUtc } ,
1010} ;
11- use bcr_wallet_lib:: wallet:: TokenOperations ;
1211use bcr_wdc_key_client:: KeyClient ;
1312use bcr_wdc_quote_client:: QuoteClient ;
1413use bcr_wdc_swap_client:: SwapClient ;
@@ -81,7 +80,12 @@ use mockall::automock;
8180#[ cfg_attr( not( target_arch = "wasm32" ) , async_trait) ]
8281pub trait MintClientApi : ServiceTraitBounds {
8382 /// 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 > ;
8589 /// Mint and return encoded token
8690 async fn mint (
8791 & self ,
@@ -159,7 +163,12 @@ impl MintClient {
159163#[ cfg_attr( target_arch = "wasm32" , async_trait( ?Send ) ) ]
160164#[ cfg_attr( not( target_arch = "wasm32" ) , async_trait) ]
161165impl 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 > {
163172 let token_mint_url =
164173 cashu:: MintUrl :: from_str ( mint_url) . map_err ( |_| Error :: InvalidMintUrl ) ?;
165174 let token =
@@ -169,7 +178,25 @@ impl MintClientApi for MintClient {
169178 return Err ( Error :: InvalidToken . into ( ) ) ;
170179 }
171180
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 ) ?;
173200
174201 let proof_states = self
175202 . swap_client ( mint_url) ?
@@ -230,7 +257,7 @@ impl MintClientApi for MintClient {
230257
231258 // generate token from proofs
232259 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 ) ;
234261
235262 Ok ( token. to_string ( ) )
236263 }
@@ -263,7 +290,7 @@ impl MintClientApi for MintClient {
263290 files : & [ Url ] ,
264291 ) -> Result < String > {
265292 let bill_info = BillInfo {
266- id : bill. id . clone ( ) . to_string ( ) ,
293+ id : map_bill_id ( bill. id . clone ( ) ) ,
267294 drawee : map_bill_ident_participant ( bill. drawee . to_owned ( ) ) ,
268295 drawer : map_bill_ident_participant ( bill. drawer . to_owned ( ) ) ,
269296 payee : map_bill_participant ( bill. payee . to_owned ( ) ) ,
@@ -454,7 +481,7 @@ fn map_bill_anon_participant(
454481 ident : BillAnonParticipant ,
455482) -> bcr_wdc_webapi:: bill:: BillAnonParticipant {
456483 bcr_wdc_webapi:: bill:: BillAnonParticipant {
457- node_id : ident. node_id . to_string ( ) ,
484+ node_id : map_node_id ( ident. node_id ) ,
458485 email : ident. email ,
459486 nostr_relays : ident. nostr_relays ,
460487 }
@@ -465,7 +492,7 @@ fn map_bill_ident_participant(
465492) -> bcr_wdc_webapi:: bill:: BillIdentParticipant {
466493 bcr_wdc_webapi:: bill:: BillIdentParticipant {
467494 t : map_contact_type ( ident. t ) ,
468- node_id : ident. node_id . to_string ( ) ,
495+ node_id : map_node_id ( ident. node_id ) ,
469496 name : ident. name ,
470497 postal_address : map_postal_address ( ident. postal_address ) ,
471498 email : ident. email ,
@@ -489,3 +516,11 @@ fn map_postal_address(pa: PostalAddress) -> bcr_wdc_webapi::identity::PostalAddr
489516 address : pa. address ,
490517 }
491518}
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