hacktober fest #214

Closed
Z3N00 wants to merge 304 commits from zeno into master
7 changed files with 446 additions and 320 deletions
Showing only changes of commit 78871a7091 - Show all commits

View file

@ -24,13 +24,13 @@ std::vector<unsigned char> heightToVch(int n)
uint256 CClaimValue::GetHash() const
{
CHash256 txHasher;
txHasher.Write(txhash.begin(), txhash.size());
txHasher.Write(outPoint.hash.begin(), outPoint.hash.size());
std::vector<unsigned char> vchtxHash(txHasher.OUTPUT_SIZE);
txHasher.Finalize(&(vchtxHash[0]));
CHash256 nOutHasher;
std::stringstream ss;
ss << nOut;
ss << outPoint.n;
std::string snOut = ss.str();
nOutHasher.Write((unsigned char*) snOut.data(), snOut.size());
std::vector<unsigned char> vchnOutHash(nOutHasher.OUTPUT_SIZE);
@ -48,33 +48,35 @@ uint256 CClaimValue::GetHash() const
bool CClaimTrieNode::insertClaim(CClaimValue claim)
{
LogPrintf("%s: Inserting %s:%d (amount: %d) into the claim trie\n", __func__, claim.txhash.ToString(), claim.nOut, claim.nAmount);
LogPrintf("%s: Inserting %s:%d (amount: %d) into the claim trie\n", __func__, claim.outPoint.hash.ToString(), claim.outPoint.n, claim.nAmount);
claims.push_back(claim);
return true;
}
bool CClaimTrieNode::removeClaim(uint256& txhash, uint32_t nOut, CClaimValue& claim)
bool CClaimTrieNode::removeClaim(const COutPoint& outPoint, CClaimValue& claim)
{
LogPrintf("%s: Removing txid: %s, nOut: %d from the claim trie\n", __func__, txhash.ToString(), nOut);
LogPrintf("%s: Removing txid: %s, nOut: %d from the claim trie\n", __func__, outPoint.hash.ToString(), outPoint.n);
std::vector<CClaimValue>::iterator position;
for (position = claims.begin(); position != claims.end(); ++position)
std::vector<CClaimValue>::iterator itClaims;
for (itClaims = claims.begin(); itClaims != claims.end(); ++itClaims)
{
if (position->txhash == txhash && position->nOut == nOut)
if (itClaims->outPoint == outPoint)
{
std::swap(claim, *position);
std::swap(claim, *itClaims);
break;
}
}
if (position != claims.end())
claims.erase(position);
if (itClaims != claims.end())
{
claims.erase(itClaims);
}
else
{
LogPrintf("CClaimTrieNode::%s() : asked to remove a claim that doesn't exist\n", __func__);
LogPrintf("CClaimTrieNode::%s() : claims that do exist:\n", __func__);
for (unsigned int i = 0; i < claims.size(); i++)
{
LogPrintf("\ttxid: %s, nOut: %d\n", claims[i].txhash.ToString(), claims[i].nOut);
LogPrintf("\ttxhash: %s, nOut: %d:\n", claims[i].outPoint.hash.ToString(), claims[i].outPoint.n);
}
return false;
}
@ -92,11 +94,13 @@ bool CClaimTrieNode::getBestClaim(CClaimValue& claim) const
}
}
bool CClaimTrieNode::haveClaim(const uint256& txhash, uint32_t nOut) const
bool CClaimTrieNode::haveClaim(const COutPoint& outPoint) const
{
for (std::vector<CClaimValue>::const_iterator itclaim = claims.begin(); itclaim != claims.end(); ++itclaim)
if (itclaim->txhash == txhash && itclaim->nOut == nOut)
{
if (itclaim->outPoint == outPoint)
return true;
}
return false;
}
@ -221,7 +225,7 @@ void CClaimTrie::clear(CClaimTrieNode* current)
}
}
bool CClaimTrie::haveClaim(const std::string& name, const uint256& txhash, uint32_t nOut) const
bool CClaimTrie::haveClaim(const std::string& name, const COutPoint& outPoint) const
{
const CClaimTrieNode* current = &root;
for (std::string::const_iterator itname = name.begin(); itname != name.end(); ++itname)
@ -231,10 +235,10 @@ bool CClaimTrie::haveClaim(const std::string& name, const uint256& txhash, uint3
return false;
current = itchildren->second;
}
return current->haveClaim(txhash, nOut);
return current->haveClaim(outPoint);
}
bool CClaimTrie::haveSupport(const std::string& name, const uint256& txhash, uint32_t nOut) const
bool CClaimTrie::haveSupport(const std::string& name, const COutPoint& outPoint) const
{
supportMapEntryType node;
if (!getSupportNode(name, node))
@ -243,13 +247,13 @@ bool CClaimTrie::haveSupport(const std::string& name, const uint256& txhash, uin
}
for (supportMapEntryType::const_iterator itnode = node.begin(); itnode != node.end(); ++itnode)
{
if (itnode->txhash == txhash && itnode->nOut == nOut)
if (itnode->outPoint == outPoint)
return true;
}
return false;
}
bool CClaimTrie::haveClaimInQueue(const std::string& name, const uint256& txhash, uint32_t nOut, int& nValidAtHeight) const
bool CClaimTrie::haveClaimInQueue(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight) const
{
std::vector<CClaimValue> nameRow;
if (!getQueueNameRow(name, nameRow))
@ -259,7 +263,7 @@ bool CClaimTrie::haveClaimInQueue(const std::string& name, const uint256& txhash
std::vector<CClaimValue>::const_iterator itNameRow;
for (itNameRow = nameRow.begin(); itNameRow != nameRow.end(); ++itNameRow)
{
if (itNameRow->txhash == txhash && itNameRow->nOut == nOut)
if (itNameRow->outPoint == outPoint)
{
nValidAtHeight = itNameRow->nValidAtHeight;
break;
@ -274,21 +278,21 @@ bool CClaimTrie::haveClaimInQueue(const std::string& name, const uint256& txhash
{
for (claimQueueRowType::const_iterator itRow = row.begin(); itRow != row.end(); ++itRow)
{
if (itRow->first == name && itRow->second.txhash == txhash && itRow->second.nOut == nOut)
if (itRow->first == name && itRow->second.outPoint == outPoint)
{
if (itRow->second.nValidAtHeight != nValidAtHeight)
{
LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nDifferent nValidAtHeight between named queue and height queue\n: name: %s, txid: %s, nOut: %d, nValidAtHeight in named queue: %d, nValidAtHeight in height queue: %d current height: %d\n", __func__, name, txhash.GetHex(), nOut, nValidAtHeight, itRow->second.nValidAtHeight, nCurrentHeight);
LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nDifferent nValidAtHeight between named queue and height queue\n: name: %s, txid: %s, nOut: %d, nValidAtHeight in named queue: %d, nValidAtHeight in height queue: %d current height: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nValidAtHeight, itRow->second.nValidAtHeight, nCurrentHeight);
}
return true;
}
}
}
LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nFound in named queue but not in height queue: name: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, name, txhash.GetHex(), nOut, nValidAtHeight, nCurrentHeight);
LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nFound in named queue but not in height queue: name: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nValidAtHeight, nCurrentHeight);
return false;
}
bool CClaimTrie::haveSupportInQueue(const std::string& name, const uint256& txhash, uint32_t nOut, int& nValidAtHeight) const
bool CClaimTrie::haveSupportInQueue(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight) const
{
std::vector<CSupportValue> nameRow;
if (!getSupportQueueNameRow(name, nameRow))
@ -298,7 +302,7 @@ bool CClaimTrie::haveSupportInQueue(const std::string& name, const uint256& txha
std::vector<CSupportValue>::const_iterator itNameRow;
for (itNameRow = nameRow.begin(); itNameRow != nameRow.end(); ++itNameRow)
{
if (itNameRow->txhash == txhash && itNameRow->nOut == nOut)
if (itNameRow->outPoint == outPoint)
{
nValidAtHeight = itNameRow->nValidAtHeight;
break;
@ -313,17 +317,17 @@ bool CClaimTrie::haveSupportInQueue(const std::string& name, const uint256& txha
{
for (supportQueueRowType::const_iterator itRow = row.begin(); itRow != row.end(); ++itRow)
{
if (itRow->first == name && itRow->second.txhash == txhash && itRow->second.nOut == nOut)
if (itRow->first == name && itRow->second.outPoint == outPoint)
{
if (itRow->second.nValidAtHeight != nValidAtHeight)
{
LogPrintf("%s: An inconsistency was found in the support queue. Please report this to the developers:\nDifferent nValidAtHeight between named queue and height queue\n: name: %s, txid: %s, nOut: %d, nValidAtHeight in named queue: %d, nValidAtHeight in height queue: %d current height: %d\n", __func__, name, txhash.GetHex(), nOut, nValidAtHeight, itRow->second.nValidAtHeight, nCurrentHeight);
LogPrintf("%s: An inconsistency was found in the support queue. Please report this to the developers:\nDifferent nValidAtHeight between named queue and height queue\n: name: %s, txid: %s, nOut: %d, nValidAtHeight in named queue: %d, nValidAtHeight in height queue: %d current height: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nValidAtHeight, itRow->second.nValidAtHeight, nCurrentHeight);
}
return true;
}
}
}
LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nFound in named queue but not in height queue: name: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, name, txhash.GetHex(), nOut, nValidAtHeight, nCurrentHeight);
LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nFound in named queue but not in height queue: name: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nValidAtHeight, nCurrentHeight);
return false;
}
@ -1060,7 +1064,7 @@ bool CClaimTrieCache::empty() const
return base->empty() && cache.empty();
}
bool CClaimTrieCache::insertClaimIntoTrie(const std::string name, CClaimValue claim, bool fCheckTakeover) const
bool CClaimTrieCache::insertClaimIntoTrie(const std::string& name, CClaimValue claim, bool fCheckTakeover) const
{
assert(base);
CClaimTrieNode* currentNode = &(base->root);
@ -1156,7 +1160,7 @@ bool CClaimTrieCache::insertClaimIntoTrie(const std::string name, CClaimValue cl
return true;
}
bool CClaimTrieCache::removeClaimFromTrie(const std::string name, uint256 txhash, uint32_t nOut, int& nValidAtHeight, bool fCheckTakeover) const
bool CClaimTrieCache::removeClaimFromTrie(const std::string& name, const COutPoint& outPoint, CClaimValue& claim, bool fCheckTakeover) const
{
assert(base);
CClaimTrieNode* currentNode = &(base->root);
@ -1196,7 +1200,6 @@ bool CClaimTrieCache::removeClaimFromTrie(const std::string name, uint256 txhash
}
bool fChanged = false;
assert(currentNode != NULL);
CClaimValue claim;
bool success = false;
if (currentNode->claims.empty())
@ -1206,7 +1209,7 @@ bool CClaimTrieCache::removeClaimFromTrie(const std::string name, uint256 txhash
}
CClaimValue currentTop = currentNode->claims.front();
success = currentNode->removeClaim(txhash, nOut, claim);
success = currentNode->removeClaim(outPoint, claim);
if (!currentNode->claims.empty())
{
@ -1221,13 +1224,10 @@ bool CClaimTrieCache::removeClaimFromTrie(const std::string name, uint256 txhash
if (!success)
{
LogPrintf("%s: Removing a claim was unsuccessful. name = %s, txhash = %s, nOut = %d", __func__, name.c_str(), txhash.GetHex(), nOut);
LogPrintf("%s: Removing a claim was unsuccessful. name = %s, txhash = %s, nOut = %d", __func__, name.c_str(), outPoint.hash.GetHex(), outPoint.n);
return false;
}
else
{
nValidAtHeight = claim.nValidAtHeight;
}
if (fChanged)
{
for (std::string::const_iterator itCur = name.begin(); itCur != name.end(); ++itCur)
@ -1360,9 +1360,9 @@ claimQueueNamesType::iterator CClaimTrieCache::getQueueCacheNameRow(const std::s
return itQueueNameRow;
}
bool CClaimTrieCache::addClaim(const std::string name, uint256 txhash, uint32_t nOut, uint160 claimId, CAmount nAmount, int nHeight) const
bool CClaimTrieCache::addClaim(const std::string& name, const COutPoint& outPoint, uint160 claimId, CAmount nAmount, int nHeight) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, claimId: %s, nAmount: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, claimId.GetHex(), nAmount, nHeight, nCurrentHeight);
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, claimId: %s, nAmount: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, claimId.GetHex(), nAmount, nHeight, nCurrentHeight);
assert(nHeight == nCurrentHeight);
CClaimValue currentClaim;
int delayForClaim;
@ -1375,14 +1375,14 @@ bool CClaimTrieCache::addClaim(const std::string name, uint256 txhash, uint32_t
{
delayForClaim = getDelayForName(name);
}
CClaimValue newClaim(txhash, nOut, claimId, nAmount, nHeight, nHeight + delayForClaim);
CClaimValue newClaim(outPoint, claimId, nAmount, nHeight, nHeight + delayForClaim);
return addClaimToQueues(name, newClaim);
}
bool CClaimTrieCache::undoSpendClaim(const std::string name, uint256 txhash, uint32_t nOut, uint160 claimId, CAmount nAmount, int nHeight, int nValidAtHeight) const
bool CClaimTrieCache::undoSpendClaim(const std::string& name, const COutPoint& outPoint, uint160 claimId, CAmount nAmount, int nHeight, int nValidAtHeight) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, claimId: %s, nAmount: %d, nHeight: %d, nValidAtHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, claimId.GetHex(), nAmount, nHeight, nValidAtHeight, nCurrentHeight);
CClaimValue claim(txhash, nOut, claimId, nAmount, nHeight, nValidAtHeight);
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, claimId: %s, nAmount: %d, nHeight: %d, nValidAtHeight: %d, nCurrentHeight: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, claimId.GetHex(), nAmount, nHeight, nValidAtHeight, nCurrentHeight);
CClaimValue claim(outPoint, claimId, nAmount, nHeight, nValidAtHeight);
if (nValidAtHeight < nCurrentHeight)
{
claimQueueEntryType entry(name, claim);
@ -1395,7 +1395,7 @@ bool CClaimTrieCache::undoSpendClaim(const std::string name, uint256 txhash, uin
}
}
bool CClaimTrieCache::addClaimToQueues(const std::string name, CClaimValue& claim) const
bool CClaimTrieCache::addClaimToQueues(const std::string& name, CClaimValue& claim) const
{
LogPrintf("%s: nValidAtHeight: %d\n", __func__, claim.nValidAtHeight);
claimQueueEntryType entry(name, claim);
@ -1407,7 +1407,7 @@ bool CClaimTrieCache::addClaimToQueues(const std::string name, CClaimValue& clai
return true;
}
bool CClaimTrieCache::removeClaimFromQueue(const std::string name, uint256 txhash, uint32_t nOut, int& nValidAtHeight) const
bool CClaimTrieCache::removeClaimFromQueue(const std::string& name, const COutPoint& outPoint, CClaimValue& claim) const
{
claimQueueNamesType::iterator itQueueNameRow = getQueueCacheNameRow(name, false);
if (itQueueNameRow == claimQueueNameCache.end())
@ -1417,9 +1417,8 @@ bool CClaimTrieCache::removeClaimFromQueue(const std::string name, uint256 txhas
std::vector<CClaimValue>::iterator itQueueName;
for (itQueueName = itQueueNameRow->second.begin(); itQueueName != itQueueNameRow->second.end(); ++itQueueName)
{
if (itQueueName->txhash == txhash && itQueueName->nOut == nOut)
if (itQueueName->outPoint == outPoint)
{
nValidAtHeight = itQueueName->nValidAtHeight;
break;
}
}
@ -1427,49 +1426,58 @@ bool CClaimTrieCache::removeClaimFromQueue(const std::string name, uint256 txhas
{
return false;
}
claimQueueType::iterator itQueueRow = getQueueCacheRow(nValidAtHeight, false);
claimQueueType::iterator itQueueRow = getQueueCacheRow(itQueueName->nValidAtHeight, false);
if (itQueueRow != claimQueueCache.end())
{
claimQueueRowType::iterator itQueue;
for (itQueue = itQueueRow->second.begin(); itQueue != itQueueRow->second.end(); ++itQueue)
{
if (name == itQueue->first && itQueue->second.txhash == txhash && itQueue->second.nOut == nOut)
if (name == itQueue->first && itQueue->second.outPoint == outPoint)
{
break;
}
}
if (itQueue != itQueueRow->second.end())
{
std::swap(claim, itQueue->second);
itQueueNameRow->second.erase(itQueueName);
itQueueRow->second.erase(itQueue);
return true;
}
}
LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nFound in named queue but not in height queue: name: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, name, txhash.GetHex(), nOut, nValidAtHeight, nCurrentHeight);
LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nFound in named queue but not in height queue: name: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, itQueueName->nValidAtHeight, nCurrentHeight);
return false;
}
bool CClaimTrieCache::undoAddClaim(const std::string name, uint256 txhash, uint32_t nOut, int nHeight) const
bool CClaimTrieCache::undoAddClaim(const std::string& name, const COutPoint& outPoint, int nHeight) const
{
int throwaway;
return removeClaim(name, txhash, nOut, nHeight, throwaway, false);
return removeClaim(name, outPoint, nHeight, throwaway, false);
}
bool CClaimTrieCache::spendClaim(const std::string name, uint256 txhash, uint32_t nOut, int nHeight, int& nValidAtHeight) const
bool CClaimTrieCache::spendClaim(const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight) const
{
return removeClaim(name, txhash, nOut, nHeight, nValidAtHeight, true);
return removeClaim(name, outPoint, nHeight, nValidAtHeight, true);
}
bool CClaimTrieCache::removeClaim(const std::string name, uint256 txhash, uint32_t nOut, int nHeight, int& nValidAtHeight, bool fCheckTakeover) const
bool CClaimTrieCache::removeClaim(const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight, bool fCheckTakeover) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %s, nHeight: %s, nCurrentHeight: %s\n", __func__, name, txhash.GetHex(), nOut, nHeight, nCurrentHeight);
LogPrintf("%s: name: %s, txhash: %s, nOut: %s, nHeight: %s, nCurrentHeight: %s\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nHeight, nCurrentHeight);
bool removed = false;
if (removeClaimFromQueue(name, txhash, nOut, nValidAtHeight))
CClaimValue claim;
if (removeClaimFromQueue(name, outPoint, claim))
{
removed = true;
if (removed == false && removeClaimFromTrie(name, txhash, nOut, nValidAtHeight, fCheckTakeover))
}
if (removed == false && removeClaimFromTrie(name, outPoint, claim, fCheckTakeover))
{
removed = true;
}
if (removed == true)
removeFromExpirationQueue(name, txhash, nOut, nHeight);
{
nValidAtHeight = claim.nValidAtHeight;
removeFromExpirationQueue(name, outPoint, nHeight);
}
return removed;
}
@ -1480,7 +1488,7 @@ void CClaimTrieCache::addToExpirationQueue(claimQueueEntryType& entry) const
itQueueRow->second.push_back(entry);
}
void CClaimTrieCache::removeFromExpirationQueue(const std::string name, uint256 txhash, uint32_t nOut, int nHeight) const
void CClaimTrieCache::removeFromExpirationQueue(const std::string& name, const COutPoint& outPoint, int nHeight) const
{
int expirationHeight = nHeight + base->nExpirationTime;
claimQueueType::iterator itQueueRow = getExpirationQueueCacheRow(expirationHeight, false);
@ -1490,7 +1498,7 @@ void CClaimTrieCache::removeFromExpirationQueue(const std::string name, uint256
for (itQueue = itQueueRow->second.begin(); itQueue != itQueueRow->second.end(); ++itQueue)
{
CClaimValue& claim = itQueue->second;
if (name == itQueue->first && claim.txhash == txhash && claim.nOut == nOut)
if (name == itQueue->first && claim.outPoint == outPoint)
break;
}
}
@ -1521,7 +1529,7 @@ claimQueueType::iterator CClaimTrieCache::getExpirationQueueCacheRow(int nHeight
return itQueueRow;
}
bool CClaimTrieCache::reorderTrieNode(const std::string name, bool fCheckTakeover) const
bool CClaimTrieCache::reorderTrieNode(const std::string& name, bool fCheckTakeover) const
{
assert(base);
nodeCacheType::iterator cachedNode;
@ -1584,7 +1592,7 @@ bool CClaimTrieCache::reorderTrieNode(const std::string name, bool fCheckTakeove
return true;
}
bool CClaimTrieCache::getSupportsForName(const std::string name, supportMapEntryType& node) const
bool CClaimTrieCache::getSupportsForName(const std::string& name, supportMapEntryType& node) const
{
supportMapType::iterator cachedNode;
cachedNode = supportCache.find(name);
@ -1599,7 +1607,7 @@ bool CClaimTrieCache::getSupportsForName(const std::string name, supportMapEntry
}
}
bool CClaimTrieCache::insertSupportIntoMap(const std::string name, CSupportValue support, bool fCheckTakeover) const
bool CClaimTrieCache::insertSupportIntoMap(const std::string& name, CSupportValue support, bool fCheckTakeover) const
{
supportMapType::iterator cachedNode;
// If this node is already in the cache, use that
@ -1619,7 +1627,7 @@ bool CClaimTrieCache::insertSupportIntoMap(const std::string name, CSupportValue
return reorderTrieNode(name, fCheckTakeover);
}
bool CClaimTrieCache::removeSupportFromMap(const std::string name, uint256 txhash, uint32_t nOut, int nHeight, int& nValidAtHeight, bool fCheckTakeover) const
bool CClaimTrieCache::removeSupportFromMap(const std::string& name, const COutPoint& outPoint, CSupportValue& support, bool fCheckTakeover) const
{
supportMapType::iterator cachedNode;
cachedNode = supportCache.find(name);
@ -1639,14 +1647,14 @@ bool CClaimTrieCache::removeSupportFromMap(const std::string name, uint256 txhas
supportMapEntryType::iterator itSupport;
for (itSupport = cachedNode->second.begin(); itSupport != cachedNode->second.end(); ++itSupport)
{
if (itSupport->txhash == txhash && itSupport->nOut == nOut && itSupport->nHeight == nHeight)
if (itSupport->outPoint == outPoint)
{
nValidAtHeight = itSupport->nValidAtHeight;
break;
}
}
if (itSupport != cachedNode->second.end())
{
std::swap(support, *itSupport);
cachedNode->second.erase(itSupport);
return reorderTrieNode(name, fCheckTakeover);
}
@ -1695,19 +1703,19 @@ supportQueueNamesType::iterator CClaimTrieCache::getSupportQueueCacheNameRow(con
return itQueueNameRow;
}
bool CClaimTrieCache::addSupportToQueue(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint160 supportedClaimId, int nHeight, int nValidAtHeight) const
bool CClaimTrieCache::addSupportToQueues(const std::string& name, CSupportValue& support) const
{
LogPrintf("%s: nValidAtHeight: %d\n", __func__, nValidAtHeight);
CSupportValue support(txhash, nOut, supportedClaimId, nAmount, nHeight, nValidAtHeight);
LogPrintf("%s: nValidAtHeight: %d\n", __func__, support.nValidAtHeight);
supportQueueEntryType entry(name, support);
supportQueueType::iterator itQueueRow = getSupportQueueCacheRow(nValidAtHeight, true);
supportQueueType::iterator itQueueRow = getSupportQueueCacheRow(support.nValidAtHeight, true);
supportQueueNamesType::iterator itQueueNameRow = getSupportQueueCacheNameRow(name, true);
itQueueRow->second.push_back(entry);
itQueueNameRow->second.push_back(support);
//addSupportToExpirationQueue(entry);
return true;
}
bool CClaimTrieCache::removeSupportFromQueue(const std::string name, uint256 txhash, uint32_t nOut, int& nValidAtHeight) const
bool CClaimTrieCache::removeSupportFromQueue(const std::string& name, const COutPoint& outPoint, CSupportValue& support) const
{
supportQueueNamesType::iterator itQueueNameRow = getSupportQueueCacheNameRow(name, false);
if (itQueueNameRow == supportQueueNameCache.end())
@ -1717,9 +1725,8 @@ bool CClaimTrieCache::removeSupportFromQueue(const std::string name, uint256 txh
std::vector<CSupportValue>::iterator itQueueName;
for (itQueueName = itQueueNameRow->second.begin(); itQueueName != itQueueNameRow->second.end(); ++itQueueName)
{
if (itQueueName->txhash == txhash && itQueueName->nOut == nOut)
if (itQueueName->outPoint == outPoint)
{
nValidAtHeight = itQueueName->nValidAtHeight;
break;
}
}
@ -1727,85 +1734,140 @@ bool CClaimTrieCache::removeSupportFromQueue(const std::string name, uint256 txh
{
return false;
}
supportQueueType::iterator itQueueRow = getSupportQueueCacheRow(nValidAtHeight, false);
supportQueueType::iterator itQueueRow = getSupportQueueCacheRow(itQueueName->nValidAtHeight, false);
if (itQueueRow != supportQueueCache.end())
{
supportQueueRowType::iterator itQueue;
for (itQueue = itQueueRow->second.begin(); itQueue != itQueueRow->second.end(); ++itQueue)
{
CSupportValue& support = itQueue->second;
if (name == itQueue->first && support.txhash == txhash && support.nOut == nOut)
if (name == itQueue->first && support.outPoint == outPoint)
{
nValidAtHeight = support.nValidAtHeight;
break;
}
}
if (itQueue != itQueueRow->second.end())
{
std::swap(support, itQueue->second);
itQueueNameRow->second.erase(itQueueName);
itQueueRow->second.erase(itQueue);
return true;
}
}
LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nFound in named support queue but not in height support queue: name: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, name, txhash.GetHex(), nOut, nValidAtHeight, nCurrentHeight);
LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nFound in named support queue but not in height support queue: name: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, itQueueName->nValidAtHeight, nCurrentHeight);
return false;
}
bool CClaimTrieCache::addSupport(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint160 supportedClaimId, int nHeight) const
bool CClaimTrieCache::addSupport(const std::string& name, const COutPoint& outPoint, CAmount nAmount, uint160 supportedClaimId, int nHeight) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nAmount: %d, supportedClaimId: %s, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, nAmount, supportedClaimId.GetHex(), nHeight, nCurrentHeight);
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nAmount: %d, supportedClaimId: %s, nHeight: %d, nCurrentHeight: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nAmount, supportedClaimId.GetHex(), nHeight, nCurrentHeight);
assert(nHeight == nCurrentHeight);
CClaimValue claim;
if (base->getInfoForName(name, claim))
int delayForSupport;
if (base->getInfoForName(name, claim) && claim.claimId == supportedClaimId)
{
if (claim.claimId == supportedClaimId)
{
LogPrintf("%s: This is a support to a best claim.\n", __func__);
return addSupportToQueue(name, txhash, nOut, nAmount, supportedClaimId, nHeight, nHeight);
}
LogPrintf("%s: This is a support to a best claim.\n", __func__);
delayForSupport = 0;
}
return addSupportToQueue(name, txhash, nOut, nAmount, supportedClaimId, nHeight, nHeight + getDelayForName(name));
else
{
delayForSupport = getDelayForName(name);
}
CSupportValue support(outPoint, supportedClaimId, nAmount, nHeight, nHeight + delayForSupport);
return addSupportToQueues(name, support);
}
bool CClaimTrieCache::undoSpendSupport(const std::string name, uint256 txhash, uint32_t nOut, uint160 supportedClaimId, CAmount nAmount, int nHeight, int nValidAtHeight) const
bool CClaimTrieCache::undoSpendSupport(const std::string& name, const COutPoint& outPoint, uint160 supportedClaimId, CAmount nAmount, int nHeight, int nValidAtHeight) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nAmount: %d, supportedClaimId: %s, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, nAmount, supportedClaimId.GetHex(), nHeight, nCurrentHeight);
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nAmount: %d, supportedClaimId: %s, nHeight: %d, nCurrentHeight: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nAmount, supportedClaimId.GetHex(), nHeight, nCurrentHeight);
CSupportValue support(outPoint, supportedClaimId, nAmount, nHeight, nValidAtHeight);
if (nValidAtHeight < nCurrentHeight)
{
CSupportValue support(txhash, nOut, supportedClaimId, nAmount, nHeight, nValidAtHeight);
supportQueueEntryType entry(name, support);
//addSupportToExpirationQueue(entry);
return insertSupportIntoMap(name, support, false);
}
else
{
return addSupportToQueue(name, txhash, nOut, nAmount, supportedClaimId, nHeight, nValidAtHeight);
return addSupportToQueues(name, support);
}
}
bool CClaimTrieCache::removeSupport(const std::string name, uint256 txhash, uint32_t nOut, int nHeight, int& nValidAtHeight, bool fCheckTakeover) const
bool CClaimTrieCache::removeSupport(const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight, bool fCheckTakeover) const
{
bool removed = false;
if (removeSupportFromQueue(name, txhash, nOut, nValidAtHeight))
CSupportValue support;
if (removeSupportFromQueue(name, outPoint, support))
removed = true;
if (removed == false && removeSupportFromMap(name, txhash, nOut, nHeight, nValidAtHeight, fCheckTakeover))
if (removed == false && removeSupportFromMap(name, outPoint, support, fCheckTakeover))
removed = true;
if (removed)
nValidAtHeight = support.nValidAtHeight;
return removed;
}
bool CClaimTrieCache::undoAddSupport(const std::string name, uint256 txhash, uint32_t nOut, int nHeight) const
/*void CClaimTrieCache::addSupportToExpirationQueue(supportQueueEntryType& entry) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, nHeight, nCurrentHeight);
int expirationHeight = entry.second.nHeight + base->nExpirationTime;
supportQueueType::iterator itQueueRow = getSupportExpirationQueueCacheRow(expirationHeight, true);
itQueueRow->second.push_back(entry);
}*/
/*void CClaimTrieCache::removeSupportFromExpirationQueue(const std::string& name, const COutPoint& outPoint, int nHeight) const
{
int expirationHeight = nHeight + base->nExpirationTime;
supportQueueType::iterator itQueueRow = getSupportExpirationQueueCacheRow(expirationHeight, false);
supportQueueRowType::iterator itQueue;
if (itQueueRow != supportExpirationQueueCache.end())
{
for (itQueue = itQueueRow->second.begin(); itQueue != itQueueRow->second.end(); ++itQueue)
{
CSupportValue& support = itQueue->second;
if (name == itQueue->first && support.outPoint == outPoint)
break;
}
}
if (itQueue != itQueueRow->second.end())
{
itQueueRow->second.erase(itQueue);
}
}*/
/*supportQueueType::iterator CClaimTrieCache::getSupportExpirationQueueCacheRow(int nHeight, bool createIfNotExists) const
{
supportQueueType::iterator itQueueRow = supportExpirationQueueCache.find(nHeight);
if (itQueueRow == supportExpirationQueueCache.end())
{
// Have to make a new row it put in the cache, if createIfNotExists is true
supportQueueRowType queueRow;
// If the row exists in the base, copy its claims into the new row.
bool exists = base->getSupportExpirationQueueRow(nHeight, queueRow);
if (!exists)
if (!createIfNotExists)
return itQueueRow;
// Stick the new row in the cache
std::pair<supportQueueType::iterator, bool> ret;
ret = supportExpirationQueueCache.insert(std::pair<int, supportQueueRowType >(nHeight, queueRow));
assert(ret.second);
itQueueRow = ret.first;
}
return itQueueRow;
}*/
bool CClaimTrieCache::undoAddSupport(const std::string& name, const COutPoint& outPoint, int nHeight) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nHeight, nCurrentHeight);
int throwaway;
return removeSupport(name, txhash, nOut, nHeight, throwaway, false);
return removeSupport(name, outPoint, nHeight, throwaway, false);
}
bool CClaimTrieCache::spendSupport(const std::string name, uint256 txhash, uint32_t nOut, int nHeight, int& nValidAtHeight) const
bool CClaimTrieCache::spendSupport(const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, nHeight, nCurrentHeight);
return removeSupport(name, txhash, nOut, nHeight, nValidAtHeight, true);
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, outPoint.hash.GetHex(), outPoint.n, nHeight, nCurrentHeight);
return removeSupport(name, outPoint, nHeight, nValidAtHeight, true);
}
bool CClaimTrieCache::incrementBlock(claimQueueRowType& insertUndo, claimQueueRowType& expireUndo, supportQueueRowType& insertSupportUndo, std::vector<std::pair<std::string, int> >& takeoverHeightUndo) const
bool CClaimTrieCache::incrementBlock(claimQueueRowType& insertUndo, claimQueueRowType& expireUndo, supportQueueRowType& insertSupportUndo,/* supportQueueRowType& expireSupportUndo,*/ std::vector<std::pair<std::string, int> >& takeoverHeightUndo) const
{
LogPrintf("%s: nCurrentHeight (before increment): %d\n", __func__, nCurrentHeight);
claimQueueType::iterator itQueueRow = getQueueCacheRow(nCurrentHeight, false);
@ -1829,13 +1891,13 @@ bool CClaimTrieCache::incrementBlock(claimQueueRowType& insertUndo, claimQueueRo
}
if (!found)
{
LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nFound in height queue but not in named queue: name: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, itEntry->first, itEntry->second.txhash.GetHex(), itEntry->second.nOut, itEntry->second.nValidAtHeight, nCurrentHeight);
LogPrintf("%s: An inconsistency was found in the claim queue. Please report this to the developers:\nFound in height queue but not in named queue: name: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, itEntry->first, itEntry->second.outPoint.hash.GetHex(), itEntry->second.outPoint.n, itEntry->second.nValidAtHeight, nCurrentHeight);
if (itQueueNameRow != claimQueueNameCache.end())
{
LogPrintf("Claims found for that name:\n");
for (std::vector<CClaimValue>::iterator itQueueName = itQueueNameRow->second.begin(); itQueueName != itQueueNameRow->second.end(); ++itQueueName)
{
LogPrintf("\ttxid: %s, nOut: %d, nValidAtHeight: %d\n", itQueueName->txhash.GetHex(), itQueueName->nOut, itQueueName->nValidAtHeight);
LogPrintf("\ttxid: %s, nOut: %d, nValidAtHeight: %d\n", itQueueName->outPoint.hash.GetHex(), itQueueName->outPoint.n, itQueueName->nValidAtHeight);
}
}
else
@ -1853,9 +1915,9 @@ bool CClaimTrieCache::incrementBlock(claimQueueRowType& insertUndo, claimQueueRo
{
for (claimQueueRowType::iterator itEntry = itExpirationRow->second.begin(); itEntry != itExpirationRow->second.end(); ++itEntry)
{
int nValidAtHeight;
assert(removeClaimFromTrie(itEntry->first, itEntry->second.txhash, itEntry->second.nOut, nValidAtHeight, true));
expireUndo.push_back(*itEntry);
CClaimValue claim;
assert(removeClaimFromTrie(itEntry->first, itEntry->second.outPoint, claim, true));
expireUndo.push_back(std::make_pair(itEntry->first, claim));
}
itExpirationRow->second.clear();
}
@ -1880,13 +1942,13 @@ bool CClaimTrieCache::incrementBlock(claimQueueRowType& insertUndo, claimQueueRo
}
if (!found)
{
LogPrintf("%s: An inconsistency was found in the support queue. Please report this to the developers:\nFound in height queue but not in named queue: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, itSupport->first, itSupport->second.txhash.GetHex(), itSupport->second.nOut, itSupport->second.nValidAtHeight, nCurrentHeight);
LogPrintf("%s: An inconsistency was found in the support queue. Please report this to the developers:\nFound in height queue but not in named queue: %s, txid: %s, nOut: %d, nValidAtHeight: %d, current height: %d\n", __func__, itSupport->first, itSupport->second.outPoint.hash.GetHex(), itSupport->second.outPoint.n, itSupport->second.nValidAtHeight, nCurrentHeight);
if (itSupportNameRow != supportQueueNameCache.end())
{
LogPrintf("Supports found for that name:\n");
for (std::vector<CSupportValue>::iterator itSupportName = itSupportNameRow->second.begin(); itSupportName != itSupportNameRow->second.end(); ++itSupportName)
{
LogPrintf("\ttxid: %s, nOut: %d, nValidAtHeight: %d\n", itSupportName->txhash.GetHex(), itSupportName->nOut, itSupportName->nValidAtHeight);
LogPrintf("\ttxid: %s, nOut: %d, nValidAtHeight: %d\n", itSupportName->outPoint.hash.GetHex(), itSupportName->outPoint.n, itSupportName->nValidAtHeight);
}
}
else
@ -1899,12 +1961,22 @@ bool CClaimTrieCache::incrementBlock(claimQueueRowType& insertUndo, claimQueueRo
}
itSupportRow->second.clear();
}
/*supportQueueType::iterator itSupportExpirationRow = getSupportExpirationQueueCacheRow(nCurrentHeight, false);
if (itSupportExpirationRow != supportExpirationQueueCache.end())
{
for (supportQueueRowType::iterator itEntry = itSupportExpirationRow->second.begin(); itEntry != itSupportExpirationRow->second.end(); ++itEntry)
{
int nValidAtHeight;
assert(removeSupportFromMap(itEntry->first, itEntry->second.outPoint, nValidAtHeight, true));
supportExpireUndo.push_back(*itEntry);
}
}*/
// check each potentially taken over name to see if a takeover occurred.
// if it did, then check the claim and support insertion queues for
// the names that have been taken over, immediately insert all claim and
// supports for those names, and stick them in the insertUndo or
// insertSupportUndo vectors, with the nValidAtHeight they had prior to
// this block
// this block.
// Run through all names that have been taken over
for (std::set<std::string>::iterator itNamesToCheck = namesToCheckForTakeover.begin(); itNamesToCheck != namesToCheckForTakeover.end(); ++itNamesToCheck)
{
@ -2061,8 +2133,8 @@ bool CClaimTrieCache::decrementBlock(claimQueueRowType& insertUndo, claimQueueRo
for (claimQueueRowType::iterator itInsertUndo = insertUndo.begin(); itInsertUndo != insertUndo.end(); ++itInsertUndo)
{
claimQueueType::iterator itQueueRow = getQueueCacheRow(itInsertUndo->second.nValidAtHeight, true);
int nValidHeightInTrie;
assert(removeClaimFromTrie(itInsertUndo->first, itInsertUndo->second.txhash, itInsertUndo->second.nOut, nValidHeightInTrie, false));
CClaimValue claim;
assert(removeClaimFromTrie(itInsertUndo->first, itInsertUndo->second.outPoint, claim, false));
claimQueueNamesType::iterator itQueueNameRow = getQueueCacheNameRow(itInsertUndo->first, true);
itQueueRow->second.push_back(*itInsertUndo);
itQueueNameRow->second.push_back(itInsertUndo->second);
@ -2079,8 +2151,8 @@ bool CClaimTrieCache::decrementBlock(claimQueueRowType& insertUndo, claimQueueRo
for (supportQueueRowType::iterator itSupportUndo = insertSupportUndo.begin(); itSupportUndo != insertSupportUndo.end(); ++itSupportUndo)
{
supportQueueType::iterator itSupportRow = getSupportQueueCacheRow(itSupportUndo->second.nValidAtHeight, true);
int nValidHeightInMap;
assert(removeSupportFromMap(itSupportUndo->first, itSupportUndo->second.txhash, itSupportUndo->second.nOut, itSupportUndo->second.nHeight, nValidHeightInMap, false));
CSupportValue support;
assert(removeSupportFromMap(itSupportUndo->first, itSupportUndo->second.outPoint, support, false));
supportQueueNamesType::iterator itSupportNameRow = getSupportQueueCacheNameRow(itSupportUndo->first, true);
itSupportRow->second.push_back(*itSupportUndo);
itSupportNameRow->second.push_back(itSupportUndo->second);

View file

@ -6,6 +6,7 @@
#include "uint256.h"
#include "util.h"
#include "leveldbwrapper.h"
#include "primitives/transaction.h"
#include <string>
#include <vector>
@ -24,8 +25,7 @@
class CClaimValue
{
public:
uint256 txhash;
uint32_t nOut;
COutPoint outPoint;
uint160 claimId;
CAmount nAmount;
CAmount nEffectiveAmount;
@ -34,9 +34,9 @@ public:
CClaimValue() {};
CClaimValue(uint256 txhash, uint32_t nOut, uint160 claimId, CAmount nAmount, int nHeight,
CClaimValue(COutPoint outPoint, uint160 claimId, CAmount nAmount, int nHeight,
int nValidAtHeight)
: txhash(txhash), nOut(nOut), claimId(claimId)
: outPoint(outPoint), claimId(claimId)
, nAmount(nAmount), nEffectiveAmount(nAmount)
, nHeight(nHeight), nValidAtHeight(nValidAtHeight)
{}
@ -47,8 +47,7 @@ public:
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(txhash);
READWRITE(nOut);
READWRITE(outPoint);
READWRITE(claimId);
READWRITE(nAmount);
READWRITE(nHeight);
@ -65,11 +64,8 @@ public:
return true;
else if (nHeight == other.nHeight)
{
if (txhash.GetHex() > other.txhash.GetHex())
if (outPoint != other.outPoint && !(outPoint < other.outPoint))
return true;
else if (txhash == other.txhash)
if (nOut > other.nOut)
return true;
}
}
return false;
@ -77,7 +73,7 @@ public:
bool operator==(const CClaimValue& other) const
{
return txhash == other.txhash && nOut == other.nOut && claimId == other.claimId && nAmount == other.nAmount && nHeight == other.nHeight && nValidAtHeight == other.nValidAtHeight;
return outPoint == other.outPoint && claimId == other.claimId && nAmount == other.nAmount && nHeight == other.nHeight && nValidAtHeight == other.nValidAtHeight;
}
bool operator!=(const CClaimValue& other) const
@ -89,27 +85,25 @@ public:
class CSupportValue
{
public:
uint256 txhash;
uint32_t nOut;
COutPoint outPoint;
uint160 supportedClaimId;
CAmount nAmount;
int nHeight;
int nValidAtHeight;
CSupportValue() {};
CSupportValue(uint256 txhash, uint32_t nOut, uint160 supportedClaimId,
CSupportValue(COutPoint outPoint, uint160 supportedClaimId,
CAmount nAmount, int nHeight, int nValidAtHeight)
: txhash(txhash), nOut(nOut)
, supportedClaimId(supportedClaimId), nAmount(nAmount)
, nHeight(nHeight), nValidAtHeight(nValidAtHeight)
: outPoint(outPoint), supportedClaimId(supportedClaimId)
, nAmount(nAmount), nHeight(nHeight)
, nValidAtHeight(nValidAtHeight)
{}
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(txhash);
READWRITE(nOut);
READWRITE(outPoint);
READWRITE(supportedClaimId);
READWRITE(nAmount);
READWRITE(nHeight);
@ -118,8 +112,9 @@ public:
bool operator==(const CSupportValue& other) const
{
return txhash == other.txhash && nOut == other.nOut && supportedClaimId == other.supportedClaimId && nAmount == other.nAmount && nHeight == other.nHeight && nValidAtHeight == other.nValidAtHeight;
return outPoint == other.outPoint && supportedClaimId == other.supportedClaimId && nAmount == other.nAmount && nHeight == other.nHeight && nValidAtHeight == other.nValidAtHeight;
}
bool operator!=(const CSupportValue& other) const
{
return !(*this == other);
@ -146,10 +141,10 @@ public:
std::vector<CClaimValue> claims;
bool insertClaim(CClaimValue claim);
bool removeClaim(uint256& txhash, uint32_t nOut, CClaimValue& claim);
bool removeClaim(const COutPoint& outPoint, CClaimValue& claim);
bool getBestClaim(CClaimValue& claim) const;
bool empty() const {return children.empty() && claims.empty();}
bool haveClaim(const uint256& txhash, uint32_t nOut) const;
bool haveClaim(const COutPoint& outPoint) const;
void reorderClaims(supportMapEntryType& supports);
ADD_SERIALIZE_METHODS;
@ -230,6 +225,7 @@ public:
bool supportEmpty() const;
bool supportQueueEmpty() const;
bool expirationQueueEmpty() const;
bool supportExpirationQueueEmpty() const;
void setExpirationTime(int t);
@ -239,16 +235,15 @@ public:
bool getSupportNode(std::string name, supportMapEntryType& node) const;
bool getSupportQueueRow(int nHeight, supportQueueRowType& row) const;
bool getSupportQueueNameRow(const std::string& name, std::vector<CSupportValue>& row) const;
bool getSupportExpirationQueueRow(int nHeight, supportQueueRowType& row) const;
bool haveClaim(const std::string& name, const uint256& txhash,
uint32_t nOut) const;
bool haveClaimInQueue(const std::string& name, const uint256& txhash,
uint32_t nOut, int& nValidAtHeight) const;
bool haveClaim(const std::string& name, const COutPoint& outPoint) const;
bool haveClaimInQueue(const std::string& name, const COutPoint& outPoint,
int& nValidAtHeight) const;
bool haveSupport(const std::string& name, const uint256& txhash,
uint32_t nOut) const;
bool haveSupportInQueue(const std::string& name, const uint256& txhash,
uint32_t nOut, int& nValidAtHeight) const;
bool haveSupport(const std::string& name, const COutPoint& outPoint) const;
bool haveSupportInQueue(const std::string& name, const COutPoint& outPoint,
int& nValidAtHeight) const;
unsigned int getTotalNamesInTrie() const;
unsigned int getTotalClaimsInTrie() const;
@ -272,7 +267,8 @@ private:
claimQueueType& expirationQueueCache, int nNewHeight,
supportMapType& supportCache,
supportQueueType& supportQueueCache,
supportQueueNamesType& supportQueueNameCache);
supportQueueNamesType& supportQueueNameCache);//,
//supportQueueType& supportExpirationQueueCache);
bool updateName(const std::string& name, CClaimTrieNode* updatedNode);
bool updateHash(const std::string& name, uint256& hash);
bool updateTakeoverHeight(const std::string& name, int nTakeoverHeight);
@ -299,6 +295,7 @@ private:
void updateSupportQueue(int nHeight, supportQueueRowType& row);
void updateSupportNameQueue(const std::string& name,
std::vector<CSupportValue>& row);
void updateSupportExpirationRow(int nHeight, supportQueueRowType& row);
void BatchWriteNode(CLevelDBBatch& batch, const std::string& name,
const CClaimTrieNode* pNode) const;
@ -309,6 +306,7 @@ private:
void BatchWriteSupportNodes(CLevelDBBatch& batch);
void BatchWriteSupportQueueRows(CLevelDBBatch& batch);
void BatchWriteSupportQueueNameRows(CLevelDBBatch& batch);
void BatchWriteSupportExpirationQueueRows(CLevelDBBatch& batch);
template<typename K> bool keyTypeEmpty(char key, K& dummy) const;
CClaimTrieNode root;
@ -320,6 +318,7 @@ private:
supportQueueType dirtySupportQueueRows;
supportQueueNamesType dirtySupportQueueNameRows;
supportQueueType dirtySupportExpirationQueueRows;
nodeCacheType dirtyNodes;
supportMapType dirtySupportNodes;
@ -342,26 +341,26 @@ public:
bool flush();
bool dirty() const { return !dirtyHashes.empty(); }
bool addClaim(const std::string name, uint256 txhash, uint32_t nOut,
bool addClaim(const std::string& name, const COutPoint& outPoint,
uint160 claimId, CAmount nAmount, int nHeight) const;
bool undoAddClaim(const std::string name, uint256 txhash, uint32_t nOut,
bool undoAddClaim(const std::string& name, const COutPoint& outPoint,
int nHeight) const;
bool spendClaim(const std::string name, uint256 txhash, uint32_t nOut,
bool spendClaim(const std::string& name, const COutPoint& outPoint,
int nHeight, int& nValidAtHeight) const;
bool undoSpendClaim(const std::string name, uint256 txhash, uint32_t nOut,
bool undoSpendClaim(const std::string& name, const COutPoint& outPoint,
uint160 claimId, CAmount nAmount, int nHeight,
int nValidAtHeight) const;
bool addSupport(const std::string name, uint256 txhash, uint32_t nOut,
bool addSupport(const std::string& name, const COutPoint& outPoint,
CAmount nAmount, uint160 supportedClaimId,
int nHeight) const;
bool undoAddSupport(const std::string name, uint256 txhash, uint32_t nOut,
bool undoAddSupport(const std::string& name, const COutPoint& outPoint,
int nHeight) const;
bool spendSupport(const std::string name, uint256 txhash, uint32_t nOut,
bool spendSupport(const std::string& name, const COutPoint& outPoint,
int nHeight, int& nValidAtHeight) const;
bool undoSpendSupport(const std::string name, uint256 txhash,
uint32_t nOut, uint160 supportedClaimId,
CAmount nAmount, int nHeight, int nValidAtHeight) const;
bool undoSpendSupport(const std::string& name, const COutPoint& outPoint,
uint160 supportedClaimId, CAmount nAmount,
int nHeight, int nValidAtHeight) const;
uint256 getBestBlock();
void setBestBlock(const uint256& hashBlock);
@ -369,18 +368,20 @@ public:
bool incrementBlock(claimQueueRowType& insertUndo,
claimQueueRowType& expireUndo,
supportQueueRowType& insertSupportUndo,
// supportQueueRowType& expireSupportUndo,
std::vector<std::pair<std::string, int> >& takeoverHeightUndo) const;
bool decrementBlock(claimQueueRowType& insertUndo,
claimQueueRowType& expireUndo,
supportQueueRowType& insertSupportUndo,
// supportQueueRowType& expireSupportUndo,
std::vector<std::pair<std::string, int> >& takeoverHeightUndo) const;
~CClaimTrieCache() { clear(); }
bool insertClaimIntoTrie(const std::string name, CClaimValue claim,
bool insertClaimIntoTrie(const std::string& name, CClaimValue claim,
bool fCheckTakeover = false) const;
bool removeClaimFromTrie(const std::string name, uint256 txhash,
uint32_t nOut, int& nValidAtHeight,
bool removeClaimFromTrie(const std::string& name, const COutPoint& outPoint,
CClaimValue& claim,
bool fCheckTakeover = false) const;
private:
CClaimTrie* base;
@ -396,6 +397,7 @@ private:
mutable supportMapType supportCache;
mutable supportQueueType supportQueueCache;
mutable supportQueueNamesType supportQueueNameCache;
mutable supportQueueType supportExpirationQueueCache;
mutable std::set<std::string> namesToCheckForTakeover;
mutable std::map<std::string, int> cacheTakeoverHeights;
mutable int nCurrentHeight; // Height of the block that is being worked on, which is
@ -405,7 +407,7 @@ private:
uint256 computeHash() const;
bool reorderTrieNode(const std::string name, bool fCheckTakeover) const;
bool reorderTrieNode(const std::string& name, bool fCheckTakeover) const;
bool recursiveComputeMerkleHash(CClaimTrieNode* tnCurrent,
std::string sPos) const;
bool recursivePruneName(CClaimTrieNode* tnCurrent, unsigned int nPos,
@ -414,15 +416,15 @@ private:
bool clear() const;
bool removeClaim(const std::string name, uint256 txhash, uint32_t nOut,
bool removeClaim(const std::string& name, const COutPoint& outPoint,
int nHeight, int& nValidAtHeight, bool fCheckTakeover) const;
bool addClaimToQueues(const std::string name, CClaimValue& claim) const;
bool removeClaimFromQueue(const std::string name, uint256 txhash,
uint32_t nOut, int& nValidAtHeight) const;
bool addClaimToQueues(const std::string& name, CClaimValue& claim) const;
bool removeClaimFromQueue(const std::string& name, const COutPoint& outPoint,
CClaimValue& claim) const;
void addToExpirationQueue(claimQueueEntryType& entry) const;
void removeFromExpirationQueue(const std::string name, uint256 txhash,
uint32_t nOut, int nHeight) const;
void removeFromExpirationQueue(const std::string& name, const COutPoint& outPoint,
int nHeight) const;
claimQueueType::iterator getQueueCacheRow(int nHeight,
bool createIfNotExists) const;
@ -431,14 +433,14 @@ private:
claimQueueType::iterator getExpirationQueueCacheRow(int nHeight,
bool createIfNotExists) const;
bool removeSupport(const std::string name, uint256 txhash, uint32_t nOut,
bool removeSupport(const std::string& name, const COutPoint& outPoint,
int nHeight, int& nValidAtHeight,
bool fCheckTakeover) const;
bool removeSupportFromMap(const std::string name, uint256 txhash,
uint32_t nOut, int nHeight, int& nValidAtHeight,
bool removeSupportFromMap(const std::string& name, const COutPoint& outPoint,
CSupportValue& support,
bool fCheckTakeover) const;
bool insertSupportIntoMap(const std::string name,
bool insertSupportIntoMap(const std::string& name,
CSupportValue support,
bool fCheckTakeover) const;
@ -446,15 +448,19 @@ private:
bool createIfNotExists) const;
supportQueueNamesType::iterator getSupportQueueCacheNameRow(const std::string& name,
bool createIfNotExists) const;
supportQueueType::iterator getSupportExpirationQueueCacheRow(int nHeight,
bool createIfNotExists) const;
bool addSupportToQueues(const std::string& name, CSupportValue& support) const;
bool removeSupportFromQueue(const std::string& name, const COutPoint& outPoint,
CSupportValue& support) const;
void addSupportToExpirationQueue(supportQueueEntryType& entry) const;
void removeSupportFromExpirationQueue(const std::string& name,
const COutPoint& outPoint,
int nHeight) const;
bool addSupportToQueue(const std::string name, uint256 txhash,
uint32_t nOut, CAmount nAmount,
uint160 supportedClaimId,
int nHeight, int nValidAtHeight) const;
bool removeSupportFromQueue(const std::string name, uint256 txhash,
uint32_t nOut, int& nValidAtHeight) const;
bool getSupportsForName(const std::string name,
bool getSupportsForName(const std::string& name,
supportMapEntryType& node) const;
bool getLastTakeoverForName(const std::string& name, int& lastTakeoverHeight) const;

View file

@ -1559,7 +1559,7 @@ static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, CClaimTr
if (nValidHeight > 0 && nValidHeight >= coins->nHeight)
{
LogPrintf("%s: (txid: %s, nOut: %d) Restoring %s to the claim trie due to a block being disconnected\n", __func__, out.hash.ToString(), out.n, name.c_str());
if (!trieCache.undoSpendClaim(name, out.hash, out.n, claimId, undo.txout.nValue, coins->nHeight, nValidHeight))
if (!trieCache.undoSpendClaim(name, COutPoint(out.hash, out.n), claimId, undo.txout.nValue, coins->nHeight, nValidHeight))
LogPrintf("%s: Something went wrong inserting the claim\n", __func__);
}
else
@ -1576,7 +1576,7 @@ static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, CClaimTr
if (nValidHeight > 0 && nValidHeight >= coins->nHeight)
{
LogPrintf("%s: (txid: %s, nOut: %d) Restoring support for %s in claimid %s due to a block being disconnected\n", __func__, out.hash.ToString(), out.n, name, supportedClaimId.ToString());
if (!trieCache.undoSpendSupport(name, out.hash, out.n, supportedClaimId, undo.txout.nValue, coins->nHeight, nValidHeight))
if (!trieCache.undoSpendSupport(name, COutPoint(out.hash, out.n), supportedClaimId, undo.txout.nValue, coins->nHeight, nValidHeight))
LogPrintf("%s: Something went wrong inserting support for the claim\n", __func__);
}
else
@ -1657,7 +1657,7 @@ bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockI
}
std::string name(vvchParams[0].begin(), vvchParams[0].end());
LogPrintf("%s: (txid: %s, nOut: %d) Trying to remove %s from the claim trie due to its block being disconnected\n", __func__, hash.ToString(), i, name.c_str());
if (!trieCache.undoAddClaim(name, hash, i, pindex->nHeight))
if (!trieCache.undoAddClaim(name, COutPoint(hash, i), pindex->nHeight))
{
LogPrintf("%s: Could not find the claim in the trie or the cache\n", __func__);
}
@ -1668,7 +1668,7 @@ bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockI
std::string name(vvchParams[0].begin(), vvchParams[0].end());
uint160 supportedClaimId(vvchParams[1]);
LogPrintf("%s: (txid: %s, nOut: %d) Removing support for claim id %s on %s due to its block being disconnected\n", __func__, hash.ToString(), i, supportedClaimId.ToString(), name.c_str());
if (!trieCache.undoAddSupport(name, hash, i, pindex->nHeight))
if (!trieCache.undoAddSupport(name, COutPoint(hash, i), pindex->nHeight))
LogPrintf("%s: Something went wrong removing support for name %s in hash %s\n", __func__, name.c_str(), hash.ToString());
}
}
@ -1960,7 +1960,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
std::string name(vvchParams[0].begin(), vvchParams[0].end());
int nValidAtHeight;
LogPrintf("%s: Removing %s from the claim trie. Tx: %s, nOut: %d\n", __func__, name, txin.prevout.hash.GetHex(), txin.prevout.n);
if (trieCache.spendClaim(name, txin.prevout.hash, txin.prevout.n, coins->nHeight, nValidAtHeight))
if (trieCache.spendClaim(name, COutPoint(txin.prevout.hash, txin.prevout.n), coins->nHeight, nValidAtHeight))
{
mClaimUndoHeights[i] = nValidAtHeight;
std::pair<std::string, uint160> entry(name, claimId);
@ -1974,7 +1974,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
uint160 supportedClaimId(vvchParams[1]);
int nValidAtHeight;
LogPrintf("%s: Removing support for %s in %s. Tx: %s, nOut: %d\n", __func__, supportedClaimId.ToString(), name, txin.prevout.hash.ToString(), txin.prevout.n);
if (trieCache.spendSupport(name, txin.prevout.hash, txin.prevout.n, coins->nHeight, nValidAtHeight))
if (trieCache.spendSupport(name, COutPoint(txin.prevout.hash, txin.prevout.n), coins->nHeight, nValidAtHeight))
{
mClaimUndoHeights[0] = nValidAtHeight;
}
@ -1995,7 +1995,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
LogPrintf("%s: Inserting %s into the claim trie. Tx: %s, nOut: %d\n", __func__, name, tx.GetHash().GetHex(), i);
if (!trieCache.addClaim(name, tx.GetHash(), i, ClaimIdHash(tx.GetHash(), i), txout.nValue, pindex->nHeight))
if (!trieCache.addClaim(name, COutPoint(tx.GetHash(), i), ClaimIdHash(tx.GetHash(), i), txout.nValue, pindex->nHeight))
{
LogPrintf("%s: Something went wrong inserting the claim\n", __func__);
}
@ -2017,7 +2017,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
if (itSpent != spentClaims.end())
{
spentClaims.erase(itSpent);
if (!trieCache.addClaim(name, tx.GetHash(), i, claimId, txout.nValue, pindex->nHeight))
if (!trieCache.addClaim(name, COutPoint(tx.GetHash(), i), claimId, txout.nValue, pindex->nHeight))
{
LogPrintf("%s: Something went wrong updating the claim\n", __func__);
}
@ -2028,7 +2028,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
uint160 supportedClaimId(vvchParams[1]);
if (!trieCache.addSupport(name, tx.GetHash(), i, txout.nValue, supportedClaimId, pindex->nHeight))
if (!trieCache.addSupport(name, COutPoint(tx.GetHash(), i), txout.nValue, supportedClaimId, pindex->nHeight))
{
LogPrintf("%s: Something went wrong inserting the support\n", __func__);
}

View file

@ -334,7 +334,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
}
std::string name(vvchParams[0].begin(), vvchParams[0].end());
int throwaway;
if (trieCache.spendClaim(name, txin.prevout.hash, txin.prevout.n, coins->nHeight, throwaway))
if (trieCache.spendClaim(name, COutPoint(txin.prevout.hash, txin.prevout.n), coins->nHeight, throwaway))
{
std::pair<std::string, uint160> entry(name, claimId);
spentClaims.push_back(entry);
@ -349,7 +349,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
int throwaway;
if (!trieCache.spendSupport(name, txin.prevout.hash, txin.prevout.n, coins->nHeight, throwaway))
if (!trieCache.spendSupport(name, COutPoint(txin.prevout.hash, txin.prevout.n), coins->nHeight, throwaway))
{
LogPrintf("%s(): The support was not found in the trie or queue\n", __func__);
}
@ -371,7 +371,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
{
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
if (!trieCache.addClaim(name, tx.GetHash(), i, ClaimIdHash(tx.GetHash(), i), txout.nValue, nHeight))
if (!trieCache.addClaim(name, COutPoint(tx.GetHash(), i), ClaimIdHash(tx.GetHash(), i), txout.nValue, nHeight))
{
LogPrintf("%s: Something went wrong inserting the name\n", __func__);
}
@ -392,7 +392,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
if (itSpent != spentClaims.end())
{
spentClaims.erase(itSpent);
if (!trieCache.addClaim(name, tx.GetHash(), i, claimId, txout.nValue, nHeight))
if (!trieCache.addClaim(name, COutPoint(tx.GetHash(), i), claimId, txout.nValue, nHeight))
{
LogPrintf("%s: Something went wrong updating a claim\n", __func__);
}
@ -407,7 +407,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
uint160 supportedClaimId(vvchParams[1]);
if (!trieCache.addSupport(name, tx.GetHash(), i, txout.nValue, supportedClaimId, nHeight))
if (!trieCache.addSupport(name, COutPoint(tx.GetHash(), i), txout.nValue, supportedClaimId, nHeight))
{
LogPrintf("%s: Something went wrong inserting the claim support\n", __func__);
}

View file

@ -35,8 +35,8 @@ UniValue getclaimtrie(const UniValue& params, bool fHelp)
CClaimValue claim;
if (it->second.getBestClaim(claim))
{
node.push_back(Pair("txid", claim.txhash.GetHex()));
node.push_back(Pair("n", (int)claim.nOut));
node.push_back(Pair("txid", claim.outPoint.hash.GetHex()));
node.push_back(Pair("n", (int)claim.outPoint.n));
node.push_back(Pair("value", ValueFromAmount(claim.nAmount)));
node.push_back(Pair("height", claim.nHeight));
}
@ -67,29 +67,29 @@ UniValue getvalueforname(const UniValue& params, bool fHelp)
if (!pclaimTrie->getInfoForName(name, claim))
return ret;
CCoinsViewCache view(pcoinsTip);
const CCoins* coin = view.AccessCoins(claim.txhash);
const CCoins* coin = view.AccessCoins(claim.outPoint.hash);
if (!coin)
{
LogPrintf("%s: %s does not exist in the coins view, despite being associated with a name\n",
__func__, claim.txhash.GetHex());
__func__, claim.outPoint.hash.GetHex());
return ret;
}
if (coin->vout.size() < claim.nOut || coin->vout[claim.nOut].IsNull())
if (coin->vout.size() < claim.outPoint.n || coin->vout[claim.outPoint.n].IsNull())
{
LogPrintf("%s: the specified txout of %s appears to have been spent\n", __func__, claim.txhash.GetHex());
LogPrintf("%s: the specified txout of %s appears to have been spent\n", __func__, claim.outPoint.hash.GetHex());
return ret;
}
int op;
std::vector<std::vector<unsigned char> > vvchParams;
if (!DecodeClaimScript(coin->vout[claim.nOut].scriptPubKey, op, vvchParams))
if (!DecodeClaimScript(coin->vout[claim.outPoint.n].scriptPubKey, op, vvchParams))
{
LogPrintf("%s: the specified txout of %s does not have a name claim command\n", __func__, claim.txhash.GetHex());
LogPrintf("%s: the specified txout of %s does not have a name claim command\n", __func__, claim.outPoint.hash.GetHex());
}
std::string sValue(vvchParams[1].begin(), vvchParams[1].end());
ret.push_back(Pair("value", sValue));
ret.push_back(Pair("txid", claim.txhash.GetHex()));
ret.push_back(Pair("n", (int)claim.nOut));
ret.push_back(Pair("txid", claim.outPoint.hash.GetHex()));
ret.push_back(Pair("n", (int)claim.outPoint.n));
ret.push_back(Pair("amount", claim.nAmount));
ret.push_back(Pair("height", claim.nHeight));
return ret;
@ -256,7 +256,7 @@ UniValue getclaimsfortx(const UniValue& params, bool fHelp)
o.push_back(Pair("depth", chainActive.Height() - nHeight));
if (op == OP_CLAIM_NAME || op == OP_UPDATE_CLAIM)
{
bool inClaimTrie = pclaimTrie->haveClaim(sName, hash, i);
bool inClaimTrie = pclaimTrie->haveClaim(sName, COutPoint(hash, i));
o.push_back(Pair("in claim trie", inClaimTrie));
if (inClaimTrie)
{
@ -265,12 +265,12 @@ UniValue getclaimsfortx(const UniValue& params, bool fHelp)
{
LogPrintf("HaveClaim was true but getInfoForName returned false.");
}
o.push_back(Pair("is controlling", (claim.txhash == hash && claim.nOut == i)));
o.push_back(Pair("is controlling", (claim.outPoint.hash == hash && claim.outPoint.n == i)));
}
else
{
int nValidAtHeight;
if (pclaimTrie->haveClaimInQueue(sName, hash, i, nValidAtHeight))
if (pclaimTrie->haveClaimInQueue(sName, COutPoint(hash, i), nValidAtHeight))
{
o.push_back(Pair("in queue", true));
o.push_back(Pair("blocks to valid", nValidAtHeight - chainActive.Height()));
@ -283,12 +283,12 @@ UniValue getclaimsfortx(const UniValue& params, bool fHelp)
}
else if (op == OP_SUPPORT_CLAIM)
{
bool inSupportMap = pclaimTrie->haveSupport(sName, hash, i);
bool inSupportMap = pclaimTrie->haveSupport(sName, COutPoint(hash, i));
o.push_back(Pair("in support map", inSupportMap));
if (!inSupportMap)
{
int nValidAtHeight;
if (pclaimTrie->haveSupportInQueue(sName, hash, i, nValidAtHeight))
if (pclaimTrie->haveSupportInQueue(sName, COutPoint(hash, i), nValidAtHeight))
{
o.push_back(Pair("in queue", true));
o.push_back(Pair("blocks to valid", nValidAtHeight - chainActive.Height()));

View file

@ -148,15 +148,21 @@ bool CreateBlocks(unsigned int num_blocks, unsigned int num_txs)
BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
{
int unused;
CClaimValue unused;
uint256 hash0(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
uint160 hash160;
CMutableTransaction tx1 = BuildTransaction(hash0);
COutPoint tx1OutPoint(tx1.GetHash(), 0);
CMutableTransaction tx2 = BuildTransaction(tx1.GetHash());
COutPoint tx2OutPoint(tx2.GetHash(), 0);
CMutableTransaction tx3 = BuildTransaction(tx2.GetHash());
COutPoint tx3OutPoint(tx3.GetHash(), 0);
CMutableTransaction tx4 = BuildTransaction(tx3.GetHash());
COutPoint tx4OutPoint(tx4.GetHash(), 0);
CMutableTransaction tx5 = BuildTransaction(tx4.GetHash());
COutPoint tx5OutPoint(tx5.GetHash(), 0);
CMutableTransaction tx6 = BuildTransaction(tx5.GetHash());
COutPoint tx6OutPoint(tx6.GetHash(), 0);
uint256 hash1;
hash1.SetHex("4bbf61ec5669c721bf007c71c59f85e6658f1de7b4562078e22f69f8f7ebcafd");
@ -173,19 +179,19 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
BOOST_CHECK(pclaimTrie->empty());
CClaimTrieCache ntState(pclaimTrie, false);
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1.GetHash(), 0, hash160, 50, 100, 200));
ntState.insertClaimIntoTrie(std::string("test2"), CClaimValue(tx2.GetHash(), 0, hash160, 50, 100, 200));
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, hash160, 50, 100, 200));
ntState.insertClaimIntoTrie(std::string("test2"), CClaimValue(tx2OutPoint, hash160, 50, 100, 200));
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!ntState.empty());
BOOST_CHECK(ntState.getMerkleHash() == hash1);
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3.GetHash(), 0, hash160, 50, 101, 201));
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, hash160, 50, 101, 201));
BOOST_CHECK(ntState.getMerkleHash() == hash1);
ntState.insertClaimIntoTrie(std::string("tes"), CClaimValue(tx4.GetHash(), 0, hash160, 50, 100, 200));
ntState.insertClaimIntoTrie(std::string("tes"), CClaimValue(tx4OutPoint, hash160, 50, 100, 200));
BOOST_CHECK(ntState.getMerkleHash() == hash2);
ntState.insertClaimIntoTrie(std::string("testtesttesttest"), CClaimValue(tx5.GetHash(), 0, hash160, 50, 100, 200));
ntState.removeClaimFromTrie(std::string("testtesttesttest"), tx5.GetHash(), 0, unused);
ntState.insertClaimIntoTrie(std::string("testtesttesttest"), CClaimValue(tx5OutPoint, hash160, 50, 100, 200));
ntState.removeClaimFromTrie(std::string("testtesttesttest"), tx5OutPoint, unused);
BOOST_CHECK(ntState.getMerkleHash() == hash2);
ntState.flush();
@ -194,16 +200,16 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState1(pclaimTrie, false);
ntState1.removeClaimFromTrie(std::string("test"), tx1.GetHash(), 0, unused);
ntState1.removeClaimFromTrie(std::string("test2"), tx2.GetHash(), 0, unused);
ntState1.removeClaimFromTrie(std::string("test"), tx3.GetHash(), 0, unused);
ntState1.removeClaimFromTrie(std::string("tes"), tx4.GetHash(), 0, unused);
ntState1.removeClaimFromTrie(std::string("test"), tx1OutPoint, unused);
ntState1.removeClaimFromTrie(std::string("test2"), tx2OutPoint, unused);
ntState1.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused);
ntState1.removeClaimFromTrie(std::string("tes"), tx4OutPoint, unused);
BOOST_CHECK(ntState1.getMerkleHash() == hash0);
CClaimTrieCache ntState2(pclaimTrie, false);
ntState2.insertClaimIntoTrie(std::string("abab"), CClaimValue(tx6.GetHash(), 0, hash160, 50, 100, 200));
ntState2.removeClaimFromTrie(std::string("test"), tx1.GetHash(), 0, unused);
ntState2.insertClaimIntoTrie(std::string("abab"), CClaimValue(tx6OutPoint, hash160, 50, 100, 200));
ntState2.removeClaimFromTrie(std::string("test"), tx1OutPoint, unused);
BOOST_CHECK(ntState2.getMerkleHash() == hash3);
@ -214,7 +220,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState3(pclaimTrie, false);
ntState3.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1.GetHash(), 0, hash160, 50, 100, 200));
ntState3.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, hash160, 50, 100, 200));
BOOST_CHECK(ntState3.getMerkleHash() == hash4);
ntState3.flush();
BOOST_CHECK(!pclaimTrie->empty());
@ -222,7 +228,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState4(pclaimTrie, false);
ntState4.removeClaimFromTrie(std::string("abab"), tx6.GetHash(), 0, unused);
ntState4.removeClaimFromTrie(std::string("abab"), tx6OutPoint, unused);
BOOST_CHECK(ntState4.getMerkleHash() == hash2);
ntState4.flush();
BOOST_CHECK(!pclaimTrie->empty());
@ -230,7 +236,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState5(pclaimTrie, false);
ntState5.removeClaimFromTrie(std::string("test"), tx3.GetHash(), 0, unused);
ntState5.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused);
BOOST_CHECK(ntState5.getMerkleHash() == hash2);
ntState5.flush();
@ -239,7 +245,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState6(pclaimTrie, false);
ntState6.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3.GetHash(), 0, hash160, 50, 101, 201));
ntState6.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, hash160, 50, 101, 201));
BOOST_CHECK(ntState6.getMerkleHash() == hash2);
ntState6.flush();
@ -248,10 +254,10 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState7(pclaimTrie, false);
ntState7.removeClaimFromTrie(std::string("test"), tx3.GetHash(), 0, unused);
ntState7.removeClaimFromTrie(std::string("test"), tx1.GetHash(), 0, unused);
ntState7.removeClaimFromTrie(std::string("tes"), tx4.GetHash(), 0, unused);
ntState7.removeClaimFromTrie(std::string("test2"), tx2.GetHash(), 0, unused);
ntState7.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused);
ntState7.removeClaimFromTrie(std::string("test"), tx1OutPoint, unused);
ntState7.removeClaimFromTrie(std::string("tes"), tx4OutPoint, unused);
ntState7.removeClaimFromTrie(std::string("test2"), tx2OutPoint, unused);
BOOST_CHECK(ntState7.getMerkleHash() == hash0);
ntState7.flush();
@ -287,45 +293,58 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
tx1.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE;
uint160 tx1ClaimId = ClaimIdHash(tx1.GetHash(), 0);
std::vector<unsigned char> vchTx1ClaimId(tx1ClaimId.begin(), tx1ClaimId.end());
COutPoint tx1OutPoint(tx1.GetHash(), 0);
CMutableTransaction tx2 = BuildTransaction(coinbases[1]);
tx2.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName2 << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
tx2.vout[0].nValue = tx1.vout[0].nValue - 1;
COutPoint tx2OutPoint(tx2.GetHash(), 0);
CMutableTransaction tx3 = BuildTransaction(tx1);
tx3.vout[0].scriptPubKey = CScript() << OP_UPDATE_CLAIM << vchName1 << vchTx1ClaimId << vchValue1 << OP_2DROP << OP_2DROP << OP_TRUE;
COutPoint tx3OutPoint(tx3.GetHash(), 0);
CMutableTransaction tx4 = BuildTransaction(tx2);
tx4.vout[0].scriptPubKey = CScript() << OP_TRUE;
COutPoint tx4OutPoint(tx4.GetHash(), 0);
CMutableTransaction tx5 = BuildTransaction(coinbases[2]);
tx5.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName2 << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
COutPoint tx5OutPoint(tx5.GetHash(), 0);
CMutableTransaction tx6 = BuildTransaction(tx3);
tx6.vout[0].scriptPubKey = CScript() << OP_TRUE;
COutPoint tx6OutPoint(tx6.GetHash(), 0);
CMutableTransaction tx7 = BuildTransaction(coinbases[3]);
tx7.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
tx7.vout[0].nValue = tx1.vout[0].nValue - 1;
uint160 tx7ClaimId = ClaimIdHash(tx7.GetHash(), 0);
std::vector<unsigned char> vchTx7ClaimId(tx7ClaimId.begin(), tx7ClaimId.end());
COutPoint tx7OutPoint(tx7.GetHash(), 0);
CMutableTransaction tx8 = BuildTransaction(tx3, 0, 2);
tx8.vout[0].scriptPubKey = CScript() << OP_UPDATE_CLAIM << vchName1 << vchTx1ClaimId << vchValue1 << OP_2DROP << OP_2DROP << OP_TRUE;
tx8.vout[0].nValue = tx8.vout[0].nValue - 1;
tx8.vout[1].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
COutPoint tx8OutPoint0(tx8.GetHash(), 0);
COutPoint tx8OutPoint1(tx8.GetHash(), 1);
CMutableTransaction tx9 = BuildTransaction(tx7);
tx9.vout[0].scriptPubKey = CScript() << OP_UPDATE_CLAIM << vchName1 << vchTx7ClaimId << vchValue2 << OP_2DROP << OP_2DROP << OP_TRUE;
COutPoint tx9OutPoint(tx9.GetHash(), 0);
CMutableTransaction tx10 = BuildTransaction(coinbases[4]);
tx10.vout[0].scriptPubKey = CScript() << OP_UPDATE_CLAIM << vchName1 << vchTx1ClaimId << vchValue1 << OP_2DROP << OP_2DROP << OP_TRUE;
COutPoint tx10OutPoint(tx10.GetHash(), 0);
CMutableTransaction tx11 = BuildTransaction(tx10);
tx11.vout[0].scriptPubKey = CScript() << OP_UPDATE_CLAIM << vchName1 << vchTx1ClaimId << vchValue1 << OP_2DROP << OP_2DROP << OP_TRUE;
COutPoint tx11OutPoint(tx11.GetHash(), 0);
CMutableTransaction tx12 = BuildTransaction(tx10);
tx12.vout[0].scriptPubKey = CScript() << OP_TRUE;
COutPoint tx12OutPoint(tx12.GetHash(), 0);
CClaimValue val;
@ -341,7 +360,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx7.GetHash());
BOOST_CHECK(val.outPoint == tx7OutPoint);
// Verify claims for controlled names are delayed, and that the bigger claim wins when inserted
@ -361,7 +380,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// Verify updates to the best claim get inserted immediately, and others don't.
@ -372,19 +391,19 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx1.GetHash(), 0));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx7.GetHash(), 0));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx1OutPoint));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx7OutPoint));
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx3.GetHash());
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName1, tx9.GetHash(), 0, nThrowaway));
BOOST_CHECK(val.outPoint == tx3OutPoint);
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName1, tx9OutPoint, nThrowaway));
// Roll back the last block, make sure tx1 and tx7 are put back in the trie
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(pclaimTrie->haveClaim(sName1, tx7.GetHash(), 0));
BOOST_CHECK(val.outPoint == tx1OutPoint);
BOOST_CHECK(pclaimTrie->haveClaim(sName1, tx7OutPoint));
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->empty());
@ -477,7 +496,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(CreateBlocks(1, 2));
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName2, tx2.GetHash(), 0, nThrowaway));
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName2, tx2OutPoint, nThrowaway));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
@ -501,7 +520,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->haveClaim(sName2, tx2.GetHash(), 0));
BOOST_CHECK(!pclaimTrie->haveClaim(sName2, tx2OutPoint));
// Undo spending tx2 with tx4, and then advance and verify tx2 is inserted into the trie when it should be
@ -515,17 +534,17 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName2, tx2.GetHash(), 0, nThrowaway));
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName2, tx2OutPoint, nThrowaway));
BOOST_CHECK(CreateBlocks(2, 1));
BOOST_CHECK(pclaimTrie->haveClaim(sName2, tx2.GetHash(), 0));
BOOST_CHECK(pclaimTrie->haveClaim(sName2, tx2OutPoint));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName2, val));
BOOST_CHECK(val.txhash == tx5.GetHash());
BOOST_CHECK(pclaimTrie->haveClaim(sName2, tx2.GetHash(), 0));
BOOST_CHECK(val.outPoint == tx5OutPoint);
BOOST_CHECK(pclaimTrie->haveClaim(sName2, tx2OutPoint));
// Test undoing a spend which involves a claim in the trie
@ -538,7 +557,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->haveClaim(sName2, tx2.GetHash(), 0));
BOOST_CHECK(!pclaimTrie->haveClaim(sName2, tx2OutPoint));
// undo spending tx2 with tx4, and verify tx2 is back in the trie
@ -547,8 +566,8 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName2, val));
BOOST_CHECK(val.txhash == tx5.GetHash());
BOOST_CHECK(pclaimTrie->haveClaim(sName2, tx2.GetHash(), 0));
BOOST_CHECK(val.outPoint == tx5OutPoint);
BOOST_CHECK(pclaimTrie->haveClaim(sName2, tx2OutPoint));
mempool.clear();
// roll back to the beginning
@ -579,7 +598,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName1, tx1.GetHash(), 0, nThrowaway));
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName1, tx1OutPoint, nThrowaway));
// move forward some, but not far enough for the claim to get into the trie
@ -594,9 +613,9 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx1.GetHash(), 0, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx1.GetHash(), 0));
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName1, tx3.GetHash(), 0, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx1OutPoint, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx1OutPoint));
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName1, tx3OutPoint, nThrowaway));
// spend the update (tx6 spends tx3)
@ -607,7 +626,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx3.GetHash(), 0));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx3OutPoint));
// undo spending the update (undo tx6 spending tx3)
@ -625,13 +644,13 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx3.GetHash());
BOOST_CHECK(val.outPoint == tx3OutPoint);
BOOST_CHECK(CreateBlocks(1, 1));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->haveClaim(sName1, tx3.GetHash(), 0));
BOOST_CHECK(pclaimTrie->haveClaim(sName1, tx3OutPoint));
// roll all the way back
@ -658,7 +677,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// update the original claim (tx3 spends tx1)
@ -669,7 +688,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx3.GetHash());
BOOST_CHECK(val.outPoint == tx3OutPoint);
// spend the update (tx6 spends tx3)
@ -688,7 +707,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx3.GetHash());
BOOST_CHECK(val.outPoint == tx3OutPoint);
// Test having two updates to a claim in the same transaction
@ -705,7 +724,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx8.GetHash() && val.nOut == 0);
BOOST_CHECK(val.outPoint == tx8OutPoint0);
// roll forward until tx8 output 1 gets into the trie
@ -722,7 +741,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx8.GetHash() && val.nOut == 1);
BOOST_CHECK(val.outPoint == tx8OutPoint1);
// roll back to before tx8
@ -746,7 +765,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
BOOST_CHECK(pclaimTrie->queueEmpty());
// advance a few blocks
@ -761,7 +780,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx10.GetHash(), 0, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx10OutPoint, nThrowaway));
BOOST_CHECK(pclaimTrie->queueEmpty());
// roll back, make sure nothing bad happens
@ -777,7 +796,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(CreateBlocks(1, 2));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx10.GetHash(), 0, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx10OutPoint, nThrowaway));
BOOST_CHECK(pclaimTrie->queueEmpty());
// update it
@ -788,13 +807,13 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx11.GetHash(), 0, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx11OutPoint, nThrowaway));
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(CreateBlocks(10, 1));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx11.GetHash(), 0, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx11.GetHash(), 0));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx11OutPoint, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx11OutPoint));
BOOST_CHECK(pclaimTrie->queueEmpty());
// roll back to before the update
@ -802,18 +821,18 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx11.GetHash(), 0));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx11.GetHash(), 0, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx10.GetHash(), 0));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx10.GetHash(), 0, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx11OutPoint));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx11OutPoint, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx10OutPoint));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx10OutPoint, nThrowaway));
BOOST_CHECK(pclaimTrie->queueEmpty());
// make sure tx10 would have gotten into the trie, then run tests again
BOOST_CHECK(CreateBlocks(10, 1));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx10.GetHash(), 0));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx10.GetHash(), 0, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx10OutPoint));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx10OutPoint, nThrowaway));
BOOST_CHECK(pclaimTrie->queueEmpty());
// update it
@ -822,18 +841,18 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(CreateBlocks(1, 2));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx11.GetHash(), 0, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx11.GetHash(), 0));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx11OutPoint, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx11OutPoint));
BOOST_CHECK(pclaimTrie->queueEmpty());
// make sure tx11 would have gotten into the trie
BOOST_CHECK(CreateBlocks(20, 1));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx11.GetHash(), 0, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx11.GetHash(), 0));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx10.GetHash(), 0, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx10.GetHash(), 0));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx11OutPoint, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx11OutPoint));
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx10OutPoint, nThrowaway));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx10OutPoint));
BOOST_CHECK(pclaimTrie->queueEmpty());
// roll all the way back
@ -903,11 +922,16 @@ BOOST_AUTO_TEST_CASE(claimtrie_claim_expiration)
CMutableTransaction tx1 = BuildTransaction(coinbases[0]);
tx1.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP << OP_TRUE;
COutPoint tx1OutPoint(tx1.GetHash(), 0);
CMutableTransaction tx2 = BuildTransaction(tx1);
tx2.vout[0].scriptPubKey = CScript() << OP_TRUE;
COutPoint tx2OutPoint(tx2.GetHash(), 0);
CMutableTransaction tx3 = BuildTransaction(coinbases[1]);
tx3.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP << OP_TRUE;
tx3.vout[0].nValue = tx1.vout[0].nValue >> 1;
COutPoint tx3OutPoint(tx3.GetHash(), 0);
int nThrowaway;
@ -1107,15 +1131,32 @@ BOOST_AUTO_TEST_CASE(claimtrie_claim_expiration)
BOOST_CHECK(CreateBlocks(4, 1));
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName, tx3.GetHash(), 0, nThrowaway));
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName, tx3OutPoint, nThrowaway));
BOOST_CHECK(CreateBlocks(1, 1));
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// roll back to before tx3 is valid
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
// advance again until tx3 is valid
BOOST_CHECK(CreateBlocks(1, 1));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.outPoint == tx1OutPoint);
// advance until the expiration event occurs. verify the expiration event occurs on time.
@ -1133,7 +1174,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_claim_expiration)
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx3.GetHash());
BOOST_CHECK(val.outPoint == tx3OutPoint);
// spend tx1
@ -1149,7 +1190,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_claim_expiration)
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// roll all the way back
@ -1182,16 +1223,19 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
CMutableTransaction tx1 = BuildTransaction(coinbases[0]);
tx1.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE;
tx1.vout[0].nValue = 100000000;
COutPoint tx1OutPoint(tx1.GetHash(), 0);
CMutableTransaction tx2 = BuildTransaction(coinbases[1]);
tx2.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
tx2.vout[0].nValue = 500000000;
COutPoint tx2OutPoint(tx2.GetHash(), 0);
CMutableTransaction tx3 = BuildTransaction(coinbases[2]);
uint160 tx1ClaimId = ClaimIdHash(tx1.GetHash(), 0);
std::vector<unsigned char> vchTx1ClaimId(tx1ClaimId.begin(), tx1ClaimId.end());
tx3.vout[0].scriptPubKey = CScript() << OP_SUPPORT_CLAIM << vchName << vchTx1ClaimId << OP_2DROP << OP_DROP << OP_TRUE;
tx3.vout[0].nValue = 500000000;
COutPoint tx3OutPoint(tx3.GetHash(), 0);
CMutableTransaction tx4 = BuildTransaction(tx1);
tx4.vout[0].scriptPubKey = CScript() << OP_TRUE;
@ -1204,6 +1248,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
CMutableTransaction tx7 = BuildTransaction(tx1);
tx7.vout[0].scriptPubKey = CScript() << OP_UPDATE_CLAIM << vchName << vchTx1ClaimId << vchValue1 << OP_2DROP << OP_2DROP << OP_TRUE;
COutPoint tx7OutPoint(tx7.GetHash(), 0);
CClaimValue val;
std::vector<uint256> blocks_to_invalidate;
@ -1279,7 +1324,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// spend tx3
@ -1296,7 +1341,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
BOOST_CHECK(val.outPoint == tx2OutPoint);
// unspend tx3, verify tx1 regains control
@ -1308,7 +1353,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// update tx1 with tx7, verify tx7 has control
@ -1323,7 +1368,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx7.GetHash());
BOOST_CHECK(val.outPoint == tx7OutPoint);
// roll back to before tx7 is inserted, verify tx1 has control
@ -1331,7 +1376,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
blocks_to_invalidate.pop_back();
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// roll back to before tx2 is valid
@ -1351,7 +1396,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
BOOST_CHECK(val.outPoint == tx2OutPoint);
// roll back to before tx3 is inserted
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
@ -1383,7 +1428,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
BOOST_CHECK(val.outPoint == tx2OutPoint);
// roll all the way back
@ -1407,7 +1452,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
BOOST_CHECK(val.outPoint == tx2OutPoint);
// advance a few blocks
@ -1455,7 +1500,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// spend tx3 again, then undo the spend and roll back until it's back in the queue
@ -1468,7 +1513,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
BOOST_CHECK(val.outPoint == tx2OutPoint);
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
@ -1478,7 +1523,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
@ -1486,7 +1531,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(!pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
BOOST_CHECK(val.outPoint == tx2OutPoint);
// advance until tx3 is valid again
@ -1495,7 +1540,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// roll all the way back
@ -1529,16 +1574,19 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
CMutableTransaction tx1 = BuildTransaction(coinbases[0]);
tx1.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE;
tx1.vout[0].nValue = 100000000;
COutPoint tx1OutPoint(tx1.GetHash(), 0);
CMutableTransaction tx2 = BuildTransaction(coinbases[1]);
tx2.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
tx2.vout[0].nValue = 500000000;
COutPoint tx2OutPoint(tx2.GetHash(), 0);
CMutableTransaction tx3 = BuildTransaction(coinbases[2]);
uint160 tx1ClaimId = ClaimIdHash(tx1.GetHash(), 0);
std::vector<unsigned char> vchTx1ClaimId(tx1ClaimId.begin(), tx1ClaimId.end());
tx3.vout[0].scriptPubKey = CScript() << OP_SUPPORT_CLAIM << vchName << vchTx1ClaimId << OP_2DROP << OP_DROP << OP_TRUE;
tx3.vout[0].nValue = 500000000;
COutPoint tx3OutPoint(tx3.GetHash(), 0);
CMutableTransaction tx4 = BuildTransaction(tx1);
tx4.vout[0].scriptPubKey = CScript() << OP_TRUE;
@ -1589,12 +1637,12 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(CreateBlocks(4, 1));
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName, tx2.GetHash(), 0, nThrowaway));
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName, tx2OutPoint, nThrowaway));
BOOST_CHECK(CreateBlocks(1, 1));
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
BOOST_CHECK(val.outPoint == tx2OutPoint);
// advance a few blocks
@ -1627,7 +1675,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// spend tx3
@ -1641,7 +1689,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
BOOST_CHECK(val.outPoint == tx2OutPoint);
// undo spend
@ -1653,7 +1701,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// roll back to before tx3 is valid
@ -1665,7 +1713,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(!pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
BOOST_CHECK(val.outPoint == tx2OutPoint);
// roll all the way back
@ -1693,7 +1741,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// advance a few blocks
@ -1710,7 +1758,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// advance some, insert tx3, should be immediately valid
@ -1725,7 +1773,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// advance until tx2 is valid, verify tx1 retains control
@ -1738,8 +1786,8 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(pclaimTrie->haveClaim(sName, tx2.GetHash(), 0));
BOOST_CHECK(val.outPoint == tx1OutPoint);
BOOST_CHECK(pclaimTrie->haveClaim(sName, tx2OutPoint));
// roll all the way back
@ -1766,7 +1814,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
BOOST_CHECK(val.outPoint == tx2OutPoint);
// advance a few blocks
@ -1783,7 +1831,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
BOOST_CHECK(val.outPoint == tx2OutPoint);
// advance some
@ -1800,7 +1848,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(!pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
BOOST_CHECK(val.outPoint == tx2OutPoint);
// advance until tx1 is valid
@ -1812,8 +1860,8 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(!pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
BOOST_CHECK(pclaimTrie->haveClaim(sName, tx1.GetHash(), 0));
BOOST_CHECK(val.outPoint == tx2OutPoint);
BOOST_CHECK(pclaimTrie->haveClaim(sName, tx1OutPoint));
// advance until tx3 is valid
@ -1825,7 +1873,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// roll all the way back
@ -1851,7 +1899,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// advance a few blocks
@ -1868,7 +1916,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// advance some, insert tx3
@ -1883,7 +1931,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// advance until tx2 is valid
@ -1896,7 +1944,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// spend tx1
@ -1910,7 +1958,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
BOOST_CHECK(val.outPoint == tx2OutPoint);
// undo spend of tx1
@ -1922,7 +1970,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(val.outPoint == tx1OutPoint);
// roll all the way back
@ -2007,8 +2055,8 @@ BOOST_AUTO_TEST_CASE(claimtrienode_serialize_unserialize)
ss >> n2;
BOOST_CHECK(n1 == n2);
CClaimValue v1(uint256S("0000000000000000000000000000000000000000000000000000000000000001"), 0, hash160, 50, 0, 100);
CClaimValue v2(uint256S("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), 1, hash160, 100, 1, 101);
CClaimValue v1(COutPoint(uint256S("0000000000000000000000000000000000000000000000000000000000000001"), 0), hash160, 50, 0, 100);
CClaimValue v2(COutPoint(uint256S("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), 1), hash160, 100, 1, 101);
n1.insertClaim(v1);
BOOST_CHECK(n1 != n2);
@ -2022,13 +2070,13 @@ BOOST_AUTO_TEST_CASE(claimtrienode_serialize_unserialize)
ss >> n2;
BOOST_CHECK(n1 == n2);
n1.removeClaim(v1.txhash, v1.nOut, throwaway);
n1.removeClaim(v1.outPoint, throwaway);
BOOST_CHECK(n1 != n2);
ss << n1;
ss >> n2;
BOOST_CHECK(n1 == n2);
n1.removeClaim(v2.txhash, v2.nOut, throwaway);
n1.removeClaim(v2.outPoint, throwaway);
BOOST_CHECK(n1 != n2);
ss << n1;
ss >> n2;

View file

@ -701,11 +701,11 @@ void ListNameClaims(const CWalletTx& wtx, const string& strAccount, int nMinDept
entry.push_back(Pair("is spent", pwalletMain->IsSpent(wtx.GetHash(), s.vout)));
if (op == OP_CLAIM_NAME)
{
entry.push_back(Pair("is in name trie", pclaimTrie->haveClaim(sName, wtx.GetHash(), s.vout)));
entry.push_back(Pair("is in name trie", pclaimTrie->haveClaim(sName, COutPoint(wtx.GetHash(), s.vout))));
}
else if (op == OP_SUPPORT_CLAIM)
{
entry.push_back(Pair("is in support map", pclaimTrie->haveSupport(sName, wtx.GetHash(), s.vout)));
entry.push_back(Pair("is in support map", pclaimTrie->haveSupport(sName, COutPoint(wtx.GetHash(), s.vout))));
}
ret.push_back(entry);
}