MCPcopy Create free account
hub / github.com/ElementsProject/elements / Solver

Function Solver

src/script/standard.cpp:158–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156}
157
158TxoutType Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned char>>& vSolutionsRet)
159{
160 vSolutionsRet.clear();
161
162 if (Params().anyonecanspend_aremine && scriptPubKey == CScript() << OP_TRUE) {
163 return TxoutType::OP_TRUE;
164 }
165
166 // Fee outputs are for elements-style transactions only
167 if (g_con_elementsmode && scriptPubKey == CScript()) {
168 return TxoutType::FEE;
169 }
170
171 // Shortcut for pay-to-script-hash, which are more constrained than the other types:
172 // it is always OP_HASH160 20 [20 byte hash] OP_EQUAL
173 if (scriptPubKey.IsPayToScriptHash())
174 {
175 std::vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22);
176 vSolutionsRet.push_back(hashBytes);
177 return TxoutType::SCRIPTHASH;
178 }
179
180 int witnessversion;
181 std::vector<unsigned char> witnessprogram;
182 if (scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) {
183 if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_KEYHASH_SIZE) {
184 vSolutionsRet.push_back(std::move(witnessprogram));
185 return TxoutType::WITNESS_V0_KEYHASH;
186 }
187 if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_SCRIPTHASH_SIZE) {
188 vSolutionsRet.push_back(std::move(witnessprogram));
189 return TxoutType::WITNESS_V0_SCRIPTHASH;
190 }
191 if (witnessversion == 1 && witnessprogram.size() == WITNESS_V1_TAPROOT_SIZE) {
192 vSolutionsRet.push_back(std::move(witnessprogram));
193 return TxoutType::WITNESS_V1_TAPROOT;
194 }
195 if (witnessversion != 0) {
196 vSolutionsRet.push_back(std::vector<unsigned char>{(unsigned char)witnessversion});
197 vSolutionsRet.push_back(std::move(witnessprogram));
198 return TxoutType::WITNESS_UNKNOWN;
199 }
200 return TxoutType::NONSTANDARD;
201 }
202
203 // Provably prunable, data-carrying output
204 //
205 // So long as script passes the IsUnspendable() test and all but the first
206 // byte passes the IsPushOnly() test we don't care what exactly is in the
207 // script.
208 if (scriptPubKey.size() >= 1 && scriptPubKey[0] == OP_RETURN && scriptPubKey.IsPushOnly(scriptPubKey.begin()+1)) {
209 return TxoutType::NULL_DATA;
210 }
211
212 std::vector<unsigned char> data;
213 if (MatchPayToPubkey(scriptPubKey, data)) {
214 vSolutionsRet.push_back(std::move(data));
215 return TxoutType::PUBKEY;

Callers 15

IsStandardFunction · 0.85
AreInputsStandardFunction · 0.85
IsMineInnerFunction · 0.85
ExtractPubKeyFunction · 0.85
TransactionChangeTypeMethod · 0.85
ProcessSubScriptMethod · 0.85
RecurseImportDataFunction · 0.85
InferScriptFunction · 0.85
ExtractDestinationFunction · 0.85
SignStepFunction · 0.85
DataFromTransactionFunction · 0.85

Calls 14

MatchPayToPubkeyFunction · 0.85
MatchPayToPubkeyHashFunction · 0.85
MatchMultisigFunction · 0.85
IsPayToScriptHashMethod · 0.80
IsWitnessProgramMethod · 0.80
IsPushOnlyMethod · 0.80
CScriptClass · 0.70
ParamsClass · 0.50
clearMethod · 0.45
beginMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by 4

BOOST_AUTO_TEST_CASEFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68
FUZZ_TARGET_INITFunction · 0.68
FUZZ_TARGET_INITFunction · 0.68