wally_psbt_to_bytes() difficult to use
Without any way of knowing the length to allocate, how do we call wally_psbt_to_bytes?
For the moment, we allocate 1k and loop, doubling each time. But worse, it returns WALLY_EINVAL for reasons OTHER than "you didn't give enough room".
There are two ways of fixing this:
- Expose psbt_get_length(). This is inefficient.
- Change the semantics of bytes_written to "bytes_needed", and set it to the number of bytes you want. Then return WALLY_ENOMEM to distinguish from unrelated errors.
The second allows a more optimal implementation in future.
Isn't psbt_get_length() already exposed?
Change the semantics of bytes_written to "bytes_needed", and set it to the number of bytes you want. Then return WALLY_ENOMEM to distinguish from unrelated errors.
I don't quite understand this. Do you mean that wally_psbt_to_bytes should compute how many bytes are needed and return that if the buffer is big enough (i.e. output the result of psbt_get_length)?