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

Method GetWitnessOnlyHash

src/primitives/transaction.cpp:95–120  ·  view source on GitHub ↗

ELEMENTS ONLY

Source from the content-addressed store, hash-verified

93
94// ELEMENTS ONLY
95uint256 CTransaction::GetWitnessOnlyHash() const
96{
97 assert(g_con_elementsmode);
98
99 std::vector<uint256> leaves;
100 leaves.reserve(std::max(vin.size(), vout.size()));
101 /* Inputs */
102 for (size_t i = 0; i < vin.size(); ++i) {
103 // Input has no witness OR is null input(coinbase)
104 const CTxInWitness& txinwit = (witness.vtxinwit.size() <= i || vin[i].prevout.IsNull()) ? CTxInWitness() : witness.vtxinwit[i];
105 leaves.push_back(txinwit.GetHash());
106 }
107 uint256 hashIn = ComputeFastMerkleRoot(leaves);
108 leaves.clear();
109 /* Outputs */
110 for (size_t i = 0; i < vout.size(); ++i) {
111 const CTxOutWitness& txoutwit = witness.vtxoutwit.size() <= i ? CTxOutWitness() : witness.vtxoutwit[i];
112 leaves.push_back(txoutwit.GetHash());
113 }
114 uint256 hashOut = ComputeFastMerkleRoot(leaves);
115 leaves.clear();
116 /* Combined */
117 leaves.push_back(hashIn);
118 leaves.push_back(hashOut);
119 return ComputeFastMerkleRoot(leaves);
120}
121
122CTransaction::CTransaction(const CMutableTransaction& tx) :
123 vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nLockTime(tx.nLockTime), witness(tx.witness), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {}

Callers 2

TxToUnivFunction · 0.80
BlockWitnessMerkleRootFunction · 0.80

Calls 9

ComputeFastMerkleRootFunction · 0.85
CTxInWitnessClass · 0.70
CTxOutWitnessClass · 0.70
reserveMethod · 0.45
sizeMethod · 0.45
IsNullMethod · 0.45
push_backMethod · 0.45
GetHashMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected