8000 script: add FromHex and FromStr implementations by apoelstra · Pull Request #537 · rust-bitcoin/rust-bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

script: add FromHex and FromStr implementations #537

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

Merged
merged 1 commit into from
Jan 5, 2021

Conversation

apoelstra
Copy link
Member

Fixes #523

ExactSizeIterator +
DoubleEndedIterator,
{
Ok(Script(Vec::from_byte_iter(iter)?.into()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you wish to skip the ? unrwapping... Vec::from_byte_iter(iter).map(Box<[u8]>::from).map(Script)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Yeah, I'll change to do that.

@JeremyRubin
Copy link
Contributor

cr-ack

@sanket1729
Copy link
Member
sanket1729 commented Dec 29, 2020

tAck 105d8414b6d37e96b1ce93d109cdb13e97d0e668. Idk why CI is failing for 1.29, also there is a unrelated warning while compiling.

Copy link
Collaborator
@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atACK

8000
@stevenroose
Copy link
Collaborator

utACK 674544d

@@ -169,7 +169,7 @@ macro_rules! display_from_debug {
}

#[cfg(test)]
macro_rules! hex_script (($s:expr) => ($crate::blockdata::script::Script::from(<Vec<u8> as $crate::hashes::hex::FromHex>::from_hex($s).unwrap())));
macro_rules! hex_script (($s:expr) => (<$crate::Script as ::std::str::FromStr>::from_str($s).unwrap()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering about the reason to have this macro, is it to hide the unwrap?

isn't slightly better to use in test Script::from_hex("0100").unwrap() instead of a macro call that hides the method called and it is usable only internally?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't matter because this is for test code only

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macro used to hide a pile of complicated stuff. Now it only hides the unwrap. At this point you're right that the macro serves little purpose and basically just obfuscates ... but removing it would've made the diff much bigger.

@sgeisler sgeisler closed this Jan 5, 2021
@sgeisler sgeisler reopened this Jan 5, 2021
Copy link
Contributor
@sgeisler sgeisler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it ever be sane to parse ASM? In that case I'm not sure if this FromStr is what people would expect it to be. But I guess the error type makes it clear.

ACK 674544d

@sgeisler sgeisler merged commit ffe452a into rust-bitcoin:master Jan 5, 2021
@apoelstra
Copy link
Member Author

No, ASM is unparseable because numbers are encoded in decimal or hex with no indication as to which is which.

@apoelstra apoelstra deleted the 2020-12--script-hex branch January 5, 2021 17:57
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

Successfully merging this pull request may close these issues.

script should impl from_str and from_hex (both do hex decoding)
7 participants
0