MCPcopy Create free account
hub / github.com/ElementsProject/elements / verify_script

Function verify_script

src/script/bitcoinconsensus.cpp:80–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80static 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
109int bitcoinconsensus_verify_script_with_amount(const unsigned char *hash_genesis_block,
110 const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen,

Calls 7

verify_flagsFunction · 0.85
GetSerializeSizeFunction · 0.85
VerifyScriptFunction · 0.85
set_errorFunction · 0.70
CScriptClass · 0.70
sizeMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected