1
1
use std:: str:: FromStr ;
2
2
3
3
use async_trait:: async_trait;
4
+ use bcr_common:: KeysClient ;
5
+ use bcr_common:: QuoteClient ;
6
+ use bcr_common:: SwapClient ;
7
+ use bcr_common:: wire:: quotes:: { ResolveOffer , StatusReply } ;
4
8
use bcr_ebill_core:: {
5
9
SecretKey , ServiceTraitBounds ,
6
- bill:: BillId ,
7
10
blockchain:: bill:: BillToShareWithExternalParty ,
8
11
util:: { BcrKeys , date:: DateTimeUtc } ,
9
12
} ;
10
- use bcr_wdc_key_client:: KeyClient ;
11
- use bcr_wdc_quote_client:: QuoteClient ;
12
- use bcr_wdc_swap_client:: SwapClient ;
13
- use bcr_wdc_webapi:: quotes:: { ResolveOffer , StatusReply } ;
14
13
use cashu:: { ProofsMethods , State , nut01 as cdk01, nut02 as cdk02} ;
15
14
use thiserror:: Error ;
16
15
@@ -135,23 +134,20 @@ impl MintClient {
135
134
}
136
135
137
136
pub fn quote_client ( & self , mint_url : & str ) -> Result < QuoteClient > {
138
- let quote_client = bcr_wdc_quote_client:: QuoteClient :: new (
139
- reqwest:: Url :: parse ( mint_url) . map_err ( |_| Error :: InvalidMintUrl ) ?,
140
- ) ;
137
+ let quote_client =
138
+ QuoteClient :: new ( reqwest:: Url :: parse ( mint_url) . map_err ( |_| Error :: InvalidMintUrl ) ?) ;
141
139
Ok ( quote_client)
142
140
}
143
141
144
- pub fn key_client ( & self , mint_url : & str ) -> Result < KeyClient > {
145
- let key_client = bcr_wdc_key_client:: KeyClient :: new (
146
- reqwest:: Url :: parse ( mint_url) . map_err ( |_| Error :: InvalidMintUrl ) ?,
147
- ) ;
142
+ pub fn key_client ( & self , mint_url : & str ) -> Result < KeysClient > {
143
+ let key_client =
144
+ KeysClient :: new ( reqwest:: Url :: parse ( mint_url) . map_err ( |_| Error :: InvalidMintUrl ) ?) ;
148
145
Ok ( key_client)
149
146
}
150
147
151
148
pub fn swap_client ( & self , mint_url : & str ) -> Result < SwapClient > {
152
- let swap_client = bcr_wdc_swap_client:: SwapClient :: new (
153
- reqwest:: Url :: parse ( mint_url) . map_err ( |_| Error :: InvalidMintUrl ) ?,
154
- ) ;
149
+ let swap_client =
150
+ SwapClient :: new ( reqwest:: Url :: parse ( mint_url) . map_err ( |_| Error :: InvalidMintUrl ) ?) ;
155
151
Ok ( swap_client)
156
152
}
157
153
}
@@ -321,22 +317,38 @@ impl MintClientApi for MintClient {
321
317
quote_id : & str ,
322
318
resolve : ResolveMintOffer ,
323
319
) -> Result < ( ) > {
324
- self . quote_client ( mint_url) ?
325
- . resolve (
326
- uuid:: Uuid :: from_str ( quote_id) . map_err ( |_| Error :: InvalidMintRequestId ) ?,
327
- resolve. into ( ) ,
328
- )
329
- . await
330
- . map_err ( |e| {
331
- log:: error!( "Error resolving request on mint {mint_url}: {e}" ) ;
332
- Error :: QuoteClient
333
- } ) ?;
320
+ match resolve {
321
+ ResolveMintOffer :: Accept => {
322
+ self . quote_client ( mint_url) ?
323
+ . accept_offer (
324
+ uuid:: Uuid :: from_str ( quote_id) . map_err ( |_| Error :: InvalidMintRequestId ) ?,
325
+ )
326
+ . await
327
+ . map_err ( |e| {
328
+ log:: error!( "Error accepting request on mint {mint_url}: {e}" ) ;
329
+ Error :: QuoteClient
330
+ } ) ?;
331
+ }
332
+ ResolveMintOffer :: Reject => {
333
+ self . quote_client ( mint_url) ?
334
+ . reject_offer (
335
+ uuid:: Uuid :: from_str ( quote_id) . map_err ( |_| Error :: InvalidMintRequestId ) ?,
336
+ )
337
+ . await
338
+ . map_err ( |e| {
339
+ log:: error!( "Error rejecting request on mint {mint_url}: {e}" ) ;
340
+ Error :: QuoteClient
341
+ } ) ?;
342
+ }
343
+ } ;
334
344
Ok ( ( ) )
335
345
}
336
346
337
347
async fn cancel_quote_for_mint ( & self , mint_url : & str , quote_id : & str ) -> Result < ( ) > {
338
348
self . quote_client ( mint_url) ?
339
- . cancel ( uuid:: Uuid :: from_str ( quote_id) . map_err ( |_| Error :: InvalidMintRequestId ) ?)
349
+ . cancel_enquiry (
350
+ uuid:: Uuid :: from_str ( quote_id) . map_err ( |_| Error :: InvalidMintRequestId ) ?,
351
+ )
340
352
. await
341
353
. map_err ( |e| {
342
354
log:: error!( "Error cancelling request on mint {mint_url}: {e}" ) ;
@@ -432,6 +444,7 @@ impl From<StatusReply> for QuoteStatusReply {
432
444
keyset_id,
433
445
expiration_date,
434
446
discounted,
447
+ ..
435
448
} => QuoteStatusReply :: Offered {
436
449
keyset_id,
437
450
expiration_date,
@@ -447,17 +460,13 @@ impl From<StatusReply> for QuoteStatusReply {
447
460
448
461
fn map_shared_bill (
449
462
bill_to_share : BillToShareWithExternalParty ,
450
- ) -> bcr_wdc_webapi :: quotes:: SharedBill {
451
- bcr_wdc_webapi :: quotes:: SharedBill {
452
- bill_id : map_bill_id ( bill_to_share. bill_id ) ,
463
+ ) -> bcr_common :: wire :: quotes:: SharedBill {
464
+ bcr_common :: wire :: quotes:: SharedBill {
465
+ bill_id : bill_to_share. bill_id ,
453
466
data : bill_to_share. data ,
454
467
file_urls : bill_to_share. file_urls ,
455
468
hash : bill_to_share. hash ,
456
469
signature : bill_to_share. signature ,
457
- receiver : bill_to_share. receiver ,
470
+ receiver : bill_to_share. receiver . into ( ) ,
458
471
}
459
472
}
460
-
461
- fn map_bill_id ( bill_id : BillId ) -> bcr_wdc_webapi:: bill:: BillId {
462
- bcr_wdc_webapi:: bill:: BillId :: from_str ( & bill_id. to_string ( ) ) . expect ( "is a bill id" )
463
- }
0 commit comments