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

Provide sorting method for selecting proofs to swap #387

Closed
Closed
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
8 changes: 6 additions & 2 deletions crates/cdk/examples/proof-selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::time::Duration;
use cdk::amount::SplitTarget;
use cdk::cdk_database::WalletMemoryDatabase;
use cdk::nuts::{CurrencyUnit, MintQuoteState};
use cdk::wallet::Wallet;
use cdk::wallet::{SelectProofsOptions, Wallet};
use cdk::Amount;
use rand::Rng;
use tokio::time::sleep;
Expand Down Expand Up @@ -51,7 +51,11 @@ async fn main() {
let proofs = wallet.get_proofs().await.unwrap();

let selected = wallet
.select_proofs_to_send(Amount::from(64), proofs, false)
.select_proofs(
Amount::from(64),
proofs,
SelectProofsOptions::default().include_fees(false),
)
.await
.unwrap();

Expand Down
10 changes: 10 additions & 0 deletions crates/cdk/src/nuts/nut01/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ impl PublicKey {
SECP256K1.verify_schnorr(sig, &msg, &self.inner.x_only_public_key().0)?;
Ok(())
}

#[cfg(test)]
pub fn random() -> Self {
Self {
inner: secp256k1::PublicKey::from_secret_key(
&SECP256K1,
&secp256k1::SecretKey::new(&mut rand::thread_rng()),
),
}
}
}

impl FromStr for PublicKey {
Expand Down
8 changes: 8 additions & 0 deletions crates/cdk/src/nuts/nut02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ impl Id {
id: bytes[1..].try_into()?,
})
}

#[cfg(test)]
pub fn random() -> Self {
Self {
version: KeySetVersion::Version00,
id: rand::random(),
}
}
}

impl TryFrom<Id> for u64 {
Expand Down
8 changes: 6 additions & 2 deletions crates/cdk/src/wallet/melt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
Amount, Error, Wallet,
};

use super::MeltQuote;
use super::{proofs::SelectProofsOptions, MeltQuote};

impl Wallet {
/// Melt Quote
Expand Down Expand Up @@ -294,7 +294,11 @@ impl Wallet {
let available_proofs = self.get_proofs().await?;

let input_proofs = self
.select_proofs_to_swap(inputs_needed_amount, available_proofs)
.select_proofs(
inputs_needed_amount,
available_proofs,
SelectProofsOptions::default(),
)
.await?;

self.melt_proofs(quote_id, input_proofs).await
Expand Down
1 change: 1 addition & 0 deletions crates/cdk/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub mod types;
pub mod util;

pub use multi_mint_wallet::MultiMintWallet;
pub use proofs::{ProofSelectionMethod, SelectProofsOptions};
pub use types::{MeltQuote, MintQuote, SendKind};

/// CDK Wallet
Expand Down
Loading
Loading