pub struct PreparedMelt<'a> { /* private fields */ }Expand description
A prepared melt operation that can be confirmed or cancelled.
Implementations§
Source§impl<'a> PreparedMelt<'a>
impl<'a> PreparedMelt<'a>
Sourcepub fn operation_id(&self) -> Uuid
pub fn operation_id(&self) -> Uuid
Get the operation ID
Sourcepub fn proofs_to_swap(&self) -> &Proofs
pub fn proofs_to_swap(&self) -> &Proofs
Get the proofs that need to be swapped
Sourcepub fn requires_swap(&self) -> bool
pub fn requires_swap(&self) -> bool
Returns true if a swap would be performed (proofs_to_swap is not empty)
Sourcepub fn total_fee_with_swap(&self) -> Amount
pub fn total_fee_with_swap(&self) -> Amount
Get the total fee if swap is performed (current default behavior)
Sourcepub fn input_fee_without_swap(&self) -> Amount
pub fn input_fee_without_swap(&self) -> Amount
Get the input fee if swap is skipped (fee on all proofs sent directly)
Sourcepub fn fee_savings_without_swap(&self) -> Amount
pub fn fee_savings_without_swap(&self) -> Amount
Get the fee savings from skipping the swap
Sourcepub fn change_amount_without_swap(&self) -> Amount
pub fn change_amount_without_swap(&self) -> Amount
Get the expected change amount if swap is skipped
Sourcepub async fn confirm(self) -> Result<FinalizedMelt, Error>
pub async fn confirm(self) -> Result<FinalizedMelt, Error>
Confirm the prepared melt and execute the payment.
This method waits for the payment to complete and returns the finalized melt. If the mint supports async payments (NUT-05), this may complete faster by not blocking on the payment processing.
§Example
use cdk::nuts::PaymentMethod;
let quote = wallet
.melt_quote(PaymentMethod::BOLT11, "lnbc...", None, None)
.await?;
// Prepare the melt
let prepared = wallet.prepare_melt("e.id, HashMap::new()).await?;
// Confirm and wait for completion
let finalized = prepared.confirm().await?;
println!(
"Melt completed: state={:?}, amount={}, fee_paid={}",
finalized.state(),
finalized.amount(),
finalized.fee_paid()
);Sourcepub async fn confirm_with_options(
self,
options: MeltConfirmOptions,
) -> Result<FinalizedMelt, Error>
pub async fn confirm_with_options( self, options: MeltConfirmOptions, ) -> Result<FinalizedMelt, Error>
Confirm the prepared melt with custom options.
This method waits for the payment to complete and returns the finalized melt. If the mint supports async payments (NUT-05), this may complete faster by not blocking on the payment processing.
Sourcepub async fn confirm_prefer_async(self) -> Result<MeltOutcome<'a>, Error>
pub async fn confirm_prefer_async(self) -> Result<MeltOutcome<'a>, Error>
Confirm the prepared melt using async support (NUT-05).
Sends the melt request with a Prefer: respond-async header and waits for the
mint’s response. Returns Paid if the payment completed immediately, or
Pending if the mint accepted the async request and will process it in the
background.
Note: This waits for the mint’s initial response, which may block if the mint
does not support async payments. Only returns Pending if the mint explicitly
supports and accepts async melt requests.
§Example
use std::collections::HashMap;
use cdk::nuts::PaymentMethod;
use cdk::wallet::MeltOutcome;
let quote = wallet
.melt_quote(PaymentMethod::BOLT11, "lnbc...", None, None)
.await?;
// Prepare the melt
let prepared = wallet.prepare_melt("e.id, HashMap::new()).await?;
// Confirm with async preference
match prepared.confirm_prefer_async().await? {
MeltOutcome::Paid(finalized) => {
println!(
"Melt completed immediately: state={:?}, amount={}, fee_paid={}",
finalized.state(),
finalized.amount(),
finalized.fee_paid()
);
}
MeltOutcome::Pending(pending) => {
// You can await the pending melt directly
let finalized = pending.await?;
println!(
"Melt completed after waiting: state={:?}, amount={}, fee_paid={}",
finalized.state(),
finalized.amount(),
finalized.fee_paid()
);
// Alternative: Instead of awaiting, you could:
// 1. Store the quote ID and check status later with:
// wallet.check_melt_quote_status("e.id).await?
// 2. Let the wallet's background task handle it via:
// wallet.finalize_pending_melts().await?
}
}Sourcepub async fn confirm_prefer_async_with_options(
self,
options: MeltConfirmOptions,
) -> Result<MeltOutcome<'a>, Error>
pub async fn confirm_prefer_async_with_options( self, options: MeltConfirmOptions, ) -> Result<MeltOutcome<'a>, Error>
Confirm with async support and custom options.
Sends the melt request with a Prefer: respond-async header and waits for the
mint’s response. Returns Paid if the payment completed immediately, or
Pending if the mint accepted the async request and will process it in the
background.
Note: This waits for the mint’s initial response, which may block if the mint
does not support async payments. Only returns Pending if the mint explicitly
supports and accepts async melt requests.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for PreparedMelt<'a>
impl<'a> !RefUnwindSafe for PreparedMelt<'a>
impl<'a> Send for PreparedMelt<'a>
impl<'a> Sync for PreparedMelt<'a>
impl<'a> Unpin for PreparedMelt<'a>
impl<'a> UnsafeUnpin for PreparedMelt<'a>
impl<'a> !UnwindSafe for PreparedMelt<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request