Skip to content
New issue

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

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

Already on GitHub? # to your account

PushBytes::read_scriptint is a bit unwieldy #3479

Closed
tcharding opened this issue Oct 16, 2024 · 4 comments
Closed

PushBytes::read_scriptint is a bit unwieldy #3479

tcharding opened this issue Oct 16, 2024 · 4 comments

Comments

@tcharding
Copy link
Member

While upgrading mininscript to track master branch I found that the PushBytes::read_scriptint function is unwieldy.

Should we add this back in:

/// Decodes an integer in script(minimal CScriptNum) format.
///
/// See [`PushBytes::read_scriptint`] for documentation.
pub fn read_scriptint(v: &[u8]) -> Result<i64, Error> {
    let push = <&PushBytes>::try_from(v).map_err(|_| Error::NumericOverflow)?;
    push.read_scriptint()
}
@tcharding
Copy link
Member Author

@tcharding
Copy link
Member Author

@apoelstra
Copy link
Member

It looks like there are two places where we call this method in miniscript. One is to convert a slice from script::Instruction::PushBytes which for some reason holds a &[u8] instead of a PushBytes. Shouldn't it hold a PushBytes instead?

The other is in witness_to_scriptsig in src/util.rs which is, frankly, a bizarre method and I think it's fine if the code there is a bit unwieldy.

@tcharding
Copy link
Member Author

It looks like there are two places where we call this method in miniscript. One is to convert a slice from script::Instruction::PushBytes which for some reason holds a &[u8] instead of a PushBytes. Shouldn't it hold a PushBytes instead?

This is a bitcoin::script::Instruction::PushBytes(PushBytes) so this call site is ok.

The other is in witness_to_scriptsig in src/util.rs which is, frankly, a bizarre method and I think it's fine if the code there is a bit unwieldy.

This is the call site that caused me to raise the issue, so you've cleared it up nicely. Thanks

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

No branches or pull requests

2 participants