-
Notifications
You must be signed in to change notification settings - Fork 831
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
Conversation
src/blockdata/script.rs
Outdated
ExactSizeIterator + | ||
DoubleEndedIterator, | ||
{ | ||
Ok(Script(Vec::from_byte_iter(iter)?.into())) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
cr-ack |
tAck 105d8414b6d37e96b1ce93d109cdb13e97d0e668. Idk why CI is failing for 1.29, also there is a unrelated warning while compiling. |
105d841
to
674544d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
atACK
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())); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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
No, ASM is unparseable because numbers are encoded in decimal or hex with no indication as to which is which. |
Fixes #523