For those cases where the version and program are not useful.
Avoid unused locals for CScript::IsWitnessProgram #12938
pull Empact wants to merge 1 commits into bitcoin:master from Empact:test-only-iswitnessprogram changing 8 files +20 −27-
Empact commented at 4:21 AM on April 11, 2018: member
- Empact force-pushed on Apr 11, 2018
-
practicalswift commented at 10:56 AM on April 11, 2018: contributor
utACK b9f0169bcce3ca7c9d0646ddda5bf264062be87b
Nice simplification
- Empact renamed this:
Overload CScript::IsWitnessProgram with a test-only version
Avoid unused locals for CScript::IsWitnessProgram
on Apr 12, 2018 -
in src/script/script.cpp:229 in b9f0169bcc outdated
226 | @@ -227,6 +227,14 @@ bool CScript::IsWitnessProgram(int& version, std::vector<unsigned char>& program 227 | return false; 228 | } 229 | if ((size_t)((*this)[1] + 2) == this->size()) {
jimpo commented at 1:40 AM on April 13, 2018:Might as well return this directly.
Empact commented at 10:04 AM on April 13, 2018:I like that style too, but held back for the sake of simplifying review. Here's my choice if I'm to simplify the method:
static constexpr bool IsOP_N(const unsigned char op) { return (op == OP_0 || (op >= OP_1 && op <= OP_16)); } // A witness program is any valid CScript that consists of a 1-byte push opcode // followed by a data push between 2 and 40 bytes. bool CScript::IsWitnessProgram() const { return ((this->size() >= 4 && this->size() <= 42) && IsOP_N((*this)[0]) && (size_t)((*this)[1] + 2) == this->size()); }Incidentally, this matches the style of
IsPayToWitnessScriptHashandIsPayToScriptHash, above. Thoughts?
jimpo approvedjimpo commented at 1:41 AM on April 13, 2018: contributorutACK b9f0169
promag commented at 10:42 AM on April 13, 2018: memberutACK b9f0169.
meshcollider added the label Refactoring on Apr 16, 2018fanquake requested review from sipa on Apr 16, 2018Empact force-pushed on Jun 1, 2018Empact force-pushed on Jun 1, 2018Empact force-pushed on Jun 1, 2018Empact force-pushed on Jun 1, 2018sdaftuar commented at 2:17 PM on June 1, 2018: memberI am generally a concept NACK on changes like this; IMO the review burden for refactoring consensus-critical code typically outweighs the benefits.
943f3b78d6Overload CScript::IsWitnessProgram with a test-only version
For those cases where the version and program are not useful.
Empact force-pushed on Jun 1, 2018laanwj commented at 5:44 PM on June 24, 2018: memberI am generally a concept NACK on changes like this; IMO the review burden for refactoring consensus-critical code typically outweighs the benefits.
Agree, seems to risky, closing.
laanwj closed this on Jun 24, 2018Empact deleted the branch on Jul 2, 2018MarcoFalke locked this on Sep 8, 2021
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-22 06:15 UTC
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-22 06:15 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me
More mirrored repositories can be found on mirror.b10c.me