mirror of
https://github.com/jwinterm/myriadcoin.git
synced 2026-10-22 06:28:44 +02:00
add support for address index
This commit is contained in:
@@ -78,6 +78,10 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) {
|
||||
}
|
||||
|
||||
CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe) : CLevelDBWrapper(GetDataDir() / "blocks" / "index", nCacheSize, fMemory, fWipe) {
|
||||
if (!Read('S', salt)) {
|
||||
salt = GetRandHash();
|
||||
Write('S', salt);
|
||||
}
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::ReadBlockFileInfo(int nFile, CBlockFileInfo &info) {
|
||||
@@ -176,6 +180,50 @@ bool CBlockTreeDB::WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos>
|
||||
return WriteBatch(batch);
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::ReadAddrIndex(uint160 addrid, std::vector<CExtDiskTxPos> &list) {
|
||||
boost::scoped_ptr<leveldb::Iterator> pcursor(NewIterator());
|
||||
uint64_t lookupid;
|
||||
{
|
||||
CHashWriter ss(SER_GETHASH, 0);
|
||||
ss << salt;
|
||||
ss << addrid;
|
||||
lookupid = UintToArith256(ss.GetHash()).GetLow64();
|
||||
}
|
||||
CDataStream ssKeySet(SER_DISK, CLIENT_VERSION);
|
||||
ssKeySet << make_pair('a', lookupid);
|
||||
pcursor->Seek(ssKeySet.str());
|
||||
|
||||
while (pcursor->Valid()) {
|
||||
std::pair<std::pair<char, uint64_t>, CExtDiskTxPos> key;
|
||||
leveldb::Slice slKey = pcursor->key();
|
||||
try {
|
||||
CDataStream ssKey(slKey.data(), slKey.data() + slKey.size(), SER_DISK, CLIENT_VERSION);
|
||||
ssKey >> key;
|
||||
} catch(std::exception &e) {
|
||||
break;
|
||||
}
|
||||
if (key.first.first == 'a' && key.first.second == lookupid) {
|
||||
list.push_back(key.second);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
pcursor->Next();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::AddAddrIndex(const std::vector<std::pair<uint160, CExtDiskTxPos> > &list) {
|
||||
unsigned char foo[0];
|
||||
CLevelDBBatch batch;
|
||||
for (std::vector<std::pair<uint160, CExtDiskTxPos> >::const_iterator it=list.begin(); it!=list.end(); it++) {
|
||||
CHashWriter ss(SER_GETHASH, 0);
|
||||
ss << salt;
|
||||
ss << it->first;
|
||||
batch.Write(make_pair(make_pair('a', UintToArith256(ss.GetHash()).GetLow64()), it->second), FLATDATA(foo));
|
||||
}
|
||||
return WriteBatch(batch, true);
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::WriteFlag(const std::string &name, bool fValue) {
|
||||
return Write(std::make_pair(DB_FLAG, name), fValue ? '1' : '0');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user