use amount type for blank messages

This commit is contained in:
thesimplekid
2023-06-14 14:56:36 -04:00
parent 97e22286b1
commit 77f5165061
3 changed files with 11 additions and 7 deletions

View File

@@ -45,7 +45,7 @@ async fn main() {
Invoice::from_str(MELTINVOICE).unwrap(),
proofs,
// TODO:
10,
Amount::from_sat(10),
)
.await;
@@ -159,7 +159,7 @@ async fn test_send(wallet: &CashuWallet, proofs: Proofs) -> Proofs {
send.send_proofs
}
async fn test_melt(wallet: &CashuWallet, invoice: Invoice, proofs: Proofs, fee_reserve: u64) {
async fn test_melt(wallet: &CashuWallet, invoice: Invoice, proofs: Proofs, fee_reserve: Amount) {
let res = wallet.melt(invoice, proofs, fee_reserve).await.unwrap();
println!("{:?}", res);

View File

@@ -224,7 +224,7 @@ impl CashuWallet {
&self,
invoice: Invoice,
proofs: Proofs,
fee_reserve: u64,
fee_reserve: Amount,
) -> Result<Melted, Error> {
let change = BlindedMessages::blank(fee_reserve)?;
let melt_response = self

View File

@@ -60,10 +60,14 @@ impl BlindedMessages {
}
/// Blank Outputs used for NUT-08 change
pub fn blank(fee_reserve: u64) -> Result<Self, Error> {
pub fn blank(fee_reserve: Amount) -> Result<Self, Error> {
let mut blinded_messages = BlindedMessages::default();
let count = ((fee_reserve as f64).log2().ceil() as u64).max(1);
let count = (fee_reserve
.to_float_in(bitcoin::Denomination::Satoshi)
.log2()
.ceil() as u64)
.max(1);
for _i in 0..count {
let secret = generate_secret();
@@ -390,10 +394,10 @@ mod tests {
#[test]
fn test_blank_blinded_messages() {
let b = BlindedMessages::blank(1000).unwrap();
let b = BlindedMessages::blank(Amount::from_sat(1000)).unwrap();
assert_eq!(b.blinded_messages.len(), 10);
let b = BlindedMessages::blank(1).unwrap();
let b = BlindedMessages::blank(Amount::from_sat(1)).unwrap();
assert_eq!(b.blinded_messages.len(), 1);
}
}