| 71 | } // anon namespace |
| 72 | |
| 73 | static int verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, CAmount amount, |
| 74 | const unsigned char *txTo , unsigned int txToLen, |
| 75 | unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err) |
| 76 | { |
| 77 | try { |
| 78 | TxInputStream stream(SER_NETWORK, PROTOCOL_VERSION, txTo, txToLen); |
| 79 | CTransaction tx; |
| 80 | stream >> tx; |
| 81 | if (nIn >= tx.vin.size()) |
| 82 | return set_error(err, bitcoinconsensus_ERR_TX_INDEX); |
| 83 | if (tx.GetSerializeSize(SER_NETWORK, PROTOCOL_VERSION) != txToLen) |
| 84 | return set_error(err, bitcoinconsensus_ERR_TX_SIZE_MISMATCH); |
| 85 | |
| 86 | // Regardless of the verification result, the tx did not error. |
| 87 | set_error(err, bitcoinconsensus_ERR_OK); |
| 88 | PrecomputedTransactionData txdata(tx); |
| 89 | return VerifyScript(tx.vin[nIn].scriptSig, CScript(scriptPubKey, scriptPubKey + scriptPubKeyLen), nIn < tx.wit.vtxinwit.size() ? &tx.wit.vtxinwit[nIn].scriptWitness : NULL, flags, TransactionSignatureChecker(&tx, nIn, amount, txdata), NULL); |
| 90 | } catch (const std::exception&) { |
| 91 | return set_error(err, bitcoinconsensus_ERR_TX_DESERIALIZE); // Error deserializing |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | int bitcoinconsensus_verify_script_with_amount(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, int64_t amount, |
| 96 | const unsigned char *txTo , unsigned int txToLen, |
no test coverage detected