Skip to content

Commit f6edbe6

Browse files
authored
Use new payload for enquire mint (#579)
1 parent 6451953 commit f6edbe6

File tree

6 files changed

+36
-96
lines changed

6 files changed

+36
-96
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 0.4.2
22

33
* Add logic to get endorsees from plaintext chain
4+
* Use new payload for requesting to mint (Breaking - has to be coordinated with Wildcat deployment of [this PR](https://github.com/BitcreditProtocol/Wildcat/pull/260))
45

56
# 0.4.1
67

crates/bcr-ebill-api/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ bcr-ebill-transport.workspace = true
3131
tokio.workspace = true
3232
tokio_with_wasm.workspace = true
3333
secp256k1.workspace = true
34-
bcr-wdc-webapi = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "15b9a36d7663a592ccc0287d87f8d72746fc2d99" }
35-
bcr-wdc-quote-client = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "15b9a36d7663a592ccc0287d87f8d72746fc2d99" }
36-
bcr-wdc-key-client = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "15b9a36d7663a592ccc0287d87f8d72746fc2d99" }
37-
bcr-wdc-swap-client = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "15b9a36d7663a592ccc0287d87f8d72746fc2d99" }
34+
bcr-wdc-webapi = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "d121a5abc87c15ec364536c18b71d941fcaaee21" }
35+
bcr-wdc-quote-client = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "d121a5abc87c15ec364536c18b71d941fcaaee21" }
36+
bcr-wdc-key-client = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "d121a5abc87c15ec364536c18b71d941fcaaee21" }
37+
bcr-wdc-swap-client = { git = "https://github.com/BitcreditProtocol/wildcat", rev = "d121a5abc87c15ec364536c18b71d941fcaaee21" }
3838
bcr-wallet-lib = { git = "https://github.com/BitcreditProtocol/Wallet-Core", rev = "f5a1ed4f52f5852bab27ec67996c2f2c8d16c6dd" }
3939
cashu = { version = "0.11", default-features = false }
4040
rand = { version = "0.8" }

crates/bcr-ebill-api/src/external/mint.rs

Lines changed: 19 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
use std::str::FromStr;
22

3-
use crate::util;
43
use async_trait::async_trait;
54
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,
98
util::{BcrKeys, date::DateTimeUtc},
109
};
1110
use bcr_wdc_key_client::KeyClient;
1211
use bcr_wdc_quote_client::QuoteClient;
1312
use bcr_wdc_swap_client::SwapClient;
14-
use bcr_wdc_webapi::quotes::{BillInfo, ResolveOffer, StatusReply};
13+
use bcr_wdc_webapi::quotes::{ResolveOffer, StatusReply};
1514
use cashu::{ProofsMethods, State, nut01 as cdk01, nut02 as cdk02};
16-
use reqwest::Url;
1715
use thiserror::Error;
1816

1917
/// Generic result type
@@ -103,10 +101,8 @@ pub trait MintClientApi: ServiceTraitBounds {
103101
async fn enquire_mint_quote(
104102
&self,
105103
mint_url: &str,
104+
bill_to_share: BillToShareWithExternalParty,
106105
requester_keys: &BcrKeys,
107-
bill: &BitcreditBill,
108-
endorsees: &[BillParticipant],
109-
files: &[Url],
110106
) -> Result<String>;
111107
/// Look up a quote for a mint
112108
async fn lookup_quote_for_mint(
@@ -284,31 +280,17 @@ impl MintClientApi for MintClient {
284280
async fn enquire_mint_quote(
285281
&self,
286282
mint_url: &str,
283+
bill_to_share: BillToShareWithExternalParty,
287284
requester_keys: &BcrKeys,
288-
bill: &BitcreditBill,
289-
endorsees: &[BillParticipant],
290-
files: &[Url],
291285
) -> 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+
306288
let public_key = cdk01::PublicKey::from_hex(requester_keys.get_public_key())
307289
.map_err(|_| Error::PubKey)?;
308290

309291
let mint_request_id = self
310292
.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())
312294
.await
313295
.map_err(|e| {
314296
log::error!("Error enquiring to mint {mint_url}: {e}");
@@ -463,64 +445,19 @@ impl From<StatusReply> for QuoteStatusReply {
463445
}
464446
}
465447

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,
517458
}
518459
}
519460

520461
fn map_bill_id(bill_id: BillId) -> bcr_wdc_webapi::bill::BillId {
521462
bcr_wdc_webapi::bill::BillId::from_str(&bill_id.to_string()).expect("is a bill id")
522463
}
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-
}

crates/bcr-ebill-api/src/service/bill_service/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5965,7 +5965,7 @@ pub mod tests {
59655965
.returning(|_, _, _| Ok(vec![]));
59665966
ctx.mint_client
59675967
.expect_enquire_mint_quote()
5968-
.returning(|_, _, _, _, _| Ok("quote_id".to_owned()));
5968+
.returning(|_, _, _| Ok("quote_id".to_owned()));
59695969
ctx.mint_store
59705970
.expect_add_request()
59715971
.returning(|_, _, _, _, _| Ok(()));

crates/bcr-ebill-api/src/service/bill_service/service.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use bcr_ebill_core::bill::{
3434
PastPaymentDataSell, PastPaymentResult, PastPaymentStatus,
3535
};
3636
use bcr_ebill_core::blockchain::bill::block::BillParticipantBlockData;
37+
use bcr_ebill_core::blockchain::bill::create_bill_to_share_with_external_party;
3738
use bcr_ebill_core::company::{Company, CompanyKeys};
3839
use bcr_ebill_core::constants::{
3940
ACCEPT_DEADLINE_SECONDS, PAYMENT_DEADLINE_SECONDS, RECOURSE_DEADLINE_SECONDS,
@@ -1497,16 +1498,17 @@ impl BillServiceApi for BillService {
14971498
};
14981499

14991500
// Send request to mint to mint
1500-
let endorsees = blockchain.get_endorsees_for_bill(&bill_keys);
1501+
let bill_to_share = create_bill_to_share_with_external_party(
1502+
bill_id,
1503+
&blockchain,
1504+
&bill_keys,
1505+
&mint_anon_participant.node_id().pub_key(),
1506+
signer_keys,
1507+
&file_urls_for_mint,
1508+
)?;
15011509
let mint_request_id = self
15021510
.mint_client
1503-
.enquire_mint_quote(
1504-
&mint_cfg.default_mint_url,
1505-
signer_keys,
1506-
&bill,
1507-
&endorsees,
1508-
&file_urls_for_mint,
1509-
)
1511+
.enquire_mint_quote(&mint_cfg.default_mint_url, bill_to_share, signer_keys)
15101512
.await?;
15111513

15121514
// Store request to mint

crates/bcr-ebill-wasm/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let config = {
5656
job_runner_check_interval_seconds: 600,
5757
// default_mint_url: "http://localhost:4343",
5858
default_mint_url: "https://wildcat-dev-docker.minibill.tech",
59-
// default_mint_node_id: "bitcrt038d1bd3e2e3a01f20c861f18eb456cc33f869c9aaa5dec685f7f7d8c40ea3b3c7",
59+
// default_mint_node_id: "bitcrt038d1bd3e2e3a01f20c861f18eb456cc33f869c9aaa5dec685f7f7d8c40ea3b3c7",
6060
default_mint_node_id: "bitcrt0372422bfa5c9b60ef2f10ced26e764983b2e675cd7fac374f5f223616530ce3fb", // dev mint
6161
};
6262

0 commit comments

Comments
 (0)