mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-08-31 00:41:58 +00:00
Fixed disassociation.
This commit is contained in:
parent
76c50bc850
commit
64a6a1701e
@ -219,7 +219,7 @@ void CCoinsViewCache::SetName(const valtype &nameSpace, const valtype &key, cons
|
|||||||
|
|
||||||
// Handle namespace association.
|
// Handle namespace association.
|
||||||
valtype associdateNamespace;
|
valtype associdateNamespace;
|
||||||
if (!cacheNames.getAssociateNamespaces(data.getValue(), associdateNamespace)) {
|
if (!cacheNames.getAssociateNamespaces(key, associdateNamespace)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +227,7 @@ void CCoinsViewCache::SetName(const valtype &nameSpace, const valtype &key, cons
|
|||||||
if (!GetNamespace(associdateNamespace, dummyData)) {
|
if (!GetNamespace(associdateNamespace, dummyData)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cacheNames.associateNamespaces(nameSpace, associdateNamespace);
|
cacheNames.associateNamespaces(nameSpace, associdateNamespace, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCoinsViewCache::DeleteName(const valtype &nameSpace, const valtype &key) {
|
void CCoinsViewCache::DeleteName(const valtype &nameSpace, const valtype &key) {
|
||||||
@ -239,7 +239,7 @@ void CCoinsViewCache::DeleteName(const valtype &nameSpace, const valtype &key) {
|
|||||||
|
|
||||||
// Handle namespace association.
|
// Handle namespace association.
|
||||||
valtype associdateNamespace;
|
valtype associdateNamespace;
|
||||||
if (!cacheNames.getAssociateNamespaces(oldData.getValue(), associdateNamespace)) {
|
if (!cacheNames.getAssociateNamespaces(key, associdateNamespace)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ bool CCacheKeyIterator::next(valtype& key, CKevaData& data)
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* CKevaCache. */
|
/* CKevaCache. */
|
||||||
|
|
||||||
const std::string CKevaCache::associatePrefix = "_A_";
|
const std::string CKevaCache::associatePrefix = "_f:";
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CKevaCache::get(const valtype& nameSpace, const valtype& key, CKevaData& data) const
|
CKevaCache::get(const valtype& nameSpace, const valtype& key, CKevaData& data) const
|
||||||
@ -215,6 +215,8 @@ void
|
|||||||
CKevaCache::set(const valtype& nameSpace, const valtype& key, const CKevaData& data)
|
CKevaCache::set(const valtype& nameSpace, const valtype& key, const CKevaData& data)
|
||||||
{
|
{
|
||||||
auto name = std::make_tuple(nameSpace, key);
|
auto name = std::make_tuple(nameSpace, key);
|
||||||
|
printf("set name is: %s\n", (EncodeBase58Check(nameSpace) + ValtypeToString(key)).c_str());
|
||||||
|
printf("set, this is: %p, data value is: %s\n", this, ValtypeToString(data.getValue()).c_str());
|
||||||
const std::set<NamespaceKeyType>::iterator di = deleted.find(name);
|
const std::set<NamespaceKeyType>::iterator di = deleted.find(name);
|
||||||
if (di != deleted.end()) {
|
if (di != deleted.end()) {
|
||||||
deleted.erase(di);
|
deleted.erase(di);
|
||||||
@ -255,25 +257,39 @@ CKevaCache::getAssociateNamespaces(const valtype& value, valtype& nameSpace)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CKevaCache::associateNamespaces(const valtype& nameSpace, const valtype& nameSpaceOther)
|
CKevaCache::associateNamespaces(const valtype& nameSpace, const valtype& nameSpaceOther, const CKevaData& data)
|
||||||
{
|
{
|
||||||
auto name = std::make_tuple(nameSpaceOther, nameSpace);
|
auto name = std::make_tuple(nameSpaceOther, nameSpace);
|
||||||
|
printf("associateNamespaces, name is: %s\n", (EncodeBase58Check(nameSpaceOther) + EncodeBase58Check(nameSpace)).c_str());
|
||||||
|
printf("associateNamespaces, this is: %p, data value is: %s\n", this, ValtypeToString(data.getValue()).c_str());
|
||||||
|
|
||||||
|
const std::set<NamespaceKeyType>::iterator di = disassociations.find(name);
|
||||||
|
if (di != disassociations.end()) {
|
||||||
|
disassociations.erase(di);
|
||||||
|
}
|
||||||
|
|
||||||
const NamespaceMap::iterator ei = associations.find(name);
|
const NamespaceMap::iterator ei = associations.find(name);
|
||||||
CKevaData data;
|
if (ei != associations.end()) {
|
||||||
if (ei != entries.end())
|
printf("CKevaCache::associateNamespaces, REPLACE !!!\n");
|
||||||
ei->second = data;
|
ei->second = data;
|
||||||
else
|
} else {
|
||||||
|
printf("CKevaCache::associateNamespaces, INSERT !!!\n");
|
||||||
associations.insert(std::make_pair(name, data));
|
associations.insert(std::make_pair(name, data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CKevaCache::disassociateNamespaces(const valtype& nameSpace, const valtype& nameSpaceOther)
|
CKevaCache::disassociateNamespaces(const valtype& nameSpace, const valtype& nameSpaceOther)
|
||||||
{
|
{
|
||||||
auto name = std::make_tuple(nameSpaceOther, nameSpace);
|
auto name = std::make_tuple(nameSpaceOther, nameSpace);
|
||||||
const NamespaceMap::iterator ei = entries.find(name);
|
const NamespaceMap::iterator ei = associations.find(name);
|
||||||
if (ei != entries.end()) {
|
printf("CKevaCache::disassociateNamespaces, name is: %s\n", (EncodeBase58Check(nameSpaceOther) + EncodeBase58Check(nameSpace)).c_str());
|
||||||
|
if (ei != associations.end()) {
|
||||||
|
printf("CKevaCache::disassociateNamespaces, erase!!!\n");
|
||||||
associations.erase(ei);
|
associations.erase(ei);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
disassociations.insert(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
CKevaIterator*
|
CKevaIterator*
|
||||||
@ -298,15 +314,20 @@ CKevaCache::updateNamesForHeight (unsigned nHeight,
|
|||||||
|
|
||||||
void CKevaCache::apply(const CKevaCache& cache)
|
void CKevaCache::apply(const CKevaCache& cache)
|
||||||
{
|
{
|
||||||
|
printf("CKevaCache::apply!!!!\n");
|
||||||
for (EntryMap::const_iterator i = cache.entries.begin(); i != cache.entries.end(); ++i) {
|
for (EntryMap::const_iterator i = cache.entries.begin(); i != cache.entries.end(); ++i) {
|
||||||
set(std::get<0>(i->first), std::get<1>(i->first), i->second);
|
set(std::get<0>(i->first), std::get<1>(i->first), i->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (NamespaceMap::const_iterator i = associations.begin(); i != associations.end(); ++i) {
|
for (NamespaceMap::const_iterator i = associations.begin(); i != associations.end(); ++i) {
|
||||||
set(std::get<0>(i->first), std::get<1>(i->first), i->second);
|
associateNamespaces(std::get<0>(i->first), std::get<1>(i->first), i->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::set<NamespaceKeyType>::const_iterator i = cache.deleted.begin(); i != cache.deleted.end(); ++i) {
|
for (std::set<NamespaceKeyType>::const_iterator i = cache.deleted.begin(); i != cache.deleted.end(); ++i) {
|
||||||
remove(std::get<0>(*i), std::get<1>(*i));
|
remove(std::get<0>(*i), std::get<1>(*i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (std::set<NamespaceKeyType>::const_iterator i = cache.disassociations.begin(); i != cache.disassociations.end(); ++i) {
|
||||||
|
disassociateNamespaces(std::get<0>(*i), std::get<1>(*i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -351,6 +351,9 @@ private:
|
|||||||
/** Namespace association. */
|
/** Namespace association. */
|
||||||
NamespaceMap associations;
|
NamespaceMap associations;
|
||||||
|
|
||||||
|
/** Namespace disassociations. */
|
||||||
|
std::set<NamespaceKeyType> disassociations;
|
||||||
|
|
||||||
friend class CCacheKeyIterator;
|
friend class CCacheKeyIterator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -361,6 +364,7 @@ public:
|
|||||||
entries.clear();
|
entries.clear();
|
||||||
deleted.clear();
|
deleted.clear();
|
||||||
associations.clear();
|
associations.clear();
|
||||||
|
disassociations.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -406,7 +410,7 @@ public:
|
|||||||
bool getAssociateNamespaces(const valtype& value, valtype& nameSpace);
|
bool getAssociateNamespaces(const valtype& value, valtype& nameSpace);
|
||||||
|
|
||||||
/* Associate nameSpace with nameSpaceOther */
|
/* Associate nameSpace with nameSpaceOther */
|
||||||
void associateNamespaces(const valtype& nameSpace, const valtype& nameSpaceOther);
|
void associateNamespaces(const valtype& nameSpace, const valtype& nameSpaceOther, const CKevaData& data);
|
||||||
|
|
||||||
/* Disassociate nameSpace with nameSpaceOther */
|
/* Disassociate nameSpace with nameSpaceOther */
|
||||||
void disassociateNamespaces(const valtype& nameSpace, const valtype& nameSpaceOther);
|
void disassociateNamespaces(const valtype& nameSpace, const valtype& nameSpaceOther);
|
||||||
|
@ -343,6 +343,11 @@ void CKevaCache::writeBatch (CDBBatch& batch) const
|
|||||||
std::pair<valtype, valtype> name = std::make_pair(std::get<0>(*i), std::get<1>(*i));
|
std::pair<valtype, valtype> name = std::make_pair(std::get<0>(*i), std::get<1>(*i));
|
||||||
batch.Erase(std::make_pair(DB_NAME, name));
|
batch.Erase(std::make_pair(DB_NAME, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (std::set<NamespaceKeyType>::const_iterator i = disassociations.begin(); i != disassociations.end(); ++i) {
|
||||||
|
std::pair<valtype, valtype> name = std::make_pair(std::get<0>(*i), std::get<1>(*i));
|
||||||
|
batch.Erase(std::make_pair(DB_NS_ASSOC, name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBlockTreeDB::ReadTxIndex(const uint256 &txid, CDiskTxPos &pos) {
|
bool CBlockTreeDB::ReadTxIndex(const uint256 &txid, CDiskTxPos &pos) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user