| 139 | } |
| 140 | |
| 141 | TxoutType 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 | } |