Skip to content
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

Modernize code: use std::optional instead of bool/outarg #114

Merged
merged 1 commit into from
Apr 21, 2022
Merged

Conversation

sipa
Copy link
Owner

@sipa sipa commented Apr 5, 2022

Built on top of #106.

}

bool ParseScriptNumber(const std::pair<opcodetype, std::vector<unsigned char>>& in, int64_t& k) {
std::optional<int64_t> ParseScriptNumber(const std::pair<opcodetype, std::vector<unsigned char>>& in) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You missed some call sites, such as:

if (!ParseScriptNumber(in[1], n)) return {};

@@ -77,13 +77,12 @@ struct TestData {
struct ParserContext {
typedef CPubKey Key;

bool ToString(const Key& key, std::string& ret) const
std::optional<std::string> ToString(const Key& key, std::string& ret) const
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to remove the out argument, too.

Copy link
Contributor

@darosior darosior left a comment

Choose a reason for hiding this comment

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

To make a comprehensive list of the missing call sites from these changes:

  • thresh parsing
  • multi parsing
  • miniscript_string usage of ToString
  • the KeyConverter in the unit tests

From my branch which has this included in Bitcoin Core on which i could actually compile.
Looks good to me otherwise, nice cleanup!

@sipa
Copy link
Owner Author

sipa commented Apr 20, 2022

Rebased, and addressed comments.

I've also made a few additional changes; turning inline "&& (num = ParseScriptNum(...)) &&" conditions into separate lines.

@darosior
Copy link
Contributor

ACK 033238f

Checked the diff with my Bitcoin Core branch that i tested quite a lot. I didn't look for more potentially missed called sites too hard.

@sipa sipa merged commit 2a51412 into master Apr 21, 2022
sipa added a commit that referenced this pull request Apr 21, 2022
13edbef miniscript: mark nodes with duplicate keys as insane (Antoine Poinsot)

Pull request description:

  Based off a rebased #114

ACKs for top commit:
  sipa:
    utACK 13edbef

Tree-SHA512: 729ff124f1a320f91069cde35b90d313faca012b122255e9b247a05d6e912e5422245dfde0f7881e0205cf8a537d390499cb3f8728e908d8ffe467dd8448eb40
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.

2 participants