* Return public keys or hashes from scriptPubKey, for 'standard' transaction types. */
| 60 | * Return public keys or hashes from scriptPubKey, for 'standard' transaction types. |
| 61 | */ |
| 62 | bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsigned char> >& vSolutionsRet, bool contractConsensus) |
| 63 | { |
| 64 | //contractConsesus is true when evaluating if a contract tx is "standard" for consensus purposes |
| 65 | //It is false in all other cases, so to prevent a particular contract tx from being broadcast on mempool, but allowed in blocks, |
| 66 | //one should ensure that contractConsensus is false |
| 67 | |
| 68 | // Templates |
| 69 | static multimap<txnouttype, CScript> mTemplates; |
| 70 | if (mTemplates.empty()) |
| 71 | { |
| 72 | // Standard tx, sender provides pubkey, receiver adds signature |
| 73 | mTemplates.insert(make_pair(TX_PUBKEY, CScript() << OP_PUBKEY << OP_CHECKSIG)); |
| 74 | |
| 75 | // Bitcoin address tx, sender provides hash of pubkey, receiver provides signature and pubkey |
| 76 | mTemplates.insert(make_pair(TX_PUBKEYHASH, CScript() << OP_DUP << OP_HASH160 << OP_PUBKEYHASH << OP_EQUALVERIFY << OP_CHECKSIG)); |
| 77 | |
| 78 | // Sender provides N pubkeys, receivers provides M signatures |
| 79 | mTemplates.insert(make_pair(TX_MULTISIG, CScript() << OP_SMALLINTEGER << OP_PUBKEYS << OP_SMALLINTEGER << OP_CHECKMULTISIG)); |
| 80 | |
| 81 | // Contract creation tx |
| 82 | mTemplates.insert(make_pair(TX_CREATE, CScript() << OP_VERSION << OP_GAS_LIMIT << OP_GAS_PRICE << OP_DATA << OP_CREATE)); |
| 83 | |
| 84 | // Call contract tx |
| 85 | mTemplates.insert(make_pair(TX_CALL, CScript() << OP_VERSION << OP_GAS_LIMIT << OP_GAS_PRICE << OP_DATA << OP_PUBKEYHASH << OP_CALL)); |
| 86 | // // Empty, provably prunable, data-carrying output |
| 87 | // if (GetBoolArg("-datacarrier", true)) |
| 88 | // mTemplates.insert(make_pair(TX_NULL_DATA, CScript() << OP_RETURN << OP_SMALLDATA)); |
| 89 | mTemplates.insert(make_pair(TX_NULL_DATA, CScript() << OP_RETURN)); |
| 90 | } |
| 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 | 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() == 20) { |
| 108 | typeRet = TX_WITNESS_V0_KEYHASH; |
| 109 | vSolutionsRet.push_back(witnessprogram); |
| 110 | return true; |
| 111 | } |
| 112 | if (witnessversion == 0 && witnessprogram.size() == 32) { |
| 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}); |