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

Function GetBlockAndTxFromMerkleBlock

src/pegins.cpp:202–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200
201template<typename T>
202static bool GetBlockAndTxFromMerkleBlock(uint256& block_hash, uint256& tx_hash, unsigned int& tx_index, T& merkle_block, const std::vector<unsigned char>& merkle_block_raw)
203{
204 try {
205 std::vector<uint256> tx_hashes;
206 std::vector<unsigned int> tx_indices;
207 CDataStream merkle_block_stream(merkle_block_raw, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
208 merkle_block_stream >> merkle_block;
209 block_hash = merkle_block.header.GetHash();
210
211 if (!merkle_block_stream.empty()) {
212 return false;
213 }
214 if (merkle_block.txn.ExtractMatches(tx_hashes, tx_indices) != merkle_block.header.hashMerkleRoot || tx_hashes.size() != 1) {
215 return false;
216 }
217 tx_hash = tx_hashes[0];
218 tx_index = tx_indices[0];
219 } catch (std::exception&) {
220 // Invalid encoding of merkle block
221 return false;
222 }
223 return true;
224}
225
226bool CheckParentProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params)
227{

Callers 1

IsValidPeginWitnessFunction · 0.85

Calls 4

GetHashMethod · 0.45
emptyMethod · 0.45
ExtractMatchesMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected