本文整理汇总了C++中BinaryDataRef::getSliceCopy方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryDataRef::getSliceCopy方法的具体用法?C++ BinaryDataRef::getSliceCopy怎么用?C++ BinaryDataRef::getSliceCopy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryDataRef
的用法示例。
在下文中一共展示了BinaryDataRef::getSliceCopy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadZeroConfMempool
void ZeroConfContainer::loadZeroConfMempool(
function<bool(const BinaryData&)> filter,
bool clearMempool)
{
//run this in its own scope so the iter and tx are closed in order to open
//RW tx afterwards
{
auto dbs = db_->getDbSelect(HISTORY);
LMDBEnv::Transaction tx;
db_->beginDBTransaction(&tx, dbs, LMDB::ReadOnly);
LDBIter dbIter(db_->getIterator(dbs));
if (!dbIter.seekToStartsWith(DB_PREFIX_ZCDATA))
{
enabled_ = true;
return;
}
do
{
BinaryDataRef zcKey = dbIter.getKeyRef();
if (zcKey.getSize() == 7)
{
//Tx, grab it from DB
StoredTx zcStx;
db_->getStoredZcTx(zcStx, zcKey);
//add to newZCMap_
Tx& zcTx = newZCMap_[zcKey.getSliceCopy(1, 6)];
zcTx = Tx(zcStx.getSerializedTx());
zcTx.setTxTime(zcStx.unixTime_);
}
else if (zcKey.getSize() == 9)
{
//TxOut, ignore it
continue;
}
else
{
//shouldn't hit this
LOGERR << "Unknown key found in ZC mempool";
break;
}
} while (dbIter.advanceAndRead(DB_PREFIX_ZCDATA));
}
if (clearMempool == true)
{
vector<BinaryData> keysToWrite, keysToDelete;
for (const auto& zcTx : newZCMap_)
keysToDelete.push_back(zcTx.first);
newZCMap_.clear();
updateZCinDB(keysToWrite, keysToDelete);
}
else if (newZCMap_.size())
{
//copy newZCmap_ to keep the pre parse ZC map
auto oldZCMap = newZCMap_;
//now parse the new ZC
parseNewZC(filter);
//set the zckey to the highest used index
if (txMap_.size() > 0)
{
BinaryData topZcKey = txMap_.rbegin()->first;
topId_.store(READ_UINT32_BE(topZcKey.getSliceCopy(2, 4)) +1);
}
//intersect oldZCMap and txMap_ to figure out the invalidated ZCs
vector<BinaryData> keysToWrite, keysToDelete;
for (const auto& zcTx : oldZCMap)
{
if (txMap_.find(zcTx.first) == txMap_.end())
keysToDelete.push_back(zcTx.first);
}
//no need to run this in a side thread, this code only runs when we have
//full control over the main thread
updateZCinDB(keysToWrite, keysToDelete);
}
enabled_ = true;
}