1
1
use std:: str:: FromStr ;
2
2
3
- use crate :: { constants :: CURRENCY_CRSAT , util} ;
3
+ use crate :: util;
4
4
use async_trait:: async_trait;
5
5
use bcr_ebill_core:: {
6
6
PostalAddress , SecretKey , ServiceTraitBounds ,
7
7
bill:: BitcreditBill ,
8
8
contact:: { BillAnonParticipant , BillIdentParticipant , BillParticipant , ContactType } ,
9
9
util:: { BcrKeys , date:: DateTimeUtc } ,
10
10
} ;
11
+ use bcr_wallet_lib:: wallet:: TokenOperations ;
11
12
use bcr_wdc_key_client:: KeyClient ;
12
13
use bcr_wdc_quote_client:: QuoteClient ;
13
14
use bcr_wdc_swap_client:: SwapClient ;
14
15
use bcr_wdc_webapi:: quotes:: { BillInfo , ResolveOffer , StatusReply } ;
15
- use cashu:: { ProofsMethods , State , nut00 as cdk00 , nut01 as cdk01, nut02 as cdk02} ;
16
+ use cashu:: { ProofsMethods , State , nut01 as cdk01, nut02 as cdk02} ;
16
17
use reqwest:: Url ;
17
18
use thiserror:: Error ;
18
19
@@ -161,34 +162,28 @@ impl MintClientApi for MintClient {
161
162
async fn check_if_proofs_are_spent ( & self , mint_url : & str , proofs : & str ) -> Result < bool > {
162
163
let token_mint_url =
163
164
cashu:: MintUrl :: from_str ( mint_url) . map_err ( |_| Error :: InvalidMintUrl ) ?;
164
- let token = cashu:: Token :: from_str ( proofs) . map_err ( |_| Error :: InvalidToken ) ?;
165
-
166
- if let cashu:: Token :: TokenV3 ( token_v3) = token {
167
- if let Some ( token_for_mint) = token_v3
168
- . token
169
- . into_iter ( )
170
- . find ( |t| t. mint == token_mint_url)
171
- {
172
- let ys = token_for_mint. proofs . ys ( ) . map_err ( |_| Error :: PubKey ) ?;
173
- let proof_states =
174
- self . swap_client ( mint_url) ?
175
- . check_state ( ys)
176
- . await
177
- . map_err ( |e| {
178
- log:: error!( "Error checking if proofs are spent at {mint_url}: {e}" ) ;
179
- Error :: SwapClient
180
- } ) ?;
181
- // all proofs have to be spent
182
- let proofs_spent = proof_states
183
- . iter ( )
184
- . all ( |ps| matches ! ( ps. state, State :: Spent ) ) ;
185
- Ok ( proofs_spent)
186
- } else {
187
- Err ( Error :: InvalidToken . into ( ) )
188
- }
189
- } else {
190
- Err ( Error :: InvalidToken . into ( ) )
165
+ let token =
166
+ bcr_wallet_lib:: wallet:: Token :: from_str ( proofs) . map_err ( |_| Error :: InvalidToken ) ?;
167
+
168
+ if token_mint_url != token. mint_url ( ) {
169
+ return Err ( Error :: InvalidToken . into ( ) ) ;
191
170
}
171
+
172
+ let ys = token. proofs ( ) . ys ( ) . map_err ( |_| Error :: PubKey ) ?;
173
+
174
+ let proof_states = self
175
+ . swap_client ( mint_url) ?
176
+ . check_state ( ys)
177
+ . await
178
+ . map_err ( |e| {
179
+ log:: error!( "Error checking if proofs are spent at {mint_url}: {e}" ) ;
180
+ Error :: SwapClient
181
+ } ) ?;
182
+ // all proofs have to be spent
183
+ let proofs_spent = proof_states
184
+ . iter ( )
185
+ . all ( |ps| matches ! ( ps. state, State :: Spent ) ) ;
186
+ Ok ( proofs_spent)
192
187
}
193
188
194
189
async fn mint (
@@ -206,6 +201,15 @@ impl MintClientApi for MintClient {
206
201
let secret_key = cdk01:: SecretKey :: from_hex ( private_key. display_secret ( ) . to_string ( ) )
207
202
. map_err ( |_| Error :: PrivateKey ) ?;
208
203
let qid = uuid:: Uuid :: from_str ( quote_id) . map_err ( |_| Error :: InvalidMintRequestId ) ?;
204
+ let currency = self
205
+ . key_client ( mint_url) ?
206
+ . keyset_info ( keyset. id )
207
+ . await
208
+ . map_err ( |e| {
209
+ log:: error!( "Error getting keyset info from {mint_url}: {e}" ) ;
210
+ Error :: Minting
211
+ } ) ?
212
+ . unit ;
209
213
210
214
// mint
211
215
let blinded_signatures = self
@@ -225,14 +229,10 @@ impl MintClientApi for MintClient {
225
229
} ) ?;
226
230
227
231
// generate token from proofs
228
- let token = cdk00:: Token :: new (
229
- token_mint_url,
230
- proofs,
231
- None ,
232
- cashu:: CurrencyUnit :: Custom ( CURRENCY_CRSAT . into ( ) ) ,
233
- ) ;
232
+ let token =
233
+ bcr_wallet_lib:: wallet:: Token :: new_credit ( token_mint_url, currency, None , proofs) ;
234
234
235
- Ok ( token. to_v3_string ( ) )
235
+ Ok ( token. to_string ( ) )
236
236
}
237
237
238
238
async fn get_keyset_info ( & self , mint_url : & str , keyset_id : & str ) -> Result < cdk02:: KeySet > {
0 commit comments