-
Notifications
You must be signed in to change notification settings - Fork 147
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
Explicitly use hex encoding in GUI to RPC API #484
Conversation
3245b2e
to
5c93535
Compare
@domob1812 This PR is ready for review. |
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.
Looks good, but please consider the comments I've added. Also I think the commit history should be squashed - all into one commit seems appropriate here to me.
src/qt/buynamespage.cpp
Outdated
params.pushKV ("name", strName); | ||
|
||
valtype vtName = valtype (strName.begin (), strName.end ()); | ||
std::string hexName = EncodeName (vtName, NameEncoding::HEX); |
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.
Maybe you could add a utility method that converts QString
to hex directly and use it here as well as in other places? The conversion is simple, but I think having an explicit method like this would improve code readability a lot.
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.
Seems this code has the same type-safety issue that you brought up in #482 (comment) . Would it be okay if I refactored this so that the string argument is in hex form rather than binary form?
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.
Yes sure.
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 decided to defer this refactor until the GUI is updated to handle hex data, and instead just added a conversion function as you requested.
src/qt/nametablemodel.cpp
Outdated
@@ -73,11 +75,17 @@ class NameTablePriv | |||
// TODO: Set name and value encoding to hex, so that nonstandard | |||
// encodings don't cause errors. |
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.
Can this TODO be removed now?
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 yet; this PR uses hex encoding for talking to the RPC API but converts back to ASCII, so encoding errors will still be an issue for now.
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.
Ok, but then I think it should be reformulated. As it is currently, it makes no sense - the TODO says "set encodings to hex", but you actually do that in the very next line.
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.
Done.
src/qt/nametablemodel.cpp
Outdated
const std::string data = maybeData.get_str(); | ||
const std::string hexName = maybeName.get_str(); | ||
const valtype vtName = DecodeName(hexName, NameEncoding::HEX); | ||
const std::string name = std::string (vtName.begin (), vtName.end ()); |
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.
Same as above, I think an explicit utility method for this conversion would be useful and improve code readability.
3854aa4
to
4c4c539
Compare
@domob1812 Addressed review, and fixed merge conflict via rebase. Feel free to proceed with review; I'll squash before you merge. |
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.
Thanks for the update, looks good. Please just consider updating the TODO text, otherwise this is good for me.
src/qt/nametablemodel.cpp
Outdated
@@ -73,11 +75,17 @@ class NameTablePriv | |||
// TODO: Set name and value encoding to hex, so that nonstandard | |||
// encodings don't cause errors. |
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.
Ok, but then I think it should be reformulated. As it is currently, it makes no sense - the TODO says "set encodings to hex", but you actually do that in the very next line.
@domob1812 Review addressed; let me know if this is ready for a squash. |
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.
Thanks for the updates. It looks good now, please just consider merging the two try-catch
blocks in both places. Then it is good to merge for me.
@domob1812 Review addressed once again; let me know if this is ready for a squash. |
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, I think this is ready for squashing and merging.
Rebased to fix merge conflict. I still need to confirm that the rebase didn't break anything, will test that in the next day or two. |
Blocked by #536 |
21fe6d3
to
922da75
Compare
#536 is merged. @domob1812 this is ready for review. |
All looks good, thanks! ACK 922da75. |
Prevents corruption issues that were happening when default encoding wasn't ASCII. Also a prereq to supporting binary data in the GUI.