Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract HttpClient into HttpClientMethods trait #429

Merged
merged 7 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/cdk-cli/src/sub_commands/mint_info.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use cdk::mint_url::MintUrl;
use cdk::wallet::client::HttpClientMethods;
use cdk::HttpClient;
use clap::Args;
use url::Url;
Expand Down
27 changes: 16 additions & 11 deletions crates/cdk-integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use cdk::cdk_lightning::MintLightning;
use cdk::dhke::construct_proofs;
use cdk::mint::FeeReserve;
use cdk::nuts::{
CurrencyUnit, Id, KeySet, MeltMethodSettings, MintInfo, MintMethodSettings, MintQuoteState,
Nuts, PaymentMethod, PreMintSecrets, Proofs, State,
CurrencyUnit, Id, KeySet, MeltMethodSettings, MintBolt11Request, MintInfo, MintMethodSettings,
MintQuoteBolt11Request, MintQuoteState, Nuts, PaymentMethod, PreMintSecrets, Proofs, State,
};
use cdk::types::{LnKey, QuoteTTL};
use cdk::wallet::client::HttpClient;
use cdk::wallet::client::{HttpClient, HttpClientMethods};
use cdk::{Mint, Wallet};
use cdk_fake_wallet::FakeWallet;
use init_regtest::{get_mint_addr, get_mint_port, get_mint_url};
Expand Down Expand Up @@ -158,8 +158,14 @@ pub async fn mint_proofs(

let wallet_client = HttpClient::new();

let request = MintQuoteBolt11Request {
amount,
unit: CurrencyUnit::Sat,
description,
};

let mint_quote = wallet_client
.post_mint_quote(mint_url.parse()?, 1.into(), CurrencyUnit::Sat, description)
.post_mint_quote(mint_url.parse()?, request)
.await?;

println!("Please pay: {}", mint_quote.request);
Expand All @@ -179,13 +185,12 @@ pub async fn mint_proofs(

let premint_secrets = PreMintSecrets::random(keyset_id, amount, &SplitTarget::default())?;

let mint_response = wallet_client
.post_mint(
mint_url.parse()?,
&mint_quote.quote,
premint_secrets.clone(),
)
.await?;
let request = MintBolt11Request {
quote: mint_quote.quote,
outputs: premint_secrets.blinded_messages(),
};

let mint_response = wallet_client.post_mint(mint_url.parse()?, request).await?;

let pre_swap_proofs = construct_proofs(
mint_response.signatures,
Expand Down
22 changes: 12 additions & 10 deletions crates/cdk-integration-tests/tests/fake_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ use bip39::Mnemonic;
use cdk::{
amount::SplitTarget,
cdk_database::WalletMemoryDatabase,
nuts::{CurrencyUnit, MeltQuoteState, PreMintSecrets, State},
wallet::{client::HttpClient, Wallet},
nuts::{CurrencyUnit, MeltBolt11Request, MeltQuoteState, PreMintSecrets, State},
wallet::{
client::{HttpClient, HttpClientMethods},
Wallet,
},
};
use cdk_fake_wallet::{create_fake_invoice, FakeInvoiceDescription};
use cdk_integration_tests::attempt_to_swap_pending;
Expand Down Expand Up @@ -354,14 +357,13 @@ async fn test_fake_melt_change_in_quote() -> Result<()> {

let client = HttpClient::new();

let melt_response = client
.post_melt(
MINT_URL.parse()?,
melt_quote.id.clone(),
proofs.clone(),
Some(premint_secrets.blinded_messages()),
)
.await?;
let melt_request = MeltBolt11Request {
quote: melt_quote.id.clone(),
inputs: proofs.clone(),
outputs: Some(premint_secrets.blinded_messages()),
};

let melt_response = client.post_melt(MINT_URL.parse()?, melt_request).await?;

assert!(melt_response.change.is_some());

Expand Down
22 changes: 14 additions & 8 deletions crates/cdk-integration-tests/tests/regtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ use bip39::Mnemonic;
use cdk::{
amount::{Amount, SplitTarget},
cdk_database::WalletMemoryDatabase,
nuts::{CurrencyUnit, MeltQuoteState, MintQuoteState, PreMintSecrets, State},
wallet::{client::HttpClient, Wallet},
nuts::{
CurrencyUnit, MeltQuoteState, MintBolt11Request, MintQuoteState, PreMintSecrets, State,
},
wallet::{
client::{HttpClient, HttpClientMethods},
Wallet,
},
};
use cdk_integration_tests::init_regtest::{get_mint_url, init_cln_client, init_lnd_client};
use lightning_invoice::Bolt11Invoice;
Expand Down Expand Up @@ -289,15 +294,16 @@ async fn test_cached_mint() -> Result<()> {
let premint_secrets =
PreMintSecrets::random(active_keyset_id, 31.into(), &SplitTarget::default()).unwrap();

let request = MintBolt11Request {
quote: quote.id,
outputs: premint_secrets.blinded_messages(),
};

let response = http_client
.post_mint(
get_mint_url().as_str().parse()?,
&quote.id,
premint_secrets.clone(),
)
.post_mint(get_mint_url().as_str().parse()?, request.clone())
.await?;
let response1 = http_client
.post_mint(get_mint_url().as_str().parse()?, &quote.id, premint_secrets)
.post_mint(get_mint_url().as_str().parse()?, request)
.await?;

assert!(response == response1);
Expand Down
4 changes: 2 additions & 2 deletions crates/cdk/src/nuts/nut03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ pub struct PreSwap {
pub fee: Amount,
}

/// Split Request [NUT-06]
/// Swap Request [NUT-03]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
pub struct SwapRequest {
/// Proofs that are to be spent in `Split`
/// Proofs that are to be spent in a `Swap`
#[cfg_attr(feature = "swagger", schema(value_type = Vec<Proof>))]
pub inputs: Proofs,
/// Blinded Messages for Mint to sign
Expand Down
Loading
Loading