mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-29 18:20:58 +02:00
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.
This commit is contained in:
@ -155,15 +155,14 @@ TxoutType Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned c
|
|||||||
std::vector<unsigned char> witnessprogram;
|
std::vector<unsigned char> witnessprogram;
|
||||||
if (scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) {
|
if (scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) {
|
||||||
if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_KEYHASH_SIZE) {
|
if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_KEYHASH_SIZE) {
|
||||||
vSolutionsRet.push_back(witnessprogram);
|
vSolutionsRet.push_back(std::move(witnessprogram));
|
||||||
return TxoutType::WITNESS_V0_KEYHASH;
|
return TxoutType::WITNESS_V0_KEYHASH;
|
||||||
}
|
}
|
||||||
if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_SCRIPTHASH_SIZE) {
|
if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_SCRIPTHASH_SIZE) {
|
||||||
vSolutionsRet.push_back(witnessprogram);
|
vSolutionsRet.push_back(std::move(witnessprogram));
|
||||||
return TxoutType::WITNESS_V0_SCRIPTHASH;
|
return TxoutType::WITNESS_V0_SCRIPTHASH;
|
||||||
}
|
}
|
||||||
if (witnessversion == 1 && witnessprogram.size() == WITNESS_V1_TAPROOT_SIZE) {
|
if (witnessversion == 1 && witnessprogram.size() == WITNESS_V1_TAPROOT_SIZE) {
|
||||||
vSolutionsRet.push_back(std::vector<unsigned char>{(unsigned char)witnessversion});
|
|
||||||
vSolutionsRet.push_back(std::move(witnessprogram));
|
vSolutionsRet.push_back(std::move(witnessprogram));
|
||||||
return TxoutType::WITNESS_V1_TAPROOT;
|
return TxoutType::WITNESS_V1_TAPROOT;
|
||||||
}
|
}
|
||||||
@ -242,8 +241,17 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
|
|||||||
addressRet = hash;
|
addressRet = hash;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case TxoutType::WITNESS_UNKNOWN:
|
|
||||||
case TxoutType::WITNESS_V1_TAPROOT: {
|
case TxoutType::WITNESS_V1_TAPROOT: {
|
||||||
|
/* For now, no WitnessV1Taproot variant in CTxDestination exists, so map
|
||||||
|
* this to WitnessUnknown. */
|
||||||
|
WitnessUnknown unk;
|
||||||
|
unk.version = 1;
|
||||||
|
std::copy(vSolutions[0].begin(), vSolutions[0].end(), unk.program);
|
||||||
|
unk.length = vSolutions[0].size();
|
||||||
|
addressRet = unk;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case TxoutType::WITNESS_UNKNOWN: {
|
||||||
WitnessUnknown unk;
|
WitnessUnknown unk;
|
||||||
unk.version = vSolutions[0][0];
|
unk.version = vSolutions[0][0];
|
||||||
std::copy(vSolutions[1].begin(), vSolutions[1].end(), unk.program);
|
std::copy(vSolutions[1].begin(), vSolutions[1].end(), unk.program);
|
||||||
|
@ -111,9 +111,8 @@ BOOST_AUTO_TEST_CASE(script_standard_Solver_success)
|
|||||||
s.clear();
|
s.clear();
|
||||||
s << OP_1 << ToByteVector(uint256::ZERO);
|
s << OP_1 << ToByteVector(uint256::ZERO);
|
||||||
BOOST_CHECK_EQUAL(Solver(s, solutions), TxoutType::WITNESS_V1_TAPROOT);
|
BOOST_CHECK_EQUAL(Solver(s, solutions), TxoutType::WITNESS_V1_TAPROOT);
|
||||||
BOOST_CHECK_EQUAL(solutions.size(), 2U);
|
BOOST_CHECK_EQUAL(solutions.size(), 1U);
|
||||||
BOOST_CHECK(solutions[0] == std::vector<unsigned char>{1});
|
BOOST_CHECK(solutions[0] == ToByteVector(uint256::ZERO));
|
||||||
BOOST_CHECK(solutions[1] == ToByteVector(uint256::ZERO));
|
|
||||||
|
|
||||||
// TxoutType::WITNESS_UNKNOWN
|
// TxoutType::WITNESS_UNKNOWN
|
||||||
s.clear();
|
s.clear();
|
||||||
|
Reference in New Issue
Block a user