mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-31 11:35:17 +01:00
dynamic change tokens
This commit is contained in:
@@ -40,7 +40,14 @@ async fn main() {
|
||||
let spendable = test_check_spendable(&client, &new_token).await;
|
||||
let proofs = test_send(&wallet, spendable).await;
|
||||
|
||||
test_melt(&wallet, Invoice::from_str(MELTINVOICE).unwrap(), proofs).await;
|
||||
test_melt(
|
||||
&wallet,
|
||||
Invoice::from_str(MELTINVOICE).unwrap(),
|
||||
proofs,
|
||||
// TODO:
|
||||
10,
|
||||
)
|
||||
.await;
|
||||
|
||||
test_check_fees(&client).await;
|
||||
}
|
||||
@@ -152,8 +159,8 @@ async fn test_send(wallet: &CashuWallet, proofs: Proofs) -> Proofs {
|
||||
send.send_proofs
|
||||
}
|
||||
|
||||
async fn test_melt(wallet: &CashuWallet, invoice: Invoice, proofs: Proofs) {
|
||||
let res = wallet.melt(invoice, proofs).await.unwrap();
|
||||
async fn test_melt(wallet: &CashuWallet, invoice: Invoice, proofs: Proofs, fee_reserve: u64) {
|
||||
let res = wallet.melt(invoice, proofs, fee_reserve).await.unwrap();
|
||||
|
||||
println!("{:?}", res);
|
||||
}
|
||||
|
||||
@@ -220,8 +220,13 @@ impl CashuWallet {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn melt(&self, invoice: Invoice, proofs: Proofs) -> Result<Melted, Error> {
|
||||
let change = BlindedMessages::blank()?;
|
||||
pub async fn melt(
|
||||
&self,
|
||||
invoice: Invoice,
|
||||
proofs: Proofs,
|
||||
fee_reserve: u64,
|
||||
) -> Result<Melted, Error> {
|
||||
let change = BlindedMessages::blank(fee_reserve)?;
|
||||
let melt_response = self
|
||||
.client
|
||||
.melt(proofs, invoice, Some(change.blinded_messages))
|
||||
|
||||
15
src/types.rs
15
src/types.rs
@@ -60,10 +60,12 @@ impl BlindedMessages {
|
||||
}
|
||||
|
||||
/// Blank Outputs used for NUT-08 change
|
||||
pub fn blank() -> Result<Self, Error> {
|
||||
pub fn blank(fee_reserve: u64) -> Result<Self, Error> {
|
||||
let mut blinded_messages = BlindedMessages::default();
|
||||
|
||||
for _i in 0..4 {
|
||||
let count = ((fee_reserve as f64).log2().ceil() as u64).max(1);
|
||||
|
||||
for _i in 0..count {
|
||||
let secret = generate_secret();
|
||||
let (blinded, r) = blind_message(secret.as_bytes(), None)?;
|
||||
|
||||
@@ -385,4 +387,13 @@ mod tests {
|
||||
|
||||
assert_eq!(token_data, token);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blank_blinded_messages() {
|
||||
let b = BlindedMessages::blank(1000).unwrap();
|
||||
assert_eq!(b.blinded_messages.len(), 10);
|
||||
|
||||
let b = BlindedMessages::blank(1).unwrap();
|
||||
assert_eq!(b.blinded_messages.len(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user