mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-05 21:26:13 +01:00
fix: send proofs with conditions
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user