MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / Solver

Function Solver

src/script/solver.cpp:141–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141TxoutType Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned char>>& vSolutionsRet)
142{
143 vSolutionsRet.clear();
144
145 // Shortcut for pay-to-script-hash, which are more constrained than the other types:
146 // it is always OP_HASH160 20 [20 byte hash] OP_EQUAL
147 if (scriptPubKey.IsPayToScriptHash())
148 {
149 std::vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22);
150 vSolutionsRet.push_back(hashBytes);
151 return TxoutType::SCRIPTHASH;
152 }
153
154 int witnessversion;
155 std::vector<unsigned char> witnessprogram;
156 if (scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) {
157 if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_KEYHASH_SIZE) {
158 vSolutionsRet.push_back(std::move(witnessprogram));
159 return TxoutType::WITNESS_V0_KEYHASH;
160 }
161 if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_SCRIPTHASH_SIZE) {
162 vSolutionsRet.push_back(std::move(witnessprogram));
163 return TxoutType::WITNESS_V0_SCRIPTHASH;
164 }
165 if (witnessversion == 1 && witnessprogram.size() == WITNESS_V1_TAPROOT_SIZE) {
166 vSolutionsRet.push_back(std::move(witnessprogram));
167 return TxoutType::WITNESS_V1_TAPROOT;
168 }
169 if (scriptPubKey.IsPayToAnchor()) {
170 return TxoutType::ANCHOR;
171 }
172 if (witnessversion != 0) {
173 vSolutionsRet.push_back(std::vector<unsigned char>{(unsigned char)witnessversion});
174 vSolutionsRet.push_back(std::move(witnessprogram));
175 return TxoutType::WITNESS_UNKNOWN;
176 }
177 return TxoutType::NONSTANDARD;
178 }
179
180 // Provably prunable, data-carrying output
181 //
182 // So long as script passes the IsUnspendable() test and all but the first
183 // byte passes the IsPushOnly() test we don't care what exactly is in the
184 // script.
185 if (scriptPubKey.size() >= 1 && scriptPubKey[0] == OP_RETURN && scriptPubKey.IsPushOnly(scriptPubKey.begin()+1)) {
186 return TxoutType::NULL_DATA;
187 }
188
189 std::vector<unsigned char> data;
190 if (MatchPayToPubkey(scriptPubKey, data)) {
191 vSolutionsRet.push_back(std::move(data));
192 return TxoutType::PUBKEY;
193 }
194
195 if (MatchPayToPubkeyHash(scriptPubKey, data)) {
196 vSolutionsRet.push_back(std::move(data));
197 return TxoutType::PUBKEYHASH;
198 }

Callers 15

ScriptToUnivFunction · 0.85
ExtractDestinationFunction · 0.85
IsStandardFunction · 0.85
ExtractPubKeyFunction · 0.85
FillPSBTMethod · 0.85
AvailableCoinsFunction · 0.85
ProcessSubScriptMethod · 0.85
InferScriptFunction · 0.85
SignStepFunction · 0.85
DataFromTransactionFunction · 0.85

Calls 13

MatchPayToPubkeyFunction · 0.85
MatchPayToPubkeyHashFunction · 0.85
MatchMultisigFunction · 0.85
IsPayToScriptHashMethod · 0.80
IsPayToAnchorMethod · 0.80
IsPushOnlyMethod · 0.80
clearMethod · 0.45
beginMethod · 0.45
push_backMethod · 0.45
IsWitnessProgramMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45

Tested by 3

BOOST_AUTO_TEST_CASEFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68
GetTxoutTypeFunction · 0.68