本文整理汇总了C++中BinaryWriter::getDataRef方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryWriter::getDataRef方法的具体用法?C++ BinaryWriter::getDataRef怎么用?C++ BinaryWriter::getDataRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryWriter
的用法示例。
在下文中一共展示了BinaryWriter::getDataRef方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateSSH
//.........这里部分代码省略.........
//let's set the iterator to the correct height (or the next key)
auto&& newKey = sshIter.getKey().getSliceCopy(0, subsshkey.getSize() - 4);
auto&& newHgtx = DBUtils::heightAndDupToHgtx(
sshPtr->alreadyScannedUpToBlk_ + 1, 0);
newKey.append(newHgtx);
sshIter.seekTo(newKey);
continue;
}
}
else
{
sshPtr->uniqueKey_ = sshKey;
break;
}
}
//sanity check
if (!sshIter.isValid())
break;
//deser subssh
StoredSubHistory subssh;
subssh.unserializeDBKey(sshIter.getKeyRef());
//check dupID
if (db_->getValidDupIDForHeight(subssh.height_) != subssh.dupID_)
continue;
subssh.unserializeDBValue(sshIter.getValueRef());
for (auto& txioPair : subssh.txioMap_)
{
if (!txioPair.second.isMultisig())
{
//add up balance
if (txioPair.second.hasTxIn())
{
//check for same block fund&spend
auto&& keyOfOutput = txioPair.second.getDBKeyOfOutput();
auto&& keyOfInput = txioPair.second.getDBKeyOfInput();
if (keyOfOutput.startsWith(keyOfInput.getSliceRef(0, 4)))
{
//both output and input are part of the same block, skip
continue;
}
sshPtr->totalUnspent_ -= txioPair.second.getValue();
}
else
{
sshPtr->totalUnspent_ += txioPair.second.getValue();
}
}
}
//txio count
sshPtr->totalTxioCount_ += subssh.txioCount_;
//build subssh summary
sshPtr->subsshSummary_[subssh.height_] = subssh.txioCount_;
}
}
//write it
auto& topheader = blockchain_->getHeaderByHash(topScannedBlockHash_);
auto topheight = topheader.getBlockHeight();
LMDBEnv::Transaction putsshtx;
db_->beginDBTransaction(&putsshtx, SSH, LMDB::ReadWrite);
auto& scrAddrMap = scrAddrFilter_->getScrAddrMap();
for (auto& scrAddr : scrAddrMap)
{
auto& ssh = sshMap_[scrAddr.first];
if (!ssh.isInitialized())
{
ssh.uniqueKey_ = scrAddr.first;
}
BinaryData&& sshKey = ssh.getDBKey();
ssh.alreadyScannedUpToBlk_ = topheight;
BinaryWriter bw;
ssh.serializeDBValue(bw, ARMORY_DB_BARE, DB_PRUNE_NONE);
db_->putValue(SSH, sshKey.getRef(), bw.getDataRef());
}
//update sdbi
StoredDBInfo sdbi;
db_->getStoredDBInfo(SSH, sdbi);
sdbi.topScannedBlkHash_ = topScannedBlockHash_;
sdbi.topBlkHgt_ = topheight;
db_->putStoredDBInfo(SSH, sdbi);
}
示例2: undo
//.........这里部分代码省略.........
//decrement summary count at height, remove entry if necessary
auto& sum = ssh.subsshSummary_[currentHeight];
sum--;
if (sum <= 0)
ssh.subsshSummary_.erase(currentHeight);
}
}
//set blockPtr to prev block
blockPtr = &blockchain_->getHeaderByHash(blockPtr->getPrevHashRef());
}
//at this point we have a map of updated ssh, as well as a
//set of keys to delete from the DB and spentness to undo by stxo key
//stxo
{
LMDBEnv::Transaction tx;
db_->beginDBTransaction(&tx, STXO, LMDB::ReadWrite);
//grab stxos and revert spentness
map<BinaryData, StoredTxOut> stxos;
for (auto& stxoKey : undoSpentness)
{
auto& stxo = stxos[stxoKey];
if (!db_->getStoredTxOut(stxo, stxoKey))
continue;
stxo.spentByTxInKey_.clear();
stxo.spentness_ = TXOUT_UNSPENT;
}
//put updated stxos
for (auto& stxo : stxos)
{
if (stxo.second.isInitialized())
db_->putStoredTxOut(stxo.second);
}
//delete invalidated stxos
auto& stxoKeysToDelete = keysToDelete[STXO];
for (auto& key : stxoKeysToDelete)
db_->deleteValue(STXO, key);
}
auto branchPointHeight =
reorgState.reorgBranchPoint->getBlockHeight();
//ssh
{
LMDBEnv::Transaction tx;
db_->beginDBTransaction(&tx, SSH, LMDB::ReadWrite);
//go thourgh all ssh in scrAddrFilter
auto& scrAddrMap = scrAddrFilter_->getScrAddrMap();
for (auto& scrAddr : scrAddrMap)
{
auto& ssh = sshMap[scrAddr.first];
//if the ssh isn't in our map, pull it from DB
if (!ssh.isInitialized())
{
db_->getStoredScriptHistorySummary(ssh, scrAddr.first);
if (ssh.uniqueKey_.getSize() == 0)
{
sshMap.erase(scrAddr.first);
continue;
}
}
//update alreadyScannedUpToBlk_ to branch point height
if (ssh.alreadyScannedUpToBlk_ > branchPointHeight)
ssh.alreadyScannedUpToBlk_ = branchPointHeight;
}
//write it all up
for (auto& ssh : sshMap)
{
if (!scrAddrFilter_->hasScrAddress(ssh.second.uniqueKey_))
{
LOGWARN << "invalid scrAddr during undo";
continue;
}
BinaryWriter bw;
ssh.second.serializeDBValue(bw, ARMORY_DB_BARE, DB_PRUNE_NONE);
db_->putValue(SSH,
ssh.second.getDBKey().getRef(),
bw.getDataRef());
}
//update SSH sdbi
StoredDBInfo sdbi;
db_->getStoredDBInfo(SSH, sdbi);
sdbi.topScannedBlkHash_ = reorgState.reorgBranchPoint->getThisHash();
sdbi.topBlkHgt_ = branchPointHeight;
db_->putStoredDBInfo(SSH, sdbi);
}
}
示例3: writeBlockData
void BlockchainScanner::writeBlockData(
shared_ptr<BatchLink> batchLinkPtr)
{
auto getGlobalOffsetForBlock = [&](unsigned height)->size_t
{
auto& header = blockchain_->getHeaderByHeight(height);
size_t val = header.getBlockFileNum();
val *= 128 * 1024 * 1024;
val += header.getOffset();
return val;
};
ProgressCalculator calc(getGlobalOffsetForBlock(
blockchain_->top().getBlockHeight()));
calc.advance(getGlobalOffsetForBlock(startAt_));
auto writeHintsLambda =
[&](const vector<shared_ptr<BlockDataBatch>>& batchVec)->void
{ processAndCommitTxHints(batchVec); };
while (1)
{
if (batchLinkPtr == nullptr)
break;
{
unique_lock<mutex> batchIsReady(batchLinkPtr->readyToWrite_);
}
if (batchLinkPtr->next_ == nullptr)
break;
//start txhint writer thread
thread writeHintsThreadId =
thread(writeHintsLambda, batchLinkPtr->batchVec_);
auto& topheader =
blockchain_->getHeaderByHash(batchLinkPtr->topScannedBlockHash_);
auto topHeight = topheader.getBlockHeight();
//serialize data
map<BinaryData, BinaryWriter> serializedSubSSH;
map<BinaryData, BinaryWriter> serializedStxo;
map<BinaryData, BinaryWriter> serializedTxHints;
map<BinaryData, StoredTxHints> txHints;
{
for (auto& batchPtr : batchLinkPtr->batchVec_)
{
for (auto& ssh : batchPtr->ssh_)
{
for (auto& subssh : ssh.second.subHistMap_)
{
//TODO: modify subssh serialization to fit our needs
BinaryWriter subsshkey;
subsshkey.put_uint8_t(DB_PREFIX_SCRIPT);
subsshkey.put_BinaryData(ssh.first);
subsshkey.put_BinaryData(subssh.first);
auto& bw = serializedSubSSH[subsshkey.getDataRef()];
subssh.second.serializeDBValue(
bw, db_, ARMORY_DB_BARE, DB_PRUNE_NONE);
}
}
for (auto& utxomap : batchPtr->utxos_)
{
auto&& txHashPrefix = utxomap.first.getSliceCopy(0, 4);
StoredTxHints& stxh = txHints[txHashPrefix];
if (stxh.txHashPrefix_.getSize() == 0)
stxh.txHashPrefix_ = txHashPrefix;
for (auto& utxo : utxomap.second)
{
stxh.dbKeyList_.push_back(utxo.second.getDBKeyOfParentTx());
auto& bw = serializedStxo[utxo.second.getDBKey()];
utxo.second.serializeDBValue(
bw, ARMORY_DB_BARE, DB_PRUNE_NONE, true);
}
stxh.preferredDBKey_ = stxh.dbKeyList_.front();
}
}
}
//we've serialized utxos, now let's do another pass for spent txouts
//to make sure they overwrite utxos that were found and spent within
//the same batch
for (auto& batchPtr : batchLinkPtr->batchVec_)
{
for (auto& stxo : batchPtr->spentTxOuts_)
{
auto& bw = serializedStxo[stxo.getDBKey()];
if (bw.getSize() > 0)
bw.reset();
stxo.serializeDBValue(
bw, ARMORY_DB_BARE, DB_PRUNE_NONE, true);
//.........这里部分代码省略.........