| 88 | } |
| 89 | |
| 90 | bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet) |
| 91 | { |
| 92 | vSolutionsRet.clear(); |
| 93 | |
| 94 | // Shortcut for pay-to-script-hash, which are more constrained than the other types: |
| 95 | // it is always OP_HASH160 20 [20 byte hash] OP_EQUAL |
| 96 | if (scriptPubKey.IsPayToScriptHash()) |
| 97 | { |
| 98 | typeRet = TX_SCRIPTHASH; |
| 99 | std::vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22); |
| 100 | vSolutionsRet.push_back(hashBytes); |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | int witnessversion; |
| 105 | std::vector<unsigned char> witnessprogram; |
| 106 | if (scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) { |
| 107 | if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_KEYHASH_SIZE) { |
| 108 | typeRet = TX_WITNESS_V0_KEYHASH; |
| 109 | vSolutionsRet.push_back(witnessprogram); |
| 110 | return true; |
| 111 | } |
| 112 | if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_SCRIPTHASH_SIZE) { |
| 113 | typeRet = TX_WITNESS_V0_SCRIPTHASH; |
| 114 | vSolutionsRet.push_back(witnessprogram); |
| 115 | return true; |
| 116 | } |
| 117 | if (witnessversion != 0) { |
| 118 | typeRet = TX_WITNESS_UNKNOWN; |
| 119 | vSolutionsRet.push_back(std::vector<unsigned char>{(unsigned char)witnessversion}); |
| 120 | vSolutionsRet.push_back(std::move(witnessprogram)); |
| 121 | return true; |
| 122 | } |
| 123 | typeRet = TX_NONSTANDARD; |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | // Provably prunable, data-carrying output |
| 128 | // |
| 129 | // So long as script passes the IsUnspendable() test and all but the first |
| 130 | // byte passes the IsPushOnly() test we don't care what exactly is in the |
| 131 | // script. |
| 132 | if (scriptPubKey.size() >= 1 && scriptPubKey[0] == OP_RETURN && scriptPubKey.IsPushOnly(scriptPubKey.begin()+1)) { |
| 133 | typeRet = TX_NULL_DATA; |
| 134 | return true; |
| 135 | } |
| 136 | |
| 137 | std::vector<unsigned char> data; |
| 138 | if (MatchPayToPubkey(scriptPubKey, data)) { |
| 139 | typeRet = TX_PUBKEY; |
| 140 | vSolutionsRet.push_back(std::move(data)); |
| 141 | return true; |
| 142 | } |
| 143 | |
| 144 | if (MatchPayToPubkeyHash(scriptPubKey, data)) { |
| 145 | typeRet = TX_PUBKEYHASH; |
| 146 | vSolutionsRet.push_back(std::move(data)); |
| 147 | return true; |