fix: send proofs with conditions

This commit is contained in:
thesimplekid
2024-08-01 06:54:25 -05:00
parent ed9762568a
commit 72bef1b852
2 changed files with 41 additions and 5 deletions

View File

@@ -47,12 +47,16 @@ async fn main() -> Result<(), Error> {
let spending_conditions = SpendingConditions::new_p2pk(secret.public_key(), None);
let bal = wallet.total_balance().await.unwrap();
println!("{}", bal);
let token = wallet
.send(
amount,
None,
Some(spending_conditions),
&SplitTarget::None,
&SplitTarget::default(),
&SendKind::default(),
false,
)
@@ -67,7 +71,7 @@ async fn main() -> Result<(), Error> {
.await
.unwrap();
println!("Redeamed locked token worth: {}", u64::from(amount));
println!("Redeemed locked token worth: {}", u64::from(amount));
Ok(())
}

View File

@@ -1029,10 +1029,42 @@ impl Wallet {
(acc1, acc2)
},
);
let available_proofs = if proofs_sum < amount {
match &conditions {
Some(conditions) => {
let available_proofs = self
.localstore
.get_proofs(
Some(mint_url.clone()),
Some(*unit),
Some(vec![State::Unspent]),
None,
)
.await?;
if proofs_sum < amount {
return Err(Error::InsufficientFunds);
}
let available_proofs = available_proofs.into_iter().map(|p| p.proof).collect();
let proofs_to_swap =
self.select_proofs_to_swap(amount, available_proofs).await?;
let proofs_with_conditions = self
.swap(
Some(amount),
SplitTarget::default(),
proofs_to_swap,
Some(conditions.clone()),
include_fees,
)
.await?;
proofs_with_conditions.ok_or(Error::InsufficientFunds)?
}
None => {
return Err(Error::InsufficientFunds);
}
}
} else {
available_proofs
};
let selected = self
.select_proofs_to_send(amount, available_proofs, include_fees)