-
Notifications
You must be signed in to change notification settings - Fork 72
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
Amount types mismatch in psbtv2.ts - PR proposal (breaking change) #115
Comments
Aaah, I flip out whenever I see I think it could make sense to use a normalizing function like: function normalizeAmount(amount: Buffer | number): Buffer {
if (Buffer.isBuffer(amount)) return amount;
else return uint64LE(amount);
} and apply it to all the setters with amounts (accepting amount = normalizeAmount(amount); so that the amount arguments would accept |
I also considered this solution. It would resolve the issue while still maintaining backwards compatibility. This could also be done with However, there is a concern regarding adding ambiguity to the arguments. What should getInputWitnessUtxo(inputIndex: number): {
readonly amount: Buffer;
readonly scriptPubKey: Buffer
} | undefined If a user sets a Honestly, this is just a minor issue. If maintaining backwards compatibility is a priority, this can be left as it is. I would be happy to submit a pull request with whatever solution you find to be the most appropriate (if any). |
The library has never been released, so I don't think it's a problem to have breaking changes. I think returning Probably, the In the latest python client library, the psbt argument now accepts a base64 string (which is internally converted from PsbtV0 to PsbtV2 if necessary), and that would probably be the safest approach; but at this time, the deserialization code isn't properly tested, so that would be too risky of a change. |
I'm converting a bitcoinjs-lib PsbtV0 object to psbtv2.ts field by field, without using serializers. Once I have obtained the signatures, I insert them back into bitcoinjs-lib, finalize the transaction, and broadcast it. If this approach is acceptable, I will submit a PR to set the |
That seems a great approach (and it doesn't prevent future improvement to the API)! |
In the current implementation, the
amount
parameter in the following declarations is sometimes defined as aBuffer
and other times as anumber
:(also
getInputWitnessUtxo
returns a Buffer for theamount
)This can cause confusion and make it easier to make errors, as the user must remember to use
uint64LE(amount)
when usingsetInputWitnessUtxo
, but not when usingsetOutputAmount
. Additionally,uint64LE
is not exposed in the API.I propose a change to consistently use
number
for theamount
parameter in both declarations, as follows:(also change
getInputWitnessUtxo
)This would simplify the API and reduce the risk of errors. However, this would be a breaking change and would require careful consideration of its impact on existing users.
Please let me know your thoughts on this proposal. Thank you for the great work on this library, I've been able to use it to spend wsh miniscripts with the Ledger with no issues at all.
The text was updated successfully, but these errors were encountered: