-
Notifications
You must be signed in to change notification settings - Fork 38.7k
refactor: Extract ParseOpCode from ParseScript #19851
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
|
When touching |
|
@practicalswift that's fine but I guess not here? |
|
ACK 7b3a0150a5e7d0cd8f31ff7bbd5a421d9020cfd1 📃
@practicalswift: Could you elaborate on why |
|
@theStack The long term plan is to remove all usages of Boost, so I thought it would be nice to take one small step in that direction when creating The unnecessary Boost usage in |
|
Ok, let's do it here. |
|
@promag: Feel free to add my commit: theStack@5dfc039 (branch https://github.com/theStack/bitcoin/tree/20200903-refactor-get-rid-of-boost-replace_first): diff --git a/src/core_read.cpp b/src/core_read.cpp
index 1829f18..155f443 100644
--- a/src/core_read.cpp
+++ b/src/core_read.cpp
@@ -15,7 +15,6 @@
#include <version.h>
#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
#include <algorithm>
@@ -40,8 +39,8 @@ opcodetype ParseOpCode(const std::string& s)
continue;
mapOpNames[strName] = static_cast<opcodetype>(op);
// Convenience: OP_ADD and just ADD are both recognized:
- boost::algorithm::replace_first(strName, "OP_", "");
- mapOpNames[strName] = static_cast<opcodetype>(op);
+ if (strName.rfind("OP_", 0) == 0)
+ mapOpNames[strName.substr(3)] = static_cast<opcodetype>(op);
}
}Another solution would be to use |
|
Code review ACK 7b3a015 |
|
Code review ACK 7b3a0150a5e7d0cd8f31ff7bbd5a421d9020cfd1 |
|
@theStack I don't think your code is equivalent. In the orignal case, both |
Hm, I guess the
Will come up with a follow-up PR then. |
7b3a015 to
539efcc
Compare
|
Decided to keep boost in this PR, don't want to drag this because of that unrelated change. Applied @laanwj suggestion. |
|
I'd suggest to adapt the expected result string for the util test case "Create a new transaction with an invalid output script": diff --git a/test/util/data/bitcoin-util-test.json b/test/util/data/bitcoin-util-test.json
index 99cd4ab..0a9846b 100644
--- a/test/util/data/bitcoin-util-test.json
+++ b/test/util/data/bitcoin-util-test.json
@@ -221,7 +221,7 @@
{ "exec": "./bitcoin-tx",
"args": ["-create", "outscript=0:123badscript"],
"return_code": 1,
- "error_txt": "error: script parse error",
+ "error_txt": "error: script parse error: unknown opcode",
"description": "Create a new transaction with an invalid output script"
},
{ "exec": "./bitcoin-tx",(The test still passes without this patch though, as matching a substring is sufficient). |
A second lookup in mapOpNames is also removed.
539efcc to
c923872
Compare
theStack
left a comment
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 c923872
@practicalswift No... rather C++ standards are preferred over Boost when appropriate, and Boost isn't allowed in libconsensus. Boost still provides many useful things the standards don't, and I doubt we will ever remove its use entirely. |
6f4e393 refactor: remove use of boost::algorithm::replace_first (Sebastian Falbesoner) Pull request description: As discussed in #19851 (#19851 (comment)), this trivial PR substitutes the (only) use of `boost::algorithm::replace_first` by a direct implementation. ACKs for top commit: laanwj: Code review ACK 6f4e393 Tree-SHA512: 2ef06498e19f864a4cbae10e8d1905e3440a2d1e8e5aae83de7597c23cdab92b4612d7fa1efbc49016e530debd127d1d50531c60ff159dbea0deaa8c836a2bfb
…e_first 6f4e393 refactor: remove use of boost::algorithm::replace_first (Sebastian Falbesoner) Pull request description: As discussed in bitcoin#19851 (bitcoin#19851 (comment)), this trivial PR substitutes the (only) use of `boost::algorithm::replace_first` by a direct implementation. ACKs for top commit: laanwj: Code review ACK 6f4e393 Tree-SHA512: 2ef06498e19f864a4cbae10e8d1905e3440a2d1e8e5aae83de7597c23cdab92b4612d7fa1efbc49016e530debd127d1d50531c60ff159dbea0deaa8c836a2bfb
|
ACK c923872 |
c923872 refactor: Extract ParseOpCode from ParseScript (João Barbosa) Pull request description: Seems more natural to have `mapOpNames` "hidden" in `ParseOpCode` than in `ParseScript`. A second lookup in `mapOpNames` is also removed. ACKs for top commit: laanwj: ACK c923872 theStack: re-ACK c923872 Tree-SHA512: d59d1964760622cf365479d44e3e676aa0bf46b60e77160140d967e012042df92121d3224c7551dc96eff5ff3294598cc6bade82adb3f60d28810e18e60e1257
…e_first 6f4e393 refactor: remove use of boost::algorithm::replace_first (Sebastian Falbesoner) Pull request description: As discussed in bitcoin#19851 (bitcoin#19851 (comment)), this trivial PR substitutes the (only) use of `boost::algorithm::replace_first` by a direct implementation. ACKs for top commit: laanwj: Code review ACK 6f4e393 Tree-SHA512: 2ef06498e19f864a4cbae10e8d1905e3440a2d1e8e5aae83de7597c23cdab92b4612d7fa1efbc49016e530debd127d1d50531c60ff159dbea0deaa8c836a2bfb
…e_first 6f4e393 refactor: remove use of boost::algorithm::replace_first (Sebastian Falbesoner) Pull request description: As discussed in bitcoin#19851 (bitcoin#19851 (comment)), this trivial PR substitutes the (only) use of `boost::algorithm::replace_first` by a direct implementation. ACKs for top commit: laanwj: Code review ACK 6f4e393 Tree-SHA512: 2ef06498e19f864a4cbae10e8d1905e3440a2d1e8e5aae83de7597c23cdab92b4612d7fa1efbc49016e530debd127d1d50531c60ff159dbea0deaa8c836a2bfb
A second lookup in mapOpNames is also removed. Github-Pull: bitcoin#19851 Rebased-From: c923872
Summary: Seems more natural to have `mapOpNames` "hidden" in `ParseOpCode` than in `ParseScript`. A second lookup in mapOpNames is also removed. This is a backport of [[bitcoin/bitcoin#19851 | core#19851]] Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D10812
Seems more natural to have
mapOpNames"hidden" inParseOpCodethan inParseScript.A second lookup in
mapOpNamesis also removed.