Skip to content

Commit f0a57f2

Browse files
committed
refactor: apply clang-format
1 parent 39407b8 commit f0a57f2

File tree

4 files changed

+70
-92
lines changed

4 files changed

+70
-92
lines changed

src/index/addressindex.cpp

Lines changed: 52 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
#include <index/addressindex.h>
66

7-
#include <index/addressindex_util.h>
87
#include <chainparams.h>
98
#include <clientversion.h>
109
#include <hash.h>
10+
#include <index/addressindex_util.h>
1111
#include <logging.h>
1212
#include <node/blockstorage.h>
1313
#include <undo.h>
@@ -47,8 +47,7 @@ bool AddressIndex::DB::WriteBatch(const std::vector<CAddressIndexEntry>& address
4747
}
4848

4949
bool AddressIndex::DB::ReadAddressIndex(const uint160& address_hash, const AddressType type,
50-
std::vector<CAddressIndexEntry>& entries,
51-
const int32_t start, const int32_t end)
50+
std::vector<CAddressIndexEntry>& entries, const int32_t start, const int32_t end)
5251
{
5352
std::unique_ptr<CDBIterator> pcursor(NewIterator());
5453

@@ -60,8 +59,8 @@ bool AddressIndex::DB::ReadAddressIndex(const uint160& address_hash, const Addre
6059

6160
while (pcursor->Valid()) {
6261
std::pair<uint8_t, CAddressIndexKey> key;
63-
if (pcursor->GetKey(key) && key.first == DB_ADDRESSINDEX &&
64-
key.second.m_address_type == type && key.second.m_address_bytes == address_hash) {
62+
if (pcursor->GetKey(key) && key.first == DB_ADDRESSINDEX && key.second.m_address_type == type &&
63+
key.second.m_address_bytes == address_hash) {
6564
if (end > 0 && key.second.m_block_height > end) {
6665
break;
6766
}
@@ -81,17 +80,16 @@ bool AddressIndex::DB::ReadAddressIndex(const uint160& address_hash, const Addre
8180
}
8281

8382
bool AddressIndex::DB::ReadAddressUnspentIndex(const uint160& address_hash, const AddressType type,
84-
std::vector<CAddressUnspentIndexEntry>& entries,
85-
const bool height_sort)
83+
std::vector<CAddressUnspentIndexEntry>& entries, const bool height_sort)
8684
{
8785
std::unique_ptr<CDBIterator> pcursor(NewIterator());
8886

8987
pcursor->Seek(std::make_pair(DB_ADDRESSUNSPENTINDEX, CAddressIndexIteratorKey(type, address_hash)));
9088

9189
while (pcursor->Valid()) {
9290
std::pair<uint8_t, CAddressUnspentKey> key;
93-
if (pcursor->GetKey(key) && key.first == DB_ADDRESSUNSPENTINDEX &&
94-
key.second.m_address_type == type && key.second.m_address_bytes == address_hash) {
91+
if (pcursor->GetKey(key) && key.first == DB_ADDRESSUNSPENTINDEX && key.second.m_address_type == type &&
92+
key.second.m_address_bytes == address_hash) {
9593
CAddressUnspentValue value;
9694
if (pcursor->GetValue(value)) {
9795
entries.emplace_back(key.second, value);
@@ -106,9 +104,9 @@ bool AddressIndex::DB::ReadAddressUnspentIndex(const uint160& address_hash, cons
106104

107105
if (height_sort) {
108106
std::sort(entries.begin(), entries.end(),
109-
[](const CAddressUnspentIndexEntry& a, const CAddressUnspentIndexEntry& b) {
110-
return a.second.m_block_height < b.second.m_block_height;
111-
});
107+
[](const CAddressUnspentIndexEntry& a, const CAddressUnspentIndexEntry& b) {
108+
return a.second.m_block_height < b.second.m_block_height;
109+
});
112110
}
113111

114112
return true;
@@ -140,8 +138,8 @@ bool AddressIndex::DB::UpdateAddressUnspentIndex(const std::vector<CAddressUnspe
140138
return CDBWrapper::WriteBatch(batch);
141139
}
142140

143-
AddressIndex::AddressIndex(size_t n_cache_size, bool f_memory, bool f_wipe)
144-
: m_db(std::make_unique<AddressIndex::DB>(n_cache_size, f_memory, f_wipe))
141+
AddressIndex::AddressIndex(size_t n_cache_size, bool f_memory, bool f_wipe) :
142+
m_db(std::make_unique<AddressIndex::DB>(n_cache_size, f_memory, f_wipe))
145143
{
146144
}
147145

@@ -157,8 +155,8 @@ bool AddressIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
157155
// Read undo data for this block to get information about spent outputs
158156
CBlockUndo blockundo;
159157
if (!node::UndoReadFromDisk(blockundo, pindex)) {
160-
return error("%s: Failed to read undo data for block %s at height %d",
161-
__func__, pindex->GetBlockHash().ToString(), pindex->nHeight);
158+
return error("%s: Failed to read undo data for block %s at height %d", __func__,
159+
pindex->GetBlockHash().ToString(), pindex->nHeight);
162160
}
163161

164162
std::vector<CAddressIndexEntry> addressIndex;
@@ -189,15 +187,13 @@ bool AddressIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
189187
}
190188

191189
// Record spending activity
192-
addressIndex.emplace_back(
193-
CAddressIndexKey(address_type, address_bytes, pindex->nHeight, i + 1, txhash, j, true),
194-
prevout.nValue * -1
195-
);
190+
addressIndex.emplace_back(CAddressIndexKey(address_type, address_bytes, pindex->nHeight, i + 1, txhash, j, true),
191+
prevout.nValue * -1);
196192

197193
// Remove from unspent index
198-
addressUnspentIndex.emplace_back(
199-
CAddressUnspentKey(address_type, address_bytes, input.prevout.hash, input.prevout.n),
200-
CAddressUnspentValue() // Null value means delete
194+
addressUnspentIndex.emplace_back(CAddressUnspentKey(address_type, address_bytes, input.prevout.hash,
195+
input.prevout.n),
196+
CAddressUnspentValue() // Null value means delete
201197
);
202198
}
203199

@@ -212,16 +208,12 @@ bool AddressIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
212208
}
213209

214210
// Record receiving activity
215-
addressIndex.emplace_back(
216-
CAddressIndexKey(address_type, address_bytes, pindex->nHeight, i + 1, txhash, k, false),
217-
out.nValue
218-
);
211+
addressIndex.emplace_back(CAddressIndexKey(address_type, address_bytes, pindex->nHeight, i + 1, txhash, k, false),
212+
out.nValue);
219213

220214
// Add to unspent index
221-
addressUnspentIndex.emplace_back(
222-
CAddressUnspentKey(address_type, address_bytes, txhash, k),
223-
CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight)
224-
);
215+
addressUnspentIndex.emplace_back(CAddressUnspentKey(address_type, address_bytes, txhash, k),
216+
CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight));
225217
}
226218
}
227219

@@ -238,16 +230,12 @@ bool AddressIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
238230
}
239231

240232
// Record receiving activity for coinbase
241-
addressIndex.emplace_back(
242-
CAddressIndexKey(address_type, address_bytes, pindex->nHeight, 0, coinbase_hash, k, false),
243-
out.nValue
244-
);
233+
addressIndex.emplace_back(CAddressIndexKey(address_type, address_bytes, pindex->nHeight, 0, coinbase_hash, k, false),
234+
out.nValue);
245235

246236
// Add coinbase outputs to unspent index
247-
addressUnspentIndex.emplace_back(
248-
CAddressUnspentKey(address_type, address_bytes, coinbase_hash, k),
249-
CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight)
250-
);
237+
addressUnspentIndex.emplace_back(CAddressUnspentKey(address_type, address_bytes, coinbase_hash, k),
238+
CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight));
251239
}
252240

253241
return m_db->WriteBatch(addressIndex, addressUnspentIndex);
@@ -262,14 +250,14 @@ bool AddressIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new
262250
for (const CBlockIndex* pindex = current_tip; pindex != new_tip; pindex = pindex->pprev) {
263251
CBlock block;
264252
if (!node::ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
265-
return error("%s: Failed to read block %s from disk during rewind",
266-
__func__, pindex->GetBlockHash().ToString());
253+
return error("%s: Failed to read block %s from disk during rewind", __func__,
254+
pindex->GetBlockHash().ToString());
267255
}
268256

269257
CBlockUndo blockundo;
270258
if (pindex->nHeight > 0 && !node::UndoReadFromDisk(blockundo, pindex)) {
271-
return error("%s: Failed to read undo data for block %s during rewind",
272-
__func__, pindex->GetBlockHash().ToString());
259+
return error("%s: Failed to read undo data for block %s during rewind", __func__,
260+
pindex->GetBlockHash().ToString());
273261
}
274262

275263
std::vector<CAddressIndexEntry> addressIndex;
@@ -294,16 +282,14 @@ bool AddressIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new
294282
}
295283

296284
// Remove receiving activity from history
297-
addressIndex.push_back(std::make_pair(
298-
CAddressIndexKey(address_type, address_bytes, pindex->nHeight, i + 1, txhash, k, false),
299-
out.nValue
300-
));
285+
addressIndex.push_back(std::make_pair(CAddressIndexKey(address_type, address_bytes, pindex->nHeight,
286+
i + 1, txhash, k, false),
287+
out.nValue));
301288

302289
// Remove from unspent index (mark for deletion)
303-
addressUnspentIndex.push_back(std::make_pair(
304-
CAddressUnspentKey(address_type, address_bytes, txhash, k),
305-
CAddressUnspentValue() // null value signals deletion
306-
));
290+
addressUnspentIndex.push_back(std::make_pair(CAddressUnspentKey(address_type, address_bytes, txhash, k),
291+
CAddressUnspentValue() // null value signals deletion
292+
));
307293
}
308294

309295
// Undo inputs (restore to unspent index, remove spending from history)
@@ -320,16 +306,14 @@ bool AddressIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new
320306
}
321307

322308
// Remove spending activity from history
323-
addressIndex.push_back(std::make_pair(
324-
CAddressIndexKey(address_type, address_bytes, pindex->nHeight, i + 1, txhash, j, true),
325-
prevout.nValue * -1
326-
));
309+
addressIndex.push_back(
310+
std::make_pair(CAddressIndexKey(address_type, address_bytes, pindex->nHeight, i + 1, txhash, j, true),
311+
prevout.nValue * -1));
327312

328313
// Restore to unspent index
329-
addressUnspentIndex.push_back(std::make_pair(
330-
CAddressUnspentKey(address_type, address_bytes, input.prevout.hash, input.prevout.n),
331-
CAddressUnspentValue(prevout.nValue, prevout.scriptPubKey, coin.nHeight)
332-
));
314+
addressUnspentIndex.push_back(
315+
std::make_pair(CAddressUnspentKey(address_type, address_bytes, input.prevout.hash, input.prevout.n),
316+
CAddressUnspentValue(prevout.nValue, prevout.scriptPubKey, coin.nHeight)));
333317
}
334318
}
335319

@@ -349,16 +333,14 @@ bool AddressIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new
349333
}
350334

351335
// Remove coinbase receiving activity
352-
addressIndex.push_back(std::make_pair(
353-
CAddressIndexKey(address_type, address_bytes, pindex->nHeight, 0, cb_hash, k, false),
354-
out.nValue
355-
));
336+
addressIndex.push_back(
337+
std::make_pair(CAddressIndexKey(address_type, address_bytes, pindex->nHeight, 0, cb_hash, k, false),
338+
out.nValue));
356339

357340
// Remove from unspent index
358-
addressUnspentIndex.push_back(std::make_pair(
359-
CAddressUnspentKey(address_type, address_bytes, cb_hash, k),
360-
CAddressUnspentValue() // null value signals deletion
361-
));
341+
addressUnspentIndex.push_back(std::make_pair(CAddressUnspentKey(address_type, address_bytes, cb_hash, k),
342+
CAddressUnspentValue() // null value signals deletion
343+
));
362344
}
363345
}
364346

@@ -385,17 +367,15 @@ void AddressIndex::BlockDisconnected(const std::shared_ptr<const CBlock>& block,
385367
// Only rewind if we have this block indexed
386368
if (best_block_index && best_block_index->nHeight >= pindex->nHeight && pindex->pprev) {
387369
if (!Rewind(best_block_index, pindex->pprev)) {
388-
error("%s: Failed to rewind %s to previous block after disconnect",
389-
__func__, GetName());
370+
error("%s: Failed to rewind %s to previous block after disconnect", __func__, GetName());
390371
}
391372
}
392373
}
393374

394375
BaseIndex::DB& AddressIndex::GetDB() const { return *m_db; }
395376

396377
bool AddressIndex::GetAddressIndex(const uint160& address_hash, const AddressType type,
397-
std::vector<CAddressIndexEntry>& entries,
398-
const int32_t start, const int32_t end) const
378+
std::vector<CAddressIndexEntry>& entries, const int32_t start, const int32_t end) const
399379
{
400380
if (!BlockUntilSyncedToCurrentChain()) {
401381
return false;
@@ -405,8 +385,7 @@ bool AddressIndex::GetAddressIndex(const uint160& address_hash, const AddressTyp
405385
}
406386

407387
bool AddressIndex::GetAddressUnspentIndex(const uint160& address_hash, const AddressType type,
408-
std::vector<CAddressUnspentIndexEntry>& entries,
409-
const bool height_sort) const
388+
std::vector<CAddressUnspentIndexEntry>& entries, const bool height_sort) const
410389
{
411390
if (!BlockUntilSyncedToCurrentChain()) {
412391
return false;

src/index/addressindex_util.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99

1010
#include <vector>
1111

12-
bool AddressBytesFromScript(const CScript& script, AddressType& address_type, uint160& address_bytes) {
12+
bool AddressBytesFromScript(const CScript& script, AddressType& address_type, uint160& address_bytes)
13+
{
1314
if (script.IsPayToScriptHash()) {
14-
address_type = AddressType::P2SH;
15+
address_type = AddressType::P2SH;
1516
address_bytes = uint160(std::vector<uint8_t>(script.begin() + 2, script.begin() + 22));
1617
} else if (script.IsPayToPublicKeyHash()) {
17-
address_type = AddressType::P2PK_OR_P2PKH;
18+
address_type = AddressType::P2PK_OR_P2PKH;
1819
address_bytes = uint160(std::vector<uint8_t>(script.begin() + 3, script.begin() + 23));
1920
} else if (script.IsPayToPublicKey()) {
20-
address_type = AddressType::P2PK_OR_P2PKH;
21+
address_type = AddressType::P2PK_OR_P2PKH;
2122
address_bytes = Hash160(std::vector<uint8_t>(script.begin() + 1, script.end() - 1));
2223
} else {
23-
address_type = AddressType::UNKNOWN;
24+
address_type = AddressType::UNKNOWN;
2425
address_bytes.SetNull();
2526
return false;
2627
}

src/index/spentindex.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ bool SpentIndex::DB::EraseSpentIndex(const std::vector<CSpentIndexKey>& keys)
5252
return CDBWrapper::WriteBatch(batch);
5353
}
5454

55-
SpentIndex::SpentIndex(size_t n_cache_size, bool f_memory, bool f_wipe)
56-
: m_db(std::make_unique<SpentIndex::DB>(n_cache_size, f_memory, f_wipe))
55+
SpentIndex::SpentIndex(size_t n_cache_size, bool f_memory, bool f_wipe) :
56+
m_db(std::make_unique<SpentIndex::DB>(n_cache_size, f_memory, f_wipe))
5757
{
5858
}
5959

@@ -69,8 +69,8 @@ bool SpentIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
6969
// Read undo data for this block to get information about spent outputs
7070
CBlockUndo blockundo;
7171
if (!node::UndoReadFromDisk(blockundo, pindex)) {
72-
return error("%s: Failed to read undo data for block %s at height %d",
73-
__func__, pindex->GetBlockHash().ToString(), pindex->nHeight);
72+
return error("%s: Failed to read undo data for block %s at height %d", __func__,
73+
pindex->GetBlockHash().ToString(), pindex->nHeight);
7474
}
7575

7676
std::vector<CSpentIndexEntry> entries;
@@ -119,8 +119,8 @@ bool SpentIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_t
119119
// Read block to get transactions
120120
CBlock block;
121121
if (!node::ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
122-
return error("%s: Failed to read block %s from disk during rewind",
123-
__func__, pindex->GetBlockHash().ToString());
122+
return error("%s: Failed to read block %s from disk during rewind", __func__,
123+
pindex->GetBlockHash().ToString());
124124
}
125125

126126
std::vector<CSpentIndexKey> keys_to_erase;
@@ -154,8 +154,7 @@ void SpentIndex::BlockDisconnected(const std::shared_ptr<const CBlock>& block, c
154154
// Only rewind if we have this block indexed
155155
if (best_block_index && best_block_index->nHeight >= pindex->nHeight && pindex->pprev) {
156156
if (!Rewind(best_block_index, pindex->pprev)) {
157-
error("%s: Failed to rewind %s to previous block after disconnect",
158-
__func__, GetName());
157+
error("%s: Failed to rewind %s to previous block after disconnect", __func__, GetName());
159158
}
160159
}
161160
}

src/index/timestampindex.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ bool TimestampIndex::DB::EraseTimestampIndex(const CTimestampIndexKey& key)
4848
return CDBWrapper::Erase(std::make_pair(DB_TIMESTAMPINDEX, key));
4949
}
5050

51-
TimestampIndex::TimestampIndex(size_t n_cache_size, bool f_memory, bool f_wipe)
52-
: m_db(std::make_unique<TimestampIndex::DB>(n_cache_size, f_memory, f_wipe))
51+
TimestampIndex::TimestampIndex(size_t n_cache_size, bool f_memory, bool f_wipe) :
52+
m_db(std::make_unique<TimestampIndex::DB>(n_cache_size, f_memory, f_wipe))
5353
{
5454
}
5555

@@ -78,8 +78,8 @@ bool TimestampIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* n
7878

7979
CTimestampIndexKey key(pindex->nTime, pindex->GetBlockHash());
8080
if (!m_db->EraseTimestampIndex(key)) {
81-
return error("%s: Failed to erase timestamp index for block %s during rewind",
82-
__func__, pindex->GetBlockHash().ToString());
81+
return error("%s: Failed to erase timestamp index for block %s during rewind", __func__,
82+
pindex->GetBlockHash().ToString());
8383
}
8484
}
8585

@@ -96,8 +96,7 @@ void TimestampIndex::BlockDisconnected(const std::shared_ptr<const CBlock>& bloc
9696
// Only rewind if we have this block indexed and it's not the genesis block
9797
if (best_block_index && best_block_index->nHeight >= pindex->nHeight && pindex->pprev) {
9898
if (!Rewind(best_block_index, pindex->pprev)) {
99-
error("%s: Failed to rewind %s to previous block after disconnect",
100-
__func__, GetName());
99+
error("%s: Failed to rewind %s to previous block after disconnect", __func__, GetName());
101100
}
102101
}
103102
}

0 commit comments

Comments
 (0)