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
WitnessVersion type #617
WitnessVersion type #617
Conversation
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.
utACK 3645c63
Looks pretty good. I really like the function documentation describing all error cases applicable to the function (especially when it's only a subset of the error enum).
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.
You mentioned here about using WitnessVersion in the is_* methods on Script. Don't know if you want to do that here.
@jrawsthorne well, tried that and it looks like it adds a lot more code instead of simplifying functions. So just made it for 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.
I prefer this approach, since it "makes impossible states impossible." I've just got a couple preference nits.
src/util/address.rs
Outdated
/// # Errors | ||
/// If the integer does not corresponds to any witness version, errors with | ||
/// [`Error::InvalidWitnessVersion`] | ||
pub fn from_no(no: u8) -> Result<Self, Error> { |
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.
Nit: use num
instead of no
for a number variable? Also, this function would probably be better named from_u8
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 was originally named from_u8
, but later I decided it is a bad name, since there are two different u8-based representations for witness version: by script byte (0
, 0x51
-0x60
) and as version number (incremental from 0 to 16). So while I'm fine with using from_num
instead of from_no
, it will be confusing to use from_u8
.
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.
Possibly raw_num
or raw_u8
?
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.
+1 for num instead of no
src/util/address.rs
Outdated
/// NB: this is not the same as an integer representation of the opcode signifying witness | ||
/// version in bitcoin script. Thus, there is no function to directly convert witness version | ||
/// into a byte since the conversion requires context (bitcoin script or just a version number) | ||
pub fn into_no(self) -> u8 { |
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.
Nit: I would prefer into_u8
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.
Commented above: the same reason for the naming here
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.
Just a few doc suggestions.
src/util/address.rs
Outdated
/// | ||
/// Structure helps to limit possible version of the witness according to the | ||
/// specification; if a plain `u8` type will be used instead it will mean that | ||
/// version > 16, which is incorrect. |
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.
Did you mean to say "if a plain u8
type was used instead it would mean that version may be > 16, which is incorrect"?
src/util/address.rs
Outdated
type Err = Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
let version = u8::from_str(s).map_err(|err| Error::UnparsableWitnessVersion(err))?; |
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 believe s.parse::<u8>()
is considered idiomatic.
src/util/address.rs
Outdated
@@ -329,7 +499,7 @@ impl Address { | |||
} | |||
|
|||
/// Check whether or not the address is following Bitcoin | |||
/// standardness rules. | |||
/// standard rules. |
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.
Not a native speaker but the original seemed correct. The rules check if the address is standard.
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.
Agreed.
Addressed all suggestions with a separate commit |
@@ -159,8 +159,8 @@ impl FromStr for AddressType { | |||
/// to 16 (inclusive). | |||
/// | |||
/// Structure helps to limit possible version of the witness according to the | |||
/// specification; if a plain `u8` type will be used instead it will mean that | |||
/// version > 16, which is incorrect. | |||
/// specification; if a plain `u8` type was be used instead it would mean that |
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.
Nit: "was be"
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.
ack 4ecfd68
Needed rebase, merged master into this branch so the review will not require to go through all commits again. Also fixed @Kixunil nit in docs. Ned re-ACK from @sanket1729 and review from @apoelstra before the merge since this is intrusive and important change |
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.
utACK 409cb91
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.
utACK 8a99a3f
Can you clean up the history by removing the merge commit and rebasing on top of master? |
ack 8a99a3f aside from history |
@apoelstra done |
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.
ACK a8571f2
@sanket1729 @sgeisler had to force-push due to conflicts with recent merges. Re-ACK will be highly appreciated |
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.
re-ACK ecc4008
Just looked at the diff-diff using git range-diff 8a99a3f...ecc400826c5eebf4c8bf3f28219af348a1ba0191
re-utACK ecc4008 |
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.
ACK ecc4008
Reopening as a new PR to #562 (github does not allow to re-open force-pushed branches) since there might be changes during the review at this level unrelated to #563 (which will be in draft mode until this is merged - and rebased after the merge)