Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wally_psbt_to_bytes() difficult to use #187

Open
rustyrussell opened this issue May 15, 2020 · 1 comment
Open

wally_psbt_to_bytes() difficult to use #187

rustyrussell opened this issue May 15, 2020 · 1 comment

Comments

@rustyrussell
Copy link
Contributor

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:

  1. Expose psbt_get_length(). This is inefficient.
  2. 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.

@rustyrussell rustyrussell changed the title wally_psbt_to_bytes() is almost unusable. wally_psbt_to_bytes() difficult to use May 15, 2020
@achow101
Copy link
Contributor

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)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants