| 156 | } |
| 157 | |
| 158 | TxoutType 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; |