| 78 | } |
| 79 | |
| 80 | static int verify_script(const unsigned char *hash_genesis_block, |
| 81 | const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, CConfidentialValue amount, |
| 82 | const unsigned char *txTo , unsigned int txToLen, |
| 83 | unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err) |
| 84 | { |
| 85 | if (!verify_flags(flags)) { |
| 86 | return set_error(err, bitcoinconsensus_ERR_INVALID_FLAGS); |
| 87 | } |
| 88 | try { |
| 89 | TxInputStream stream(PROTOCOL_VERSION, txTo, txToLen); |
| 90 | CTransaction tx(deserialize, stream); |
| 91 | if (nIn >= tx.vin.size()) |
| 92 | return set_error(err, bitcoinconsensus_ERR_TX_INDEX); |
| 93 | if (GetSerializeSize(tx, PROTOCOL_VERSION) != txToLen) |
| 94 | return set_error(err, bitcoinconsensus_ERR_TX_SIZE_MISMATCH); |
| 95 | |
| 96 | // Regardless of the verification result, the tx did not error. |
| 97 | set_error(err, bitcoinconsensus_ERR_OK); |
| 98 | |
| 99 | auto hash_genesis_block_ = hash_genesis_block ? uint256{hash_genesis_block, 32} : uint256{}; |
| 100 | PrecomputedTransactionData txdata(hash_genesis_block_); |
| 101 | txdata.Init(tx, {}); |
| 102 | const CScriptWitness* pScriptWitness = (tx.witness.vtxinwit.size() > nIn ? &tx.witness.vtxinwit[nIn].scriptWitness : NULL); |
| 103 | return VerifyScript(tx.vin[nIn].scriptSig, CScript(scriptPubKey, scriptPubKey + scriptPubKeyLen), pScriptWitness, flags, TransactionSignatureChecker(&tx, nIn, amount, txdata, MissingDataBehavior::FAIL), nullptr); |
| 104 | } catch (const std::exception&) { |
| 105 | return set_error(err, bitcoinconsensus_ERR_TX_DESERIALIZE); // Error deserializing |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | int bitcoinconsensus_verify_script_with_amount(const unsigned char *hash_genesis_block, |
| 110 | const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, |
no test coverage detected