Skip to content

Commit 31df02a

Browse files
committed
Change Solver() output for WITNESS_V1_TAPROOT
This is just a small simplification to prepare for the follow-up instruction of a CTxDestination variant for taproot outputs. In the old code, WITNESS_V1_TAPROOT and WITNESS_UNKNOWN both produced {version, program} as Solver() output. Change this so that WITNESS_V1_TAPROOT produces just {program}, like WITNESS_V0_* do.
1 parent 4b1cc08 commit 31df02a

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/script/standard.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,14 @@ TxoutType Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned c
155155
std::vector<unsigned char> witnessprogram;
156156
if (scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) {
157157
if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_KEYHASH_SIZE) {
158-
vSolutionsRet.push_back(witnessprogram);
158+
vSolutionsRet.push_back(std::move(witnessprogram));
159159
return TxoutType::WITNESS_V0_KEYHASH;
160160
}
161161
if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_SCRIPTHASH_SIZE) {
162-
vSolutionsRet.push_back(witnessprogram);
162+
vSolutionsRet.push_back(std::move(witnessprogram));
163163
return TxoutType::WITNESS_V0_SCRIPTHASH;
164164
}
165165
if (witnessversion == 1 && witnessprogram.size() == WITNESS_V1_TAPROOT_SIZE) {
166-
vSolutionsRet.push_back(std::vector<unsigned char>{(unsigned char)witnessversion});
167166
vSolutionsRet.push_back(std::move(witnessprogram));
168167
return TxoutType::WITNESS_V1_TAPROOT;
169168
}
@@ -242,8 +241,17 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
242241
addressRet = hash;
243242
return true;
244243
}
245-
case TxoutType::WITNESS_UNKNOWN:
246244
case TxoutType::WITNESS_V1_TAPROOT: {
245+
/* For now, no WitnessV1Taproot variant in CTxDestination exists, so map
246+
* this to WitnessUnknown. */
247+
WitnessUnknown unk;
248+
unk.version = 1;
249+
std::copy(vSolutions[0].begin(), vSolutions[0].end(), unk.program);
250+
unk.length = vSolutions[0].size();
251+
addressRet = unk;
252+
return true;
253+
}
254+
case TxoutType::WITNESS_UNKNOWN: {
247255
WitnessUnknown unk;
248256
unk.version = vSolutions[0][0];
249257
std::copy(vSolutions[1].begin(), vSolutions[1].end(), unk.program);

src/test/script_standard_tests.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ BOOST_AUTO_TEST_CASE(script_standard_Solver_success)
111111
s.clear();
112112
s << OP_1 << ToByteVector(uint256::ZERO);
113113
BOOST_CHECK_EQUAL(Solver(s, solutions), TxoutType::WITNESS_V1_TAPROOT);
114-
BOOST_CHECK_EQUAL(solutions.size(), 2U);
115-
BOOST_CHECK(solutions[0] == std::vector<unsigned char>{1});
116-
BOOST_CHECK(solutions[1] == ToByteVector(uint256::ZERO));
114+
BOOST_CHECK_EQUAL(solutions.size(), 1U);
115+
BOOST_CHECK(solutions[0] == ToByteVector(uint256::ZERO));
117116

118117
// TxoutType::WITNESS_UNKNOWN
119118
s.clear();

0 commit comments

Comments
 (0)