|
1 | 1 | use std::str::FromStr; |
2 | 2 |
|
3 | | -use crate::util; |
4 | 3 | use async_trait::async_trait; |
5 | 4 | use bcr_ebill_core::{ |
6 | | - NodeId, PostalAddress, SecretKey, ServiceTraitBounds, |
7 | | - bill::{BillId, BitcreditBill}, |
8 | | - contact::{BillAnonParticipant, BillIdentParticipant, BillParticipant, ContactType}, |
| 5 | + SecretKey, ServiceTraitBounds, |
| 6 | + bill::BillId, |
| 7 | + blockchain::bill::BillToShareWithExternalParty, |
9 | 8 | util::{BcrKeys, date::DateTimeUtc}, |
10 | 9 | }; |
11 | 10 | use bcr_wdc_key_client::KeyClient; |
12 | 11 | use bcr_wdc_quote_client::QuoteClient; |
13 | 12 | use bcr_wdc_swap_client::SwapClient; |
14 | | -use bcr_wdc_webapi::quotes::{BillInfo, ResolveOffer, StatusReply}; |
| 13 | +use bcr_wdc_webapi::quotes::{ResolveOffer, StatusReply}; |
15 | 14 | use cashu::{ProofsMethods, State, nut01 as cdk01, nut02 as cdk02}; |
16 | | -use reqwest::Url; |
17 | 15 | use thiserror::Error; |
18 | 16 |
|
19 | 17 | /// Generic result type |
@@ -103,10 +101,8 @@ pub trait MintClientApi: ServiceTraitBounds { |
103 | 101 | async fn enquire_mint_quote( |
104 | 102 | &self, |
105 | 103 | mint_url: &str, |
| 104 | + bill_to_share: BillToShareWithExternalParty, |
106 | 105 | requester_keys: &BcrKeys, |
107 | | - bill: &BitcreditBill, |
108 | | - endorsees: &[BillParticipant], |
109 | | - files: &[Url], |
110 | 106 | ) -> Result<String>; |
111 | 107 | /// Look up a quote for a mint |
112 | 108 | async fn lookup_quote_for_mint( |
@@ -284,31 +280,17 @@ impl MintClientApi for MintClient { |
284 | 280 | async fn enquire_mint_quote( |
285 | 281 | &self, |
286 | 282 | mint_url: &str, |
| 283 | + bill_to_share: BillToShareWithExternalParty, |
287 | 284 | requester_keys: &BcrKeys, |
288 | | - bill: &BitcreditBill, |
289 | | - endorsees: &[BillParticipant], |
290 | | - files: &[Url], |
291 | 285 | ) -> Result<String> { |
292 | | - let bill_info = BillInfo { |
293 | | - id: map_bill_id(bill.id.clone()), |
294 | | - drawee: map_bill_ident_participant(bill.drawee.to_owned()), |
295 | | - drawer: map_bill_ident_participant(bill.drawer.to_owned()), |
296 | | - payee: map_bill_participant(bill.payee.to_owned()), |
297 | | - endorsees: endorsees |
298 | | - .iter() |
299 | | - .map(|e| map_bill_participant(e.to_owned())) |
300 | | - .collect(), |
301 | | - sum: bill.sum, |
302 | | - maturity_date: util::date::date_string_to_rfc3339(&bill.maturity_date) |
303 | | - .map_err(|_| Error::InvalidDate)?, |
304 | | - file_urls: files.to_owned(), |
305 | | - }; |
| 286 | + let shared_bill = map_shared_bill(bill_to_share); |
| 287 | + |
306 | 288 | let public_key = cdk01::PublicKey::from_hex(requester_keys.get_public_key()) |
307 | 289 | .map_err(|_| Error::PubKey)?; |
308 | 290 |
|
309 | 291 | let mint_request_id = self |
310 | 292 | .quote_client(mint_url)? |
311 | | - .enquire(bill_info, public_key, &requester_keys.get_key_pair()) |
| 293 | + .enquire(shared_bill, public_key, &requester_keys.get_key_pair()) |
312 | 294 | .await |
313 | 295 | .map_err(|e| { |
314 | 296 | log::error!("Error enquiring to mint {mint_url}: {e}"); |
@@ -463,64 +445,19 @@ impl From<StatusReply> for QuoteStatusReply { |
463 | 445 | } |
464 | 446 | } |
465 | 447 |
|
466 | | -// These are needed for now, because we use different `bcr-ebill-core` versions in wildcat and here |
467 | | -// this should be remediated, once we're stable on both sides |
468 | | - |
469 | | -fn map_bill_participant(part: BillParticipant) -> bcr_wdc_webapi::bill::BillParticipant { |
470 | | - match part { |
471 | | - BillParticipant::Ident(data) => { |
472 | | - bcr_wdc_webapi::bill::BillParticipant::Ident(map_bill_ident_participant(data)) |
473 | | - } |
474 | | - BillParticipant::Anon(data) => { |
475 | | - bcr_wdc_webapi::bill::BillParticipant::Anon(map_bill_anon_participant(data)) |
476 | | - } |
477 | | - } |
478 | | -} |
479 | | - |
480 | | -fn map_bill_anon_participant( |
481 | | - ident: BillAnonParticipant, |
482 | | -) -> bcr_wdc_webapi::bill::BillAnonParticipant { |
483 | | - bcr_wdc_webapi::bill::BillAnonParticipant { |
484 | | - node_id: map_node_id(ident.node_id), |
485 | | - email: ident.email, |
486 | | - nostr_relays: ident.nostr_relays, |
487 | | - } |
488 | | -} |
489 | | - |
490 | | -fn map_bill_ident_participant( |
491 | | - ident: BillIdentParticipant, |
492 | | -) -> bcr_wdc_webapi::bill::BillIdentParticipant { |
493 | | - bcr_wdc_webapi::bill::BillIdentParticipant { |
494 | | - t: map_contact_type(ident.t), |
495 | | - node_id: map_node_id(ident.node_id), |
496 | | - name: ident.name, |
497 | | - postal_address: map_postal_address(ident.postal_address), |
498 | | - email: ident.email, |
499 | | - nostr_relays: ident.nostr_relays, |
500 | | - } |
501 | | -} |
502 | | - |
503 | | -fn map_contact_type(ct: ContactType) -> bcr_wdc_webapi::contact::ContactType { |
504 | | - match ct { |
505 | | - ContactType::Person => bcr_wdc_webapi::contact::ContactType::Person, |
506 | | - ContactType::Company => bcr_wdc_webapi::contact::ContactType::Company, |
507 | | - ContactType::Anon => bcr_wdc_webapi::contact::ContactType::Anon, |
508 | | - } |
509 | | -} |
510 | | - |
511 | | -fn map_postal_address(pa: PostalAddress) -> bcr_wdc_webapi::identity::PostalAddress { |
512 | | - bcr_wdc_webapi::identity::PostalAddress { |
513 | | - country: pa.country, |
514 | | - city: pa.city, |
515 | | - zip: pa.zip, |
516 | | - address: pa.address, |
| 448 | +fn map_shared_bill( |
| 449 | + 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), |
| 453 | + data: bill_to_share.data, |
| 454 | + file_urls: bill_to_share.file_urls, |
| 455 | + hash: bill_to_share.hash, |
| 456 | + signature: bill_to_share.signature, |
| 457 | + receiver: bill_to_share.receiver, |
517 | 458 | } |
518 | 459 | } |
519 | 460 |
|
520 | 461 | fn map_bill_id(bill_id: BillId) -> bcr_wdc_webapi::bill::BillId { |
521 | 462 | bcr_wdc_webapi::bill::BillId::from_str(&bill_id.to_string()).expect("is a bill id") |
522 | 463 | } |
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