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

Method WriteBlock

src/index/txindex.cpp:57–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55TxIndex::~TxIndex() {}
56
57bool TxIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
58{
59 // Exclude genesis block transaction because outputs are not spendable.
60 //ELEMENTS: we do index the genesis block
61 //if (pindex->nHeight == 0) return true;
62
63 CDiskTxPos pos{
64 WITH_LOCK(::cs_main, return pindex->GetBlockPos()),
65 GetSizeOfCompactSize(block.vtx.size())};
66 std::vector<std::pair<uint256, CDiskTxPos>> vPos;
67 vPos.reserve(block.vtx.size());
68 for (const auto& tx : block.vtx) {
69 vPos.emplace_back(tx->GetHash(), pos);
70 pos.nTxOffset += ::GetSerializeSize(*tx, CLIENT_VERSION);
71 }
72 return m_db->WriteTxs(vPos);
73}
74
75BaseIndex::DB& TxIndex::GetDB() const { return *m_db; }
76

Callers

nothing calls this directly

Calls 7

GetSizeOfCompactSizeFunction · 0.85
GetSerializeSizeFunction · 0.85
emplace_backMethod · 0.80
WriteTxsMethod · 0.80
sizeMethod · 0.45
reserveMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected