cashubtc / cashu-ts

A TypeScript library for building Cashu wallets
MIT License
60 stars 35 forks source link

NUT-08 dynamic output count log(0) #79

Closed callebtc closed 10 months ago

callebtc commented 1 year ago

If the fee reserve is 0 sat, the log will fail. Therefore

def calculate_number_of_blank_outputs(fee_reserve_sat: int):
    assert fee_reserve_sat >= 0, "Fee reserve can't be negative."
    if fee_reserve_sat == 0:
        return 0
    return max(math.ceil(math.log2(fee_reserve_sat)), 1)
gandlafbtc commented 1 year ago

The code in cashu-ts runs as per protocol, but it is not so straight forward to follow why. I think it would make sense to implement it in the way @callebtc proposed.

Right now:

0 -> -Infinity this works because -infinity will be smaller than 0 and we won't enter the loop. So 0 messages get created 1 -> 0 which equates to falsy and thus we return 1 and create one message

changing to the code proposed would make it easier to understand what's happening

BilligsterUser commented 1 year ago

A Test with 0 Fee https://github.com/cashubtc/cashu-ts/blob/126013a7d38f03b7e035b912b73c731fd3d7005a/test/wallet.test.ts#L162

BilligsterUser commented 1 year ago

changing to the code proposed would make it easier to understand what's happening

We have a test and its works soo.... 😜😅

callebtc commented 1 year ago

changing to the code proposed would make it easier to understand what's happening

We have a test and its works soo.... 😜😅

Never argue with JS! 🫨

BilligsterUser commented 1 year ago

changing to the code proposed would make it easier to understand what's happening

We have a test and its works soo.... 😜😅

Never argue with JS! 🫨

Never argue with my tests