Portions 0% to 100% exclusive
Hello there!
I've been using ledger for a personal project, which involves using variable portions to split money between accounts. Sometimes, all the money will be sent to one account (depending on the transaction initiated by the user), and so the calculated portion will end up as 0/100 or 100/100, which throws a 400 Bad Request because of [1].
This causes a bunch of pain, because it means I need to dynamically change the numscript code itself (or use different numscript files) to represent transactions with 1 recipient versus N recipients. As far as I can tell, the system should handle 0% and 100% portions fine, it already has to handle similar cases when remaining is zero.
What's the motivation for not allowing 0% or 100% to be valid portions? If there's no particular concern with it, I'd be happy to update the code and add plenty of tests to ensure the behavior is correct.
[1] https://github.com/formancehq/machine/blob/a89d5180092111f4a658238a64394576007742b6/core/portion.go#L26
Somewhat related: when the send amount is zero, the ledger correctly just ignores the ~transaction~ posting, I'd expect a similar behavior for 0% portions in portioned sources and destinations
Hey @bcspragu! Thanks for opening this one and the detailed case; I'll confirm this in a bit but it looks like a leftover from a pre-remaining era that we should indeed be able to change in this direction
PS: confirming there's no strong blockers on this one @bcspragu! Adding it to our todo list for the coming weeks, but don't have a strong deadline yet - if you want to try your hand at the implementation we can fast-track the review and be there for help!
Is blocking things on my end, but I wouldn't expect y'all to handle that :smile: I'll give it a go and see what I come up with
Okay, gave it a go, was pretty straightforward to add.
The PR to add support in the Numscript machine: https://github.com/formancehq/machine/pull/59 The PR to add a test to the ledger for the new behavior: https://github.com/formancehq/ledger/pull/433
Whew that was fast 🔥 @antoinegelloz @Azorlogh wanna take this one?