Unify claimtrie tests, add some additional root hash checks #181

Closed
BrannonKing wants to merge 291 commits from unify_claimtrie_tests into master
33 changed files with 530 additions and 531 deletions
Showing only changes of commit eb25177f5e - Show all commits

View file

@ -107,8 +107,8 @@ BITCOIN_CORE_H = \
merkleblock.h \
miner.h \
mruset.h \
ncc.h \
ncctrie.h \
nameclaim.h \
claimtrie.h \
net.h \
netbase.h \
noui.h \
@ -175,7 +175,7 @@ libbitcoin_server_a_SOURCES = \
main.cpp \
merkleblock.cpp \
miner.cpp \
ncctrie.cpp \
claimtrie.cpp \
net.cpp \
noui.cpp \
policy/fees.cpp \
@ -184,7 +184,7 @@ libbitcoin_server_a_SOURCES = \
rpcblockchain.cpp \
rpcmining.cpp \
rpcmisc.cpp \
rpcncctrie.cpp \
rpcclaimtrie.cpp \
rpcnet.cpp \
rpcrawtransaction.cpp \
rpcserver.cpp \
@ -249,7 +249,7 @@ libbitcoin_common_a_SOURCES = \
hash.cpp \
key.cpp \
keystore.cpp \
ncc.cpp \
nameclaim.cpp \
netbase.cpp \
primitives/block.cpp \
primitives/transaction.cpp \

View file

@ -55,7 +55,7 @@ BITCOIN_TESTS =\
test/miner_tests.cpp \
test/mruset_tests.cpp \
test/multisig_tests.cpp \
test/ncctrie_tests.cpp \
test/claimtrie_tests.cpp \
test/netbase_tests.cpp \
test/pmt_tests.cpp \
test/policyestimator_tests.cpp \

View file

@ -27,7 +27,7 @@ std::string HelpMessageCli()
strUsage += HelpMessageOpt("-regtest", _("Enter regression test mode, which uses a special chain in which blocks can be "
"solved instantly. This is intended for regression testing tools and app development."));
strUsage += HelpMessageOpt("-rpcconnect=<ip>", strprintf(_("Send commands to node running on <ip> (default: %s)"), "127.0.0.1"));
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), 8332, 18332));
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), 9245, 19245));
strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start"));
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));

View file

@ -141,7 +141,7 @@ public:
//! block header
int nVersion;
uint256 hashMerkleRoot;
uint256 hashNCCTrie;
uint256 hashClaimTrie;
unsigned int nTime;
unsigned int nBits;
unsigned int nNonce;
@ -166,7 +166,7 @@ public:
nVersion = 0;
hashMerkleRoot = uint256();
hashNCCTrie = uint256();
hashClaimTrie = uint256();
nTime = 0;
nBits = 0;
nNonce = 0;
@ -183,7 +183,7 @@ public:
nVersion = block.nVersion;
hashMerkleRoot = block.hashMerkleRoot;
hashNCCTrie = block.hashNCCTrie;
hashClaimTrie = block.hashClaimTrie;
nTime = block.nTime;
nBits = block.nBits;
nNonce = block.nNonce;
@ -214,7 +214,7 @@ public:
if (pprev)
block.hashPrevBlock = pprev->GetBlockHash();
block.hashMerkleRoot = hashMerkleRoot;
block.hashNCCTrie = hashNCCTrie;
block.hashClaimTrie = hashClaimTrie;
block.nTime = nTime;
block.nBits = nBits;
block.nNonce = nNonce;
@ -249,10 +249,10 @@ public:
std::string ToString() const
{
return strprintf("CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, ncctrie=%s, hashBlock=%s)",
return strprintf("CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, claimtrie=%s, hashBlock=%s)",
pprev, nHeight,
hashMerkleRoot.ToString(),
hashNCCTrie.ToString(),
hashClaimTrie.ToString(),
GetBlockHash().ToString());
}
@ -322,7 +322,7 @@ public:
READWRITE(this->nVersion);
READWRITE(hashPrev);
READWRITE(hashMerkleRoot);
READWRITE(hashNCCTrie);
READWRITE(hashClaimTrie);
READWRITE(nTime);
READWRITE(nBits);
READWRITE(nNonce);
@ -334,7 +334,7 @@ public:
block.nVersion = nVersion;
block.hashPrevBlock = hashPrev;
block.hashMerkleRoot = hashMerkleRoot;
block.hashNCCTrie = hashNCCTrie;
block.hashClaimTrie = hashClaimTrie;
block.nTime = nTime;
block.nBits = nBits;
block.nNonce = nNonce;

View file

@ -50,7 +50,7 @@ public:
pchMessageStart[2] = 0xaa;
pchMessageStart[3] = 0xf1;
vAlertPubKey = ParseHex("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284");
nDefaultPort = 8333;
nDefaultPort = 9246;
nMinerThreads = 2;
nPruneAfterHeight = 100000;
@ -79,7 +79,7 @@ public:
genesis.vtx.push_back(txNew);
genesis.hashPrevBlock.SetNull();
genesis.hashMerkleRoot = genesis.BuildMerkleTree();
genesis.hashNCCTrie = uint256S("0x0000000000000000000000000000000000000000000000000000000000000001");
genesis.hashClaimTrie = uint256S("0x0000000000000000000000000000000000000000000000000000000000000001");
genesis.nVersion = 1;
genesis.nTime = 1417453734;
genesis.nBits = 0x1f00ffff;
@ -154,7 +154,7 @@ public:
pchMessageStart[2] = 0x09;
pchMessageStart[3] = 0x07;
vAlertPubKey = ParseHex("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a");
nDefaultPort = 18333;
nDefaultPort = 19246;
nMinerThreads = 0;
nPruneAfterHeight = 1000;

View file

@ -17,7 +17,7 @@ class CBaseMainParams : public CBaseChainParams
public:
CBaseMainParams()
{
nRPCPort = 8332;
nRPCPort = 9245;
}
};
static CBaseMainParams mainParams;
@ -30,7 +30,7 @@ class CBaseTestNetParams : public CBaseMainParams
public:
CBaseTestNetParams()
{
nRPCPort = 18332;
nRPCPort = 19245;
strDataDir = "testnet3";
}
};

View file

@ -1,4 +1,4 @@
#include "ncctrie.h"
#include "claimtrie.h"
#include "leveldbwrapper.h"
#include <boost/scoped_ptr.hpp>
@ -28,9 +28,9 @@ uint256 CNodeValue::GetHash() const
return valHash;
}
bool CNCCTrieNode::insertValue(CNodeValue val, bool * pfChanged)
bool CClaimTrieNode::insertValue(CNodeValue val, bool * pfChanged)
{
LogPrintf("%s: Inserting %s:%d (amount: %d) into the ncc trie\n", __func__, val.txhash.ToString(), val.nOut, val.nAmount);
LogPrintf("%s: Inserting %s:%d (amount: %d) into the claim trie\n", __func__, val.txhash.ToString(), val.nOut, val.nAmount);
bool fChanged = false;
if (values.empty())
@ -51,9 +51,9 @@ bool CNCCTrieNode::insertValue(CNodeValue val, bool * pfChanged)
return true;
}
bool CNCCTrieNode::removeValue(uint256& txhash, uint32_t nOut, CNodeValue& val, bool * pfChanged)
bool CClaimTrieNode::removeValue(uint256& txhash, uint32_t nOut, CNodeValue& val, bool * pfChanged)
{
LogPrintf("%s: Removing txid: %s, nOut: %d from the ncc trie\n", __func__, txhash.ToString(), nOut);
LogPrintf("%s: Removing txid: %s, nOut: %d from the claim trie\n", __func__, txhash.ToString(), nOut);
bool fChanged = false;
CNodeValue currentTop = values.front();
@ -71,8 +71,8 @@ bool CNCCTrieNode::removeValue(uint256& txhash, uint32_t nOut, CNodeValue& val,
values.erase(position);
else
{
LogPrintf("CNCCTrieNode::%s() : asked to remove a value that doesn't exist\n", __func__);
LogPrintf("CNCCTrieNode::%s() : values that do exist:\n", __func__);
LogPrintf("CClaimTrieNode::%s() : asked to remove a value that doesn't exist\n", __func__);
LogPrintf("CClaimTrieNode::%s() : values that do exist:\n", __func__);
for (unsigned int i = 0; i < values.size(); i++)
{
LogPrintf("\ttxid: %s, nOut: %d\n", values[i].txhash.ToString(), values[i].nOut);
@ -92,7 +92,7 @@ bool CNCCTrieNode::removeValue(uint256& txhash, uint32_t nOut, CNodeValue& val,
return true;
}
bool CNCCTrieNode::getBestValue(CNodeValue& value) const
bool CClaimTrieNode::getBestValue(CNodeValue& value) const
{
if (values.empty())
return false;
@ -103,7 +103,7 @@ bool CNCCTrieNode::getBestValue(CNodeValue& value) const
}
}
bool CNCCTrieNode::haveValue(const uint256& txhash, uint32_t nOut) const
bool CClaimTrieNode::haveValue(const uint256& txhash, uint32_t nOut) const
{
for (std::vector<CNodeValue>::const_iterator itval = values.begin(); itval != values.end(); ++itval)
if (itval->txhash == txhash && itval->nOut == nOut)
@ -111,17 +111,17 @@ bool CNCCTrieNode::haveValue(const uint256& txhash, uint32_t nOut) const
return false;
}
uint256 CNCCTrie::getMerkleHash()
uint256 CClaimTrie::getMerkleHash()
{
return root.hash;
}
bool CNCCTrie::empty() const
bool CClaimTrie::empty() const
{
return root.empty();
}
bool CNCCTrie::queueEmpty() const
bool CClaimTrie::queueEmpty() const
{
for (valueQueueType::const_iterator itRow = dirtyQueueRows.begin(); itRow != dirtyQueueRows.end(); ++itRow)
{
@ -153,7 +153,7 @@ bool CNCCTrie::queueEmpty() const
return true;
}
bool CNCCTrie::expirationQueueEmpty() const
bool CClaimTrie::expirationQueueEmpty() const
{
for (valueQueueType::const_iterator itRow = dirtyExpirationQueueRows.begin(); itRow != dirtyExpirationQueueRows.end(); ++itRow)
{
@ -185,17 +185,17 @@ bool CNCCTrie::expirationQueueEmpty() const
return true;
}
void CNCCTrie::setExpirationTime(int t)
void CClaimTrie::setExpirationTime(int t)
{
nExpirationTime = t;
}
void CNCCTrie::clear()
void CClaimTrie::clear()
{
clear(&root);
}
void CNCCTrie::clear(CNCCTrieNode* current)
void CClaimTrie::clear(CClaimTrieNode* current)
{
for (nodeMapType::const_iterator itchildren = current->children.begin(); itchildren != current->children.end(); ++itchildren)
{
@ -204,9 +204,9 @@ void CNCCTrie::clear(CNCCTrieNode* current)
}
}
bool CNCCTrie::haveClaim(const std::string& name, const uint256& txhash, uint32_t nOut) const
bool CClaimTrie::haveClaim(const std::string& name, const uint256& txhash, uint32_t nOut) const
{
const CNCCTrieNode* current = &root;
const CClaimTrieNode* current = &root;
for (std::string::const_iterator itname = name.begin(); itname != name.end(); ++itname)
{
nodeMapType::const_iterator itchildren = current->children.find(*itname);
@ -217,15 +217,15 @@ bool CNCCTrie::haveClaim(const std::string& name, const uint256& txhash, uint32_
return current->haveValue(txhash, nOut);
}
unsigned int CNCCTrie::getTotalNamesInTrie() const
unsigned int CClaimTrie::getTotalNamesInTrie() const
{
if (empty())
return 0;
const CNCCTrieNode* current = &root;
const CClaimTrieNode* current = &root;
return getTotalNamesRecursive(current);
}
unsigned int CNCCTrie::getTotalNamesRecursive(const CNCCTrieNode* current) const
unsigned int CClaimTrie::getTotalNamesRecursive(const CClaimTrieNode* current) const
{
unsigned int names_in_subtrie = 0;
if (!(current->values.empty()))
@ -237,15 +237,15 @@ unsigned int CNCCTrie::getTotalNamesRecursive(const CNCCTrieNode* current) const
return names_in_subtrie;
}
unsigned int CNCCTrie::getTotalClaimsInTrie() const
unsigned int CClaimTrie::getTotalClaimsInTrie() const
{
if (empty())
return 0;
const CNCCTrieNode* current = &root;
const CClaimTrieNode* current = &root;
return getTotalClaimsRecursive(current);
}
unsigned int CNCCTrie::getTotalClaimsRecursive(const CNCCTrieNode* current) const
unsigned int CClaimTrie::getTotalClaimsRecursive(const CClaimTrieNode* current) const
{
unsigned int claims_in_subtrie = current->values.size();
for (nodeMapType::const_iterator it = current->children.begin(); it != current->children.end(); ++it)
@ -255,15 +255,15 @@ unsigned int CNCCTrie::getTotalClaimsRecursive(const CNCCTrieNode* current) cons
return claims_in_subtrie;
}
CAmount CNCCTrie::getTotalValueOfClaimsInTrie(bool fControllingOnly) const
CAmount CClaimTrie::getTotalValueOfClaimsInTrie(bool fControllingOnly) const
{
if (empty())
return 0;
const CNCCTrieNode* current = &root;
const CClaimTrieNode* current = &root;
return getTotalValueOfClaimsRecursive(current, fControllingOnly);
}
CAmount CNCCTrie::getTotalValueOfClaimsRecursive(const CNCCTrieNode* current, bool fControllingOnly) const
CAmount CClaimTrie::getTotalValueOfClaimsRecursive(const CClaimTrieNode* current, bool fControllingOnly) const
{
CAmount value_in_subtrie = 0;
for (std::vector<CNodeValue>::const_iterator itval = current->values.begin(); itval != current->values.end(); ++itval)
@ -279,7 +279,7 @@ CAmount CNCCTrie::getTotalValueOfClaimsRecursive(const CNCCTrieNode* current, bo
return value_in_subtrie;
}
bool CNCCTrie::recursiveFlattenTrie(const std::string& name, const CNCCTrieNode* current, std::vector<namedNodeType>& nodes) const
bool CClaimTrie::recursiveFlattenTrie(const std::string& name, const CClaimTrieNode* current, std::vector<namedNodeType>& nodes) const
{
namedNodeType node(name, *current);
nodes.push_back(node);
@ -293,7 +293,7 @@ bool CNCCTrie::recursiveFlattenTrie(const std::string& name, const CNCCTrieNode*
return true;
}
std::vector<namedNodeType> CNCCTrie::flattenTrie() const
std::vector<namedNodeType> CClaimTrie::flattenTrie() const
{
std::vector<namedNodeType> nodes;
if (!recursiveFlattenTrie("", &root, nodes))
@ -301,9 +301,9 @@ std::vector<namedNodeType> CNCCTrie::flattenTrie() const
return nodes;
}
bool CNCCTrie::getInfoForName(const std::string& name, CNodeValue& val) const
bool CClaimTrie::getInfoForName(const std::string& name, CNodeValue& val) const
{
const CNCCTrieNode* current = &root;
const CClaimTrieNode* current = &root;
for (std::string::const_iterator itname = name.begin(); itname != name.end(); ++itname)
{
nodeMapType::const_iterator itchildren = current->children.find(*itname);
@ -314,14 +314,14 @@ bool CNCCTrie::getInfoForName(const std::string& name, CNodeValue& val) const
return current->getBestValue(val);
}
bool CNCCTrie::checkConsistency()
bool CClaimTrie::checkConsistency()
{
if (empty())
return true;
return recursiveCheckConsistency(&root);
}
bool CNCCTrie::recursiveCheckConsistency(CNCCTrieNode* node)
bool CClaimTrie::recursiveCheckConsistency(CClaimTrieNode* node)
{
std::vector<unsigned char> vchToHash;
@ -353,7 +353,7 @@ bool CNCCTrie::recursiveCheckConsistency(CNCCTrieNode* node)
return calculatedHash == node->hash;
}
bool CNCCTrie::getQueueRow(int nHeight, std::vector<CValueQueueEntry>& row)
bool CClaimTrie::getQueueRow(int nHeight, std::vector<CValueQueueEntry>& row)
{
valueQueueType::iterator itQueueRow = dirtyQueueRows.find(nHeight);
if (itQueueRow != dirtyQueueRows.end())
@ -364,7 +364,7 @@ bool CNCCTrie::getQueueRow(int nHeight, std::vector<CValueQueueEntry>& row)
return db.Read(std::make_pair('r', nHeight), row);
}
bool CNCCTrie::getExpirationQueueRow(int nHeight, std::vector<CValueQueueEntry>& row)
bool CClaimTrie::getExpirationQueueRow(int nHeight, std::vector<CValueQueueEntry>& row)
{
valueQueueType::iterator itQueueRow = dirtyExpirationQueueRows.find(nHeight);
if (itQueueRow != dirtyExpirationQueueRows.end())
@ -375,7 +375,7 @@ bool CNCCTrie::getExpirationQueueRow(int nHeight, std::vector<CValueQueueEntry>&
return db.Read(std::make_pair('e', nHeight), row);
}
void CNCCTrie::updateQueueRow(int nHeight, std::vector<CValueQueueEntry>& row)
void CClaimTrie::updateQueueRow(int nHeight, std::vector<CValueQueueEntry>& row)
{
valueQueueType::iterator itQueueRow = dirtyQueueRows.find(nHeight);
if (itQueueRow == dirtyQueueRows.end())
@ -389,7 +389,7 @@ void CNCCTrie::updateQueueRow(int nHeight, std::vector<CValueQueueEntry>& row)
itQueueRow->second.swap(row);
}
void CNCCTrie::updateExpirationRow(int nHeight, std::vector<CValueQueueEntry>& row)
void CClaimTrie::updateExpirationRow(int nHeight, std::vector<CValueQueueEntry>& row)
{
valueQueueType::iterator itQueueRow = dirtyExpirationQueueRows.find(nHeight);
if (itQueueRow == dirtyExpirationQueueRows.end())
@ -403,14 +403,14 @@ void CNCCTrie::updateExpirationRow(int nHeight, std::vector<CValueQueueEntry>& r
itQueueRow->second.swap(row);
}
bool CNCCTrie::update(nodeCacheType& cache, hashMapType& hashes, const uint256& hashBlockIn, valueQueueType& queueCache, valueQueueType& expirationQueueCache, int nNewHeight)
bool CClaimTrie::update(nodeCacheType& cache, hashMapType& hashes, const uint256& hashBlockIn, valueQueueType& queueCache, valueQueueType& expirationQueueCache, int nNewHeight)
{
// General strategy: the cache is ordered by length, ensuring child
// nodes are always inserted after their parents. Insert each node
// one at a time. When updating a node, swap its values with those
// of the cached node and delete all characters (and their children
// and so forth) which don't exist in the updated node. When adding
// a new node, make sure that its <character, CNCCTrieNode*> pair
// a new node, make sure that its <character, CClaimTrieNode*> pair
// gets into the parent's children.
// Then, update all of the given hashes.
// This can probably be optimized by checking each substring against
@ -450,17 +450,17 @@ bool CNCCTrie::update(nodeCacheType& cache, hashMapType& hashes, const uint256&
return true;
}
void CNCCTrie::markNodeDirty(const std::string &name, CNCCTrieNode* node)
void CClaimTrie::markNodeDirty(const std::string &name, CClaimTrieNode* node)
{
std::pair<nodeCacheType::iterator, bool> ret;
ret = dirtyNodes.insert(std::pair<std::string, CNCCTrieNode*>(name, node));
ret = dirtyNodes.insert(std::pair<std::string, CClaimTrieNode*>(name, node));
if (ret.second == false)
ret.first->second = node;
}
bool CNCCTrie::updateName(const std::string &name, CNCCTrieNode* updatedNode)
bool CClaimTrie::updateName(const std::string &name, CClaimTrieNode* updatedNode)
{
CNCCTrieNode* current = &root;
CClaimTrieNode* current = &root;
for (std::string::const_iterator itname = name.begin(); itname != name.end(); ++itname)
{
nodeMapType::iterator itchild = current->children.find(*itname);
@ -468,7 +468,7 @@ bool CNCCTrie::updateName(const std::string &name, CNCCTrieNode* updatedNode)
{
if (itname + 1 == name.end())
{
CNCCTrieNode* newNode = new CNCCTrieNode();
CClaimTrieNode* newNode = new CClaimTrieNode();
current->children[*itname] = newNode;
current = newNode;
}
@ -503,7 +503,7 @@ bool CNCCTrie::updateName(const std::string &name, CNCCTrieNode* updatedNode)
return true;
}
bool CNCCTrie::recursiveNullify(CNCCTrieNode* node, std::string& name)
bool CClaimTrie::recursiveNullify(CClaimTrieNode* node, std::string& name)
{
assert(node != NULL);
for (nodeMapType::iterator itchild = node->children.begin(); itchild != node->children.end(); ++itchild)
@ -520,9 +520,9 @@ bool CNCCTrie::recursiveNullify(CNCCTrieNode* node, std::string& name)
return true;
}
bool CNCCTrie::updateHash(const std::string& name, uint256& hash)
bool CClaimTrie::updateHash(const std::string& name, uint256& hash)
{
CNCCTrieNode* current = &root;
CClaimTrieNode* current = &root;
for (std::string::const_iterator itname = name.begin(); itname != name.end(); ++itname)
{
nodeMapType::iterator itchild = current->children.find(*itname);
@ -536,7 +536,7 @@ bool CNCCTrie::updateHash(const std::string& name, uint256& hash)
return true;
}
void CNCCTrie::BatchWriteNode(CLevelDBBatch& batch, const std::string& name, const CNCCTrieNode* pNode) const
void CClaimTrie::BatchWriteNode(CLevelDBBatch& batch, const std::string& name, const CClaimTrieNode* pNode) const
{
LogPrintf("%s: Writing %s to disk with %d values\n", __func__, name, pNode->values.size());
if (pNode)
@ -545,7 +545,7 @@ void CNCCTrie::BatchWriteNode(CLevelDBBatch& batch, const std::string& name, con
batch.Erase(std::make_pair('n', name));
}
void CNCCTrie::BatchWriteQueueRows(CLevelDBBatch& batch)
void CClaimTrie::BatchWriteQueueRows(CLevelDBBatch& batch)
{
for (valueQueueType::iterator itQueue = dirtyQueueRows.begin(); itQueue != dirtyQueueRows.end(); ++itQueue)
{
@ -560,7 +560,7 @@ void CNCCTrie::BatchWriteQueueRows(CLevelDBBatch& batch)
}
}
void CNCCTrie::BatchWriteExpirationQueueRows(CLevelDBBatch& batch)
void CClaimTrie::BatchWriteExpirationQueueRows(CLevelDBBatch& batch)
{
for (valueQueueType::iterator itQueue = dirtyExpirationQueueRows.begin(); itQueue != dirtyExpirationQueueRows.end(); ++itQueue)
{
@ -575,7 +575,7 @@ void CNCCTrie::BatchWriteExpirationQueueRows(CLevelDBBatch& batch)
}
}
bool CNCCTrie::WriteToDisk()
bool CClaimTrie::WriteToDisk()
{
CLevelDBBatch batch;
for (nodeCacheType::iterator itcache = dirtyNodes.begin(); itcache != dirtyNodes.end(); ++itcache)
@ -590,14 +590,14 @@ bool CNCCTrie::WriteToDisk()
return db.WriteBatch(batch);
}
bool CNCCTrie::InsertFromDisk(const std::string& name, CNCCTrieNode* node)
bool CClaimTrie::InsertFromDisk(const std::string& name, CClaimTrieNode* node)
{
if (name.size() == 0)
{
root = *node;
return true;
}
CNCCTrieNode* current = &root;
CClaimTrieNode* current = &root;
for (std::string::const_iterator itname = name.begin(); itname + 1 != name.end(); ++itname)
{
nodeMapType::iterator itchild = current->children.find(*itname);
@ -609,7 +609,7 @@ bool CNCCTrie::InsertFromDisk(const std::string& name, CNCCTrieNode* node)
return true;
}
bool CNCCTrie::ReadFromDisk(bool check)
bool CClaimTrie::ReadFromDisk(bool check)
{
if (!db.Read('h', hashBlock))
LogPrintf("%s: Couldn't read the best block's hash\n", __func__);
@ -632,7 +632,7 @@ bool CNCCTrie::ReadFromDisk(bool check)
std::string name;
ssKey >> name;
CDataStream ssValue(slValue.data(), slValue.data()+slValue.size(), SER_DISK, CLIENT_VERSION);
CNCCTrieNode* node = new CNCCTrieNode();
CClaimTrieNode* node = new CClaimTrieNode();
ssValue >> *node;
if (!InsertFromDisk(name, node))
return false;
@ -647,7 +647,7 @@ bool CNCCTrie::ReadFromDisk(bool check)
}
if (check)
{
LogPrintf("Checking NCC trie consistency...");
LogPrintf("Checking Claim trie consistency...");
if (checkConsistency())
{
LogPrintf("consistent\n");
@ -659,7 +659,7 @@ bool CNCCTrie::ReadFromDisk(bool check)
return true;
}
bool CNCCTrieCache::recursiveComputeMerkleHash(CNCCTrieNode* tnCurrent, std::string sPos) const
bool CClaimTrieCache::recursiveComputeMerkleHash(CClaimTrieNode* tnCurrent, std::string sPos) const
{
if (sPos == "" && tnCurrent->empty())
{
@ -716,7 +716,7 @@ bool CNCCTrieCache::recursiveComputeMerkleHash(CNCCTrieNode* tnCurrent, std::str
return true;
}
uint256 CNCCTrieCache::getMerkleHash() const
uint256 CClaimTrieCache::getMerkleHash() const
{
if (empty())
{
@ -738,22 +738,22 @@ uint256 CNCCTrieCache::getMerkleHash() const
return base->root.hash;
}
bool CNCCTrieCache::empty() const
bool CClaimTrieCache::empty() const
{
return base->empty() && cache.empty();
}
bool CNCCTrieCache::insertClaimIntoTrie(const std::string name, CNodeValue val) const
bool CClaimTrieCache::insertClaimIntoTrie(const std::string name, CNodeValue val) const
{
assert(base);
CNCCTrieNode* currentNode = &(base->root);
CClaimTrieNode* currentNode = &(base->root);
nodeCacheType::iterator cachedNode;
cachedNode = cache.find("");
if (cachedNode != cache.end())
currentNode = cachedNode->second;
if (currentNode == NULL)
{
currentNode = new CNCCTrieNode();
currentNode = new CClaimTrieNode();
cache[""] = currentNode;
}
for (std::string::const_iterator itCur = name.begin(); itCur != name.end(); ++itCur)
@ -790,10 +790,10 @@ bool CNCCTrieCache::insertClaimIntoTrie(const std::string name, CNodeValue val)
}
else
{
currentNode = new CNCCTrieNode(*currentNode);
currentNode = new CClaimTrieNode(*currentNode);
cache[sCurrentSubstring] = currentNode;
}
CNCCTrieNode* newNode = new CNCCTrieNode();
CClaimTrieNode* newNode = new CClaimTrieNode();
currentNode->children[*itCur] = newNode;
cache[sNextSubstring] = newNode;
currentNode = newNode;
@ -806,7 +806,7 @@ bool CNCCTrieCache::insertClaimIntoTrie(const std::string name, CNodeValue val)
}
else
{
currentNode = new CNCCTrieNode(*currentNode);
currentNode = new CClaimTrieNode(*currentNode);
cache[name] = currentNode;
}
bool fChanged = false;
@ -823,10 +823,10 @@ bool CNCCTrieCache::insertClaimIntoTrie(const std::string name, CNodeValue val)
return true;
}
bool CNCCTrieCache::removeClaimFromTrie(const std::string name, uint256 txhash, uint32_t nOut, int& nValidAtHeight) const
bool CClaimTrieCache::removeClaimFromTrie(const std::string name, uint256 txhash, uint32_t nOut, int& nValidAtHeight) const
{
assert(base);
CNCCTrieNode* currentNode = &(base->root);
CClaimTrieNode* currentNode = &(base->root);
nodeCacheType::iterator cachedNode;
cachedNode = cache.find("");
if (cachedNode != cache.end())
@ -858,7 +858,7 @@ bool CNCCTrieCache::removeClaimFromTrie(const std::string name, uint256 txhash,
assert(cachedNode->second == currentNode);
else
{
currentNode = new CNCCTrieNode(*currentNode);
currentNode = new CClaimTrieNode(*currentNode);
cache[name] = currentNode;
}
bool fChanged = false;
@ -883,14 +883,14 @@ bool CNCCTrieCache::removeClaimFromTrie(const std::string name, uint256 txhash,
}
dirtyHashes.insert(name);
}
CNCCTrieNode* rootNode = &(base->root);
CClaimTrieNode* rootNode = &(base->root);
cachedNode = cache.find("");
if (cachedNode != cache.end())
rootNode = cachedNode->second;
return recursivePruneName(rootNode, 0, name);
}
bool CNCCTrieCache::recursivePruneName(CNCCTrieNode* tnCurrent, unsigned int nPos, std::string sName, bool* pfNullified) const
bool CClaimTrieCache::recursivePruneName(CClaimTrieNode* tnCurrent, unsigned int nPos, std::string sName, bool* pfNullified) const
{
bool fNullified = false;
std::string sCurrentSubstring = sName.substr(0, nPos);
@ -898,7 +898,7 @@ bool CNCCTrieCache::recursivePruneName(CNCCTrieNode* tnCurrent, unsigned int nPo
{
std::string sNextSubstring = sName.substr(0, nPos + 1);
unsigned char cNext = sName.at(nPos);
CNCCTrieNode* tnNext = NULL;
CClaimTrieNode* tnNext = NULL;
nodeCacheType::iterator cachedNode = cache.find(sNextSubstring);
if (cachedNode != cache.end())
tnNext = cachedNode->second;
@ -933,7 +933,7 @@ bool CNCCTrieCache::recursivePruneName(CNCCTrieNode* tnCurrent, unsigned int nPo
{
// it isn't, so make a copy, stick it in the cache,
// and make it the new current node
tnCurrent = new CNCCTrieNode(*tnCurrent);
tnCurrent = new CClaimTrieNode(*tnCurrent);
cache[sCurrentSubstring] = tnCurrent;
}
// erase the character from the current node, which is
@ -962,7 +962,7 @@ bool CNCCTrieCache::recursivePruneName(CNCCTrieNode* tnCurrent, unsigned int nPo
return true;
}
valueQueueType::iterator CNCCTrieCache::getQueueCacheRow(int nHeight, bool createIfNotExists) const
valueQueueType::iterator CClaimTrieCache::getQueueCacheRow(int nHeight, bool createIfNotExists) const
{
valueQueueType::iterator itQueueRow = valueQueueCache.find(nHeight);
if (itQueueRow == valueQueueCache.end())
@ -983,14 +983,14 @@ valueQueueType::iterator CNCCTrieCache::getQueueCacheRow(int nHeight, bool creat
return itQueueRow;
}
bool CNCCTrieCache::addClaim(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight) const
bool CClaimTrieCache::addClaim(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nAmount: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, nAmount, nHeight, nCurrentHeight);
assert(nHeight == nCurrentHeight);
return addClaimToQueues(name, txhash, nOut, nAmount, nHeight, nHeight + DEFAULT_DELAY);
}
bool CNCCTrieCache::addClaim(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight, uint256 prevTxhash, uint32_t nPrevOut) const
bool CClaimTrieCache::addClaim(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight, uint256 prevTxhash, uint32_t nPrevOut) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nAmount: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, nAmount, nHeight, nCurrentHeight);
assert(nHeight == nCurrentHeight);
@ -1006,7 +1006,7 @@ bool CNCCTrieCache::addClaim(const std::string name, uint256 txhash, uint32_t nO
return addClaim(name, txhash, nOut, nAmount, nHeight);
}
bool CNCCTrieCache::undoSpendClaim(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight, int nValidAtHeight) const
bool CClaimTrieCache::undoSpendClaim(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight, int nValidAtHeight) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nAmount: %d, nHeight: %d, nValidAtHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, nAmount, nHeight, nValidAtHeight, nCurrentHeight);
if (nValidAtHeight < nCurrentHeight)
@ -1023,7 +1023,7 @@ bool CNCCTrieCache::undoSpendClaim(const std::string name, uint256 txhash, uint3
return true;
}
bool CNCCTrieCache::addClaimToQueues(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight, int nValidAtHeight) const
bool CClaimTrieCache::addClaimToQueues(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight, int nValidAtHeight) const
{
LogPrintf("%s: nValidAtHeight: %d\n", __func__, nValidAtHeight);
CNodeValue val(txhash, nOut, nAmount, nHeight, nValidAtHeight);
@ -1034,7 +1034,7 @@ bool CNCCTrieCache::addClaimToQueues(const std::string name, uint256 txhash, uin
return true;
}
bool CNCCTrieCache::removeClaimFromQueue(const std::string name, uint256 txhash, uint32_t nOut, int nHeightToCheck, int& nValidAtHeight) const
bool CClaimTrieCache::removeClaimFromQueue(const std::string name, uint256 txhash, uint32_t nOut, int nHeightToCheck, int& nValidAtHeight) const
{
valueQueueType::iterator itQueueRow = getQueueCacheRow(nHeightToCheck, false);
if (itQueueRow == valueQueueCache.end())
@ -1059,18 +1059,18 @@ bool CNCCTrieCache::removeClaimFromQueue(const std::string name, uint256 txhash,
return false;
}
bool CNCCTrieCache::undoAddClaim(const std::string name, uint256 txhash, uint32_t nOut, int nHeight) const
bool CClaimTrieCache::undoAddClaim(const std::string name, uint256 txhash, uint32_t nOut, int nHeight) const
{
int throwaway;
return removeClaim(name, txhash, nOut, nHeight, throwaway);
}
bool CNCCTrieCache::spendClaim(const std::string name, uint256 txhash, uint32_t nOut, int nHeight, int& nValidAtHeight) const
bool CClaimTrieCache::spendClaim(const std::string name, uint256 txhash, uint32_t nOut, int nHeight, int& nValidAtHeight) const
{
return removeClaim(name, txhash, nOut, nHeight, nValidAtHeight);
}
bool CNCCTrieCache::removeClaim(const std::string name, uint256 txhash, uint32_t nOut, int nHeight, int& nValidAtHeight) const
bool CClaimTrieCache::removeClaim(const std::string name, uint256 txhash, uint32_t nOut, int nHeight, int& nValidAtHeight) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %s, nHeight: %s, nCurrentHeight: %s\n", __func__, name, txhash.GetHex(), nOut, nHeight, nCurrentHeight);
bool removed = false;
@ -1090,14 +1090,14 @@ bool CNCCTrieCache::removeClaim(const std::string name, uint256 txhash, uint32_t
return removed;
}
void CNCCTrieCache::addToExpirationQueue(CValueQueueEntry& entry) const
void CClaimTrieCache::addToExpirationQueue(CValueQueueEntry& entry) const
{
int expirationHeight = entry.val.nHeight + base->nExpirationTime;
valueQueueType::iterator itQueueRow = getExpirationQueueCacheRow(expirationHeight, true);
itQueueRow->second.push_back(entry);
}
void CNCCTrieCache::removeFromExpirationQueue(const std::string name, uint256 txhash, uint32_t nOut, int nHeight) const
void CClaimTrieCache::removeFromExpirationQueue(const std::string name, uint256 txhash, uint32_t nOut, int nHeight) const
{
int expirationHeight = nHeight + base->nExpirationTime;
valueQueueType::iterator itQueueRow = getExpirationQueueCacheRow(expirationHeight, false);
@ -1117,7 +1117,7 @@ void CNCCTrieCache::removeFromExpirationQueue(const std::string name, uint256 tx
}
}
valueQueueType::iterator CNCCTrieCache::getExpirationQueueCacheRow(int nHeight, bool createIfNotExists) const
valueQueueType::iterator CClaimTrieCache::getExpirationQueueCacheRow(int nHeight, bool createIfNotExists) const
{
valueQueueType::iterator itQueueRow = expirationQueueCache.find(nHeight);
if (itQueueRow == expirationQueueCache.end())
@ -1138,7 +1138,7 @@ valueQueueType::iterator CNCCTrieCache::getExpirationQueueCacheRow(int nHeight,
return itQueueRow;
}
bool CNCCTrieCache::incrementBlock(CNCCTrieQueueUndo& insertUndo, CNCCTrieQueueUndo& expireUndo) const
bool CClaimTrieCache::incrementBlock(CClaimTrieQueueUndo& insertUndo, CClaimTrieQueueUndo& expireUndo) const
{
LogPrintf("%s: nCurrentHeight (before increment): %d\n", __func__, nCurrentHeight);
valueQueueType::iterator itQueueRow = getQueueCacheRow(nCurrentHeight, false);
@ -1167,14 +1167,14 @@ bool CNCCTrieCache::incrementBlock(CNCCTrieQueueUndo& insertUndo, CNCCTrieQueueU
return true;
}
bool CNCCTrieCache::decrementBlock(CNCCTrieQueueUndo& insertUndo, CNCCTrieQueueUndo& expireUndo) const
bool CClaimTrieCache::decrementBlock(CClaimTrieQueueUndo& insertUndo, CClaimTrieQueueUndo& expireUndo) const
{
LogPrintf("%s: nCurrentHeight (before decrement): %d\n", __func__, nCurrentHeight);
nCurrentHeight--;
if (insertUndo.begin() != insertUndo.end())
{
valueQueueType::iterator itQueueRow = getQueueCacheRow(nCurrentHeight, true);
for (CNCCTrieQueueUndo::iterator itInsertUndo = insertUndo.begin(); itInsertUndo != insertUndo.end(); ++itInsertUndo)
for (CClaimTrieQueueUndo::iterator itInsertUndo = insertUndo.begin(); itInsertUndo != insertUndo.end(); ++itInsertUndo)
{
int nValidHeightInTrie;
assert(removeClaimFromTrie(itInsertUndo->name, itInsertUndo->val.txhash, itInsertUndo->val.nOut, nValidHeightInTrie));
@ -1185,7 +1185,7 @@ bool CNCCTrieCache::decrementBlock(CNCCTrieQueueUndo& insertUndo, CNCCTrieQueueU
if (expireUndo.begin() != expireUndo.end())
{
valueQueueType::iterator itExpireRow = getExpirationQueueCacheRow(nCurrentHeight, true);
for (CNCCTrieQueueUndo::iterator itExpireUndo = expireUndo.begin(); itExpireUndo != expireUndo.end(); ++itExpireUndo)
for (CClaimTrieQueueUndo::iterator itExpireUndo = expireUndo.begin(); itExpireUndo != expireUndo.end(); ++itExpireUndo)
{
insertClaimIntoTrie(itExpireUndo->name, itExpireUndo->val);
itExpireRow->second.push_back(*itExpireUndo);
@ -1194,7 +1194,7 @@ bool CNCCTrieCache::decrementBlock(CNCCTrieQueueUndo& insertUndo, CNCCTrieQueueU
return true;
}
uint256 CNCCTrieCache::getBestBlock()
uint256 CClaimTrieCache::getBestBlock()
{
if (hashBlock.IsNull())
if (base != NULL)
@ -1202,12 +1202,12 @@ uint256 CNCCTrieCache::getBestBlock()
return hashBlock;
}
void CNCCTrieCache::setBestBlock(const uint256& hashBlockIn)
void CClaimTrieCache::setBestBlock(const uint256& hashBlockIn)
{
hashBlock = hashBlockIn;
}
bool CNCCTrieCache::clear() const
bool CClaimTrieCache::clear() const
{
for (nodeCacheType::iterator itcache = cache.begin(); itcache != cache.end(); ++itcache)
{
@ -1220,7 +1220,7 @@ bool CNCCTrieCache::clear() const
return true;
}
bool CNCCTrieCache::flush()
bool CClaimTrieCache::flush()
{
if (dirty())
getMerkleHash();

View file

@ -1,5 +1,5 @@
#ifndef BITCOIN_NCCTRIE_H
#define BITCOIN_NCCTRIE_H
#ifndef BITCOIN_ClaimTRIE_H
#define BITCOIN_ClaimTRIE_H
#include "amount.h"
#include "serialize.h"
@ -67,18 +67,18 @@ public:
}
};
class CNCCTrieNode;
class CNCCTrie;
class CClaimTrieNode;
class CClaimTrie;
typedef std::map<unsigned char, CNCCTrieNode*> nodeMapType;
typedef std::map<unsigned char, CClaimTrieNode*> nodeMapType;
typedef std::pair<std::string, CNCCTrieNode> namedNodeType;
typedef std::pair<std::string, CClaimTrieNode> namedNodeType;
class CNCCTrieNode
class CClaimTrieNode
{
public:
CNCCTrieNode() {}
CNCCTrieNode(uint256 hash) : hash(hash) {}
CClaimTrieNode() {}
CClaimTrieNode(uint256 hash) : hash(hash) {}
uint256 hash;
uint256 bestBlock;
nodeMapType children;
@ -96,12 +96,12 @@ public:
READWRITE(values);
}
bool operator==(const CNCCTrieNode& other) const
bool operator==(const CClaimTrieNode& other) const
{
return hash == other.hash && values == other.values;
}
bool operator!=(const CNCCTrieNode& other) const
bool operator!=(const CClaimTrieNode& other) const
{
return !(*this == other);
}
@ -137,18 +137,18 @@ class CValueQueueEntry
};
typedef std::map<int, std::vector<CValueQueueEntry> > valueQueueType;
typedef std::vector<CValueQueueEntry> CNCCTrieQueueUndo;
typedef std::vector<CValueQueueEntry> CClaimTrieQueueUndo;
typedef std::map<std::string, CNCCTrieNode*, nodenamecompare> nodeCacheType;
typedef std::map<std::string, CClaimTrieNode*, nodenamecompare> nodeCacheType;
typedef std::map<std::string, uint256> hashMapType;
class CNCCTrieCache;
class CClaimTrieCache;
class CNCCTrie
class CClaimTrie
{
public:
CNCCTrie(bool fMemory = false, bool fWipe = false) : db(GetDataDir() / "ncctrie", 100, fMemory, fWipe), nCurrentHeight(0), nExpirationTime(262974), root(uint256S("0000000000000000000000000000000000000000000000000000000000000001")) {}
CClaimTrie(bool fMemory = false, bool fWipe = false) : db(GetDataDir() / "claimtrie", 100, fMemory, fWipe), nCurrentHeight(0), nExpirationTime(262974), root(uint256S("0000000000000000000000000000000000000000000000000000000000000001")) {}
uint256 getMerkleHash();
CLevelDBWrapper db;
bool empty() const;
@ -168,39 +168,39 @@ public:
unsigned int getTotalNamesInTrie() const;
unsigned int getTotalClaimsInTrie() const;
CAmount getTotalValueOfClaimsInTrie(bool fControllingOnly) const;
friend class CNCCTrieCache;
friend class CClaimTrieCache;
int nExpirationTime;
private:
void clear(CNCCTrieNode* current);
void clear(CClaimTrieNode* current);
bool update(nodeCacheType& cache, hashMapType& hashes, const uint256& hashBlock, valueQueueType& queueCache, valueQueueType& expirationQueueCache, int nNewHeight);
bool updateName(const std::string& name, CNCCTrieNode* updatedNode);
bool updateName(const std::string& name, CClaimTrieNode* updatedNode);
bool updateHash(const std::string& name, uint256& hash);
bool recursiveNullify(CNCCTrieNode* node, std::string& name);
bool recursiveCheckConsistency(CNCCTrieNode* node);
bool InsertFromDisk(const std::string& name, CNCCTrieNode* node);
unsigned int getTotalNamesRecursive(const CNCCTrieNode* current) const;
unsigned int getTotalClaimsRecursive(const CNCCTrieNode* current) const;
CAmount getTotalValueOfClaimsRecursive(const CNCCTrieNode* current, bool fControllingOnly) const;
bool recursiveFlattenTrie(const std::string& name, const CNCCTrieNode* current, std::vector<namedNodeType>& nodes) const;
CNCCTrieNode root;
bool recursiveNullify(CClaimTrieNode* node, std::string& name);
bool recursiveCheckConsistency(CClaimTrieNode* node);
bool InsertFromDisk(const std::string& name, CClaimTrieNode* node);
unsigned int getTotalNamesRecursive(const CClaimTrieNode* current) const;
unsigned int getTotalClaimsRecursive(const CClaimTrieNode* current) const;
CAmount getTotalValueOfClaimsRecursive(const CClaimTrieNode* current, bool fControllingOnly) const;
bool recursiveFlattenTrie(const std::string& name, const CClaimTrieNode* current, std::vector<namedNodeType>& nodes) const;
CClaimTrieNode root;
uint256 hashBlock;
valueQueueType dirtyQueueRows;
valueQueueType dirtyExpirationQueueRows;
nodeCacheType dirtyNodes;
void markNodeDirty(const std::string& name, CNCCTrieNode* node);
void markNodeDirty(const std::string& name, CClaimTrieNode* node);
void updateQueueRow(int nHeight, std::vector<CValueQueueEntry>& row);
void updateExpirationRow(int nHeight, std::vector<CValueQueueEntry>& row);
void BatchWriteNode(CLevelDBBatch& batch, const std::string& name, const CNCCTrieNode* pNode) const;
void BatchWriteNode(CLevelDBBatch& batch, const std::string& name, const CClaimTrieNode* pNode) const;
void BatchEraseNode(CLevelDBBatch& batch, const std::string& nome) const;
void BatchWriteQueueRows(CLevelDBBatch& batch);
void BatchWriteExpirationQueueRows(CLevelDBBatch& batch);
};
class CNCCTrieCache
class CClaimTrieCache
{
public:
CNCCTrieCache(CNCCTrie* base): base(base) {assert(base); nCurrentHeight = base->nCurrentHeight;}
CClaimTrieCache(CClaimTrie* base): base(base) {assert(base); nCurrentHeight = base->nCurrentHeight;}
uint256 getMerkleHash() const;
bool empty() const;
bool flush();
@ -212,13 +212,13 @@ public:
bool undoSpendClaim(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight, int nValidAtHeight) const;
uint256 getBestBlock();
void setBestBlock(const uint256& hashBlock);
bool incrementBlock(CNCCTrieQueueUndo& insertUndo, CNCCTrieQueueUndo& expireUndo) const;
bool decrementBlock(CNCCTrieQueueUndo& insertUndo, CNCCTrieQueueUndo& expireUndo) const;
~CNCCTrieCache() { clear(); }
bool incrementBlock(CClaimTrieQueueUndo& insertUndo, CClaimTrieQueueUndo& expireUndo) const;
bool decrementBlock(CClaimTrieQueueUndo& insertUndo, CClaimTrieQueueUndo& expireUndo) const;
~CClaimTrieCache() { clear(); }
bool insertClaimIntoTrie(const std::string name, CNodeValue val) const;
bool removeClaimFromTrie(const std::string name, uint256 txhash, uint32_t nOut, int& nValidAtHeight) const;
private:
CNCCTrie* base;
CClaimTrie* base;
mutable nodeCacheType cache;
mutable std::set<std::string> dirtyHashes;
mutable hashMapType cacheHashes;
@ -227,8 +227,8 @@ private:
mutable int nCurrentHeight; // Height of the block that is being worked on, which is
// one greater than the height of the chain's tip
uint256 computeHash() const;
bool recursiveComputeMerkleHash(CNCCTrieNode* tnCurrent, std::string sPos) const;
bool recursivePruneName(CNCCTrieNode* tnCurrent, unsigned int nPos, std::string sName, bool* pfNullified = NULL) const;
bool recursiveComputeMerkleHash(CClaimTrieNode* tnCurrent, std::string sPos) const;
bool recursivePruneName(CClaimTrieNode* tnCurrent, unsigned int nPos, std::string sName, bool* pfNullified = NULL) const;
bool clear() const;
bool removeClaim(const std::string name, uint256 txhash, uint32_t nOut, int nHeight, int& nValidAtHeight) const;
bool addClaimToQueues(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight, int nValidAtHeight) const;
@ -240,4 +240,4 @@ private:
uint256 hashBlock;
};
#endif // BITCOIN_NCCTRIE_H
#endif // BITCOIN_ClaimTRIE_H

View file

@ -185,8 +185,8 @@ void Shutdown()
pcoinsdbview = NULL;
delete pblocktree;
pblocktree = NULL;
delete pnccTrie;
pnccTrie = NULL;
delete pclaimTrie;
pclaimTrie = NULL;
}
#ifdef ENABLE_WALLET
if (pwalletMain)
@ -413,7 +413,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-rpcbind=<addr>", _("Bind to given address to listen for JSON-RPC connections. Use [host]:port notation for IPv6. This option can be specified multiple times (default: bind to all interfaces)"));
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Listen for JSON-RPC connections on <port> (default: %u or testnet: %u)"), 8332, 18332));
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Listen for JSON-RPC connections on <port> (default: %u or testnet: %u)"), 9245, 19245));
strUsage += HelpMessageOpt("-rpcallowip=<ip>", _("Allow JSON-RPC connections from specified source. Valid for <ip> are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option can be specified multiple times"));
strUsage += HelpMessageOpt("-rpcthreads=<n>", strprintf(_("Set the number of threads to service RPC calls (default: %d)"), 4));
strUsage += HelpMessageOpt("-rpckeepalive", strprintf(_("RPC support for HTTP persistent connections (default: %d)"), 1));
@ -1120,13 +1120,13 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
delete pcoinsdbview;
delete pcoinscatcher;
delete pblocktree;
delete pnccTrie;
delete pclaimTrie;
pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReindex);
pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex);
pcoinscatcher = new CCoinsViewErrorCatcher(pcoinsdbview);
pcoinsTip = new CCoinsViewCache(pcoinscatcher);
pnccTrie = new CNCCTrie(false, fReindex);
pclaimTrie = new CClaimTrie(false, fReindex);
if (fReindex) {
pblocktree->WriteReindexing(true);
@ -1157,9 +1157,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
break;
}
if (!pnccTrie->ReadFromDisk(true))
if (!pclaimTrie->ReadFromDisk(true))
{
strLoadError = _("Error loading the ncc trie from disk");
strLoadError = _("Error loading the claim trie from disk");
break;
}

View file

@ -14,7 +14,7 @@
#include "consensus/validation.h"
#include "init.h"
#include "merkleblock.h"
#include "ncc.h"
#include "nameclaim.h"
#include "net.h"
#include "pow.h"
#include "txdb.h"
@ -23,7 +23,6 @@
#include "undo.h"
#include "util.h"
#include "utilmoneystr.h"
#include "ncc.h"
#include "validationinterface.h"
#include <sstream>
@ -517,7 +516,7 @@ CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& loc
}
CCoinsViewCache *pcoinsTip = NULL;
CNCCTrie *pnccTrie = NULL;
CClaimTrie *pclaimTrie = NULL;
CBlockTreeDB *pblocktree = NULL;
//////////////////////////////////////////////////////////////////////////////
@ -647,7 +646,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason)
txnouttype whichType;
BOOST_FOREACH(const CTxOut& txout, tx.vout) {
const CScript& scriptPubKey = StripNCCScriptPrefix(txout.scriptPubKey);
const CScript& scriptPubKey = StripClaimScriptPrefix(txout.scriptPubKey);
if (!::IsStandard(scriptPubKey, whichType)) {
reason = "scriptpubkey";
@ -713,7 +712,7 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
vector<vector<unsigned char> > vSolutions;
txnouttype whichType;
// get the scriptPubKey corresponding to this input:
const CScript& prevScript = StripNCCScriptPrefix(prev.scriptPubKey);
const CScript& prevScript = StripClaimScriptPrefix(prev.scriptPubKey);
if (!Solver(prevScript, whichType, vSolutions))
return false;
@ -784,7 +783,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
for (unsigned int i = 0; i < tx.vin.size(); i++)
{
const CTxOut &prevout = inputs.GetOutputFor(tx.vin[i]);
const CScript& scriptPubKey = StripNCCScriptPrefix(prevout.scriptPubKey);
const CScript& scriptPubKey = StripClaimScriptPrefix(prevout.scriptPubKey);
if (scriptPubKey.IsPayToScriptHash())
nSigOps += scriptPubKey.GetSigOpCount(tx.vin[i].scriptSig);
}
@ -1597,7 +1596,7 @@ bool AbortNode(CValidationState& state, const std::string& strMessage, const std
* @param out The out point that corresponds to the tx input.
* @return True on success.
*/
static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, CNCCTrieCache& trieCache, const COutPoint& out)
static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, CClaimTrieCache& trieCache, const COutPoint& out)
{
bool fClean = true;
@ -1619,15 +1618,15 @@ static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, CNCCTrie
if (coins->vout.size() < out.n+1)
coins->vout.resize(out.n+1);
// restore NCC claim if applicable
// restore claim if applicable
int op;
std::vector<std::vector<unsigned char> > vvchParams;
if (DecodeNCCScript(undo.txout.scriptPubKey, op, vvchParams))
if (DecodeClaimScript(undo.txout.scriptPubKey, op, vvchParams))
{
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
LogPrintf("%s: Restoring %s to the NCC trie due to a block being disconnected\n", __func__, name.c_str());
int nValidHeight = undo.nNCCValidHeight;
LogPrintf("%s: Restoring %s to the claim trie due to a block being disconnected\n", __func__, name.c_str());
int nValidHeight = undo.nClaimValidHeight;
if (nValidHeight > 0 && nValidHeight >= coins->nHeight)
{
if (!trieCache.undoSpendClaim(name, out.hash, out.n, undo.txout.nValue, coins->nHeight, nValidHeight))
@ -1640,7 +1639,7 @@ static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, CNCCTrie
return fClean;
}
bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, CNCCTrieCache& trieCache, bool* pfClean)
bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, CClaimTrieCache& trieCache, bool* pfClean)
{
assert(pindex->GetBlockHash() == view.GetBestBlock());
assert(pindex->GetBlockHash() == trieCache.getBestBlock());
@ -1682,18 +1681,18 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
if (*outs != outsBlock)
fClean = fClean && error("DisconnectBlock(): added transaction mismatch? database corrupted");
// remove any NCC claims
// remove any claims
for (unsigned int i = 0; i < tx.vout.size(); ++i)
{
const CTxOut& txout = tx.vout[i];
int op;
std::vector<std::vector<unsigned char> > vvchParams;
if (DecodeNCCScript(txout.scriptPubKey, op, vvchParams))
if (DecodeClaimScript(txout.scriptPubKey, op, vvchParams))
{
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
LogPrintf("%s: Removing %s from the ncc trie due to its block being disconnected\n", __func__, name.c_str());
LogPrintf("%s: Removing %s from the claim trie due to its block being disconnected\n", __func__, name.c_str());
if (!trieCache.undoAddClaim(name, hash, i, pindex->nHeight))
LogPrintf("%s: Something went wrong removing the name %s in hash %s\n", __func__, name.c_str(), hash.GetHex());
}
@ -1720,7 +1719,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
// move best block pointer to prevout block
view.SetBestBlock(pindex->pprev->GetBlockHash());
trieCache.setBestBlock(pindex->pprev->GetBlockHash());
assert(trieCache.getMerkleHash() == pindex->pprev->hashNCCTrie);
assert(trieCache.getMerkleHash() == pindex->pprev->hashClaimTrie);
if (pfClean) {
*pfClean = fClean;
@ -1826,7 +1825,7 @@ static int64_t nTimeIndex = 0;
static int64_t nTimeCallbacks = 0;
static int64_t nTimeTotal = 0;
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, CNCCTrieCache& trieCache, bool fJustCheck)
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, CClaimTrieCache& trieCache, bool fJustCheck)
{
const CChainParams& chainparams = Params();
AssertLockHeld(cs_main);
@ -1918,7 +1917,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
return state.DoS(100, error("ConnectBlock(): too many sigops"),
REJECT_INVALID, "bad-blk-sigops");
std::map<unsigned int, unsigned int> mNCCUndoHeights;
std::map<unsigned int, unsigned int> mClaimUndoHeights;
if (!tx.IsCoinBase())
{
@ -1944,11 +1943,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
return false;
control.Add(vChecks);
// To handle NCC updates, stick all NCC claims found in the inputs into a map of
// name: (txhash, nOut). When running through the outputs, if any NCC claim's
// To handle claim updates, stick all claims found in the inputs into a map of
// name: (txhash, nOut). When running through the outputs, if any claim's
// name is found in the map, send the name's txhash and nOut to the trie cache,
// and then remove the name: (txhash, nOut) mapping from the map.
// If there are two or more NCC claims in the inputs with the same name, only
// If there are two or more claims in the inputs with the same name, only
// use the first.
// TODO: before releasing, see if it's a better idea to make an explicit
// operation for updating, like OP_UPDATE_NAME, which directly references
@ -1968,15 +1967,15 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
int op;
std::vector<std::vector<unsigned char> > vvchParams;
if (DecodeNCCScript(coins->vout[txin.prevout.n].scriptPubKey, op, vvchParams))
if (DecodeClaimScript(coins->vout[txin.prevout.n].scriptPubKey, op, vvchParams))
{
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
int nValidAtHeight;
LogPrintf("%s: Removing %s from the ncc trie. Tx: %s, nOut: %d\n", __func__, name, txin.prevout.hash.GetHex(), txin.prevout.n);
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))
{
mNCCUndoHeights[i] = nValidAtHeight;
mClaimUndoHeights[i] = nValidAtHeight;
std::pair<uint256, unsigned int> val(txin.prevout.hash, txin.prevout.n);
std::pair<std::string, std::pair<uint256, unsigned int> > entry(name, val);
spentClaims.insert(entry);
@ -1990,11 +1989,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
int op;
std::vector<std::vector<unsigned char> > vvchParams;
if (DecodeNCCScript(txout.scriptPubKey, op, vvchParams))
if (DecodeClaimScript(txout.scriptPubKey, op, vvchParams))
{
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
LogPrintf("%s: Inserting %s into the ncc trie. Tx: %s, nOut: %d\n", __func__, name, tx.GetHash().GetHex(), i);
LogPrintf("%s: Inserting %s into the claim trie. Tx: %s, nOut: %d\n", __func__, name, tx.GetHash().GetHex(), i);
spentClaimsType::iterator itSpent = spentClaims.find(name);
bool success;
if (itSpent != spentClaims.end())
@ -2017,17 +2016,17 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
blockundo.vtxundo.push_back(CTxUndo());
}
UpdateCoins(tx, state, view, i == 0 ? undoDummy : blockundo.vtxundo.back(), pindex->nHeight);
if (i > 0 && !mNCCUndoHeights.empty())
if (i > 0 && !mClaimUndoHeights.empty())
{
std::vector<CTxInUndo>& txinUndos = blockundo.vtxundo.back().vprevout;
for (std::map<unsigned int, unsigned int>::iterator itHeight = mNCCUndoHeights.begin(); itHeight != mNCCUndoHeights.end(); ++itHeight)
for (std::map<unsigned int, unsigned int>::iterator itHeight = mClaimUndoHeights.begin(); itHeight != mClaimUndoHeights.end(); ++itHeight)
{
txinUndos[itHeight->first].nNCCValidHeight = itHeight->second;
txinUndos[itHeight->first].nClaimValidHeight = itHeight->second;
}
}
// The CTxUndo vector contains the heights at which NCC claims should be put into the trie.
// This is necessary because some NCC claims are inserted immediately into the trie, and
// others are inserted after a delay, depending on the state of the NCC trie at the time
// The CTxUndo vector contains the heights at which claims should be put into the trie.
// This is necessary because some claims are inserted immediately into the trie, and
// others are inserted after a delay, depending on the state of the claim trie at the time
// that the claim was originally inserted into the blockchain. That state will not be
// available when and if this block is disconnected.
@ -2037,11 +2036,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
assert(trieCache.incrementBlock(blockundo.insertUndo, blockundo.expireUndo));
if (trieCache.getMerkleHash() != block.hashNCCTrie)
if (trieCache.getMerkleHash() != block.hashClaimTrie)
return state.DoS(100,
error("ConnectBlock() : the merkle root of the NCC trie does not match "
error("ConnectBlock() : the merkle root of the claim trie does not match "
"(actual=%s vs block=%s)", trieCache.getMerkleHash().GetHex(),
block.hashNCCTrie.GetHex()), REJECT_INVALID, "bad-ncc-merkle-hash");
block.hashClaimTrie.GetHex()), REJECT_INVALID, "bad-claim-merkle-hash");
int64_t nTime1 = GetTimeMicros(); nTimeConnect += nTime1 - nTimeStart;
LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1), nTimeConnect * 0.000001);
@ -2196,8 +2195,8 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
if (!CheckDiskSpace(128 * 2 * 2 * pcoinsTip->GetCacheSize()))
return state.Error("out of disk space");
// Flush the chainstate (which may refer to block index entries).
if (!pnccTrie->WriteToDisk())
return AbortNode("Failed to write to ncc trie database");
if (!pclaimTrie->WriteToDisk())
return AbortNode("Failed to write to claim trie database");
if (!pcoinsTip->Flush())
return AbortNode(state, "Failed to write to coin database");
nLastFlush = nNow;
@ -2277,12 +2276,12 @@ bool static DisconnectTip(CValidationState &state) {
int64_t nStart = GetTimeMicros();
{
CCoinsViewCache view(pcoinsTip);
CNCCTrieCache trieCache(pnccTrie);
CClaimTrieCache trieCache(pclaimTrie);
if (!DisconnectBlock(block, state, pindexDelete, view, trieCache))
return error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString());
assert(view.Flush());
assert(trieCache.flush());
assert(pindexDelete->pprev->hashNCCTrie == trieCache.getMerkleHash());
assert(pindexDelete->pprev->hashClaimTrie == trieCache.getMerkleHash());
}
LogPrint("bench", "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * 0.001);
// Write the chain state to disk, if necessary.
@ -2335,7 +2334,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
LogPrint("bench", " - Load block from disk: %.2fms [%.2fs]\n", (nTime2 - nTime1) * 0.001, nTimeReadFromDisk * 0.000001);
{
CCoinsViewCache view(pcoinsTip);
CNCCTrieCache trieCache(pnccTrie);
CClaimTrieCache trieCache(pclaimTrie);
CInv inv(MSG_BLOCK, pindexNew->GetBlockHash());
bool rv = ConnectBlock(*pblock, state, pindexNew, view, trieCache);
GetMainSignals().BlockChecked(*pblock, state);
@ -3101,7 +3100,7 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex
return error("%s: CheckIndexAgainstCheckpoint(): %s", __func__, state.GetRejectReason().c_str());
CCoinsViewCache viewNew(pcoinsTip);
CNCCTrieCache trieCache(pnccTrie);
CClaimTrieCache trieCache(pclaimTrie);
CBlockIndex indexDummy(block);
indexDummy.pprev = pindexPrev;
indexDummy.nHeight = pindexPrev->nHeight + 1;
@ -3426,7 +3425,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
nCheckLevel = std::max(0, std::min(4, nCheckLevel));
LogPrintf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel);
CCoinsViewCache coins(coinsview);
CNCCTrieCache trieCache(pnccTrie);
CClaimTrieCache trieCache(pclaimTrie);
CBlockIndex* pindexState = chainActive.Tip();
CBlockIndex* pindexFailure = NULL;
int nGoodTransactions = 0;

View file

@ -18,7 +18,7 @@
#include "net.h"
#include "primitives/block.h"
#include "primitives/transaction.h"
#include "ncctrie.h"
#include "claimtrie.h"
#include "script/script.h"
#include "script/sigcache.h"
#include "script/standard.h"
@ -387,10 +387,10 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex);
* In case pfClean is provided, operation will try to be tolerant about errors, and *pfClean
* will be true if no problems were found. Otherwise, the return value will be false in case
* of problems. Note that in any case, coins may be modified. */
bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, CNCCTrieCache& trieCache, bool* pfClean = NULL);
bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, CClaimTrieCache& trieCache, bool* pfClean = NULL);
/** Apply the effects of this block (with given index) on the UTXO set represented by coins */
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, CNCCTrieCache& trieCache, bool fJustCheck = false);
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, CClaimTrieCache& trieCache, bool fJustCheck = false);
/** Context-independent validity checks */
bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true);
@ -486,8 +486,8 @@ extern CChain chainActive;
/** Global variable that points to the active CCoinsView (protected by cs_main) */
extern CCoinsViewCache *pcoinsTip;
/** Global variable that points to the active CNCCTrie (protected by cs_main) */
extern CNCCTrie *pnccTrie;
/** Global variable that points to the active CClaimTrie (protected by cs_main) */
extern CClaimTrie *pclaimTrie;
/** Global variable that points to the active block tree (protected by cs_main) */
extern CBlockTreeDB *pblocktree;

View file

@ -11,8 +11,8 @@
#include "consensus/validation.h"
#include "hash.h"
#include "main.h"
#include "ncc.h"
#include "ncctrie.h"
#include "nameclaim.h"
#include "claimtrie.h"
#include "net.h"
#include "pow.h"
#include "primitives/transaction.h"
@ -142,11 +142,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
const int nHeight = pindexPrev->nHeight + 1;
pblock->nTime = GetAdjustedTime();
CCoinsViewCache view(pcoinsTip);
if (!pnccTrie)
if (!pclaimTrie)
{
return NULL;
}
CNCCTrieCache trieCache(pnccTrie);
CClaimTrieCache trieCache(pclaimTrie);
// Priority order to process transactions
list<COrphan> vOrphan; // list memory doesn't move
@ -308,7 +308,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
std::vector<std::vector<unsigned char> > vvchParams;
int op;
if (DecodeNCCScript(coins->vout[txin.prevout.n].scriptPubKey, op, vvchParams))
if (DecodeClaimScript(coins->vout[txin.prevout.n].scriptPubKey, op, vvchParams))
{
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
@ -329,7 +329,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
std::vector<std::vector<unsigned char> > vvchParams;
int op;
if (DecodeNCCScript(txout.scriptPubKey, op, vvchParams))
if (DecodeClaimScript(txout.scriptPubKey, op, vvchParams))
{
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
@ -396,10 +396,10 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
pblock->nNonce = 0;
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
CNCCTrieQueueUndo dummyInsertUndo;
CNCCTrieQueueUndo dummyExpireUndo;
CClaimTrieQueueUndo dummyInsertUndo;
CClaimTrieQueueUndo dummyExpireUndo;
trieCache.incrementBlock(dummyInsertUndo, dummyExpireUndo);
pblock->hashNCCTrie = trieCache.getMerkleHash();
pblock->hashClaimTrie = trieCache.getMerkleHash();
CValidationState state;
if (!TestBlockValidity(state, *pblock, pindexPrev, false, false))

View file

@ -1,13 +1,13 @@
#include "ncc.h"
#include "nameclaim.h"
#include "util.h"
bool DecodeNCCScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams)
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams)
{
CScript::const_iterator pc = scriptIn.begin();
return DecodeNCCScript(scriptIn, op, vvchParams, pc);
return DecodeClaimScript(scriptIn, op, vvchParams, pc);
}
bool DecodeNCCScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams, CScript::const_iterator& pc)
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams, CScript::const_iterator& pc)
{
opcodetype opcode;
if (!scriptIn.GetOp(pc, opcode))
@ -51,13 +51,13 @@ bool DecodeNCCScript(const CScript& scriptIn, int& op, std::vector<std::vector<u
return true;
}
CScript StripNCCScriptPrefix(const CScript& scriptIn)
CScript StripClaimScriptPrefix(const CScript& scriptIn)
{
int op;
std::vector<std::vector<unsigned char> > vvchParams;
CScript::const_iterator pc = scriptIn.begin();
if (!DecodeNCCScript(scriptIn, op, vvchParams, pc))
if (!DecodeClaimScript(scriptIn, op, vvchParams, pc))
{
return scriptIn;
}

12
src/nameclaim.h Normal file
View file

@ -0,0 +1,12 @@
#ifndef BITCOIN_NAMECLAIM_H
#define BITCOIN_NAMECLAIM_H
#include "script/script.h"
#include <vector>
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams);
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams, CScript::const_iterator& pc);
CScript StripClaimScriptPrefix(const CScript& scriptIn);
#endif // BITCOIN_NAMECLAIM_H

View file

@ -1,12 +0,0 @@
#ifndef BITCOIN_NCC_H
#define BITCOIN_NCC_H
#include "script/script.h"
#include <vector>
bool DecodeNCCScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams);
bool DecodeNCCScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams, CScript::const_iterator& pc);
CScript StripNCCScriptPrefix(const CScript& scriptIn);
#endif // BITCOIN_NCC_H

View file

@ -112,12 +112,12 @@ uint256 CBlock::CheckMerkleBranch(uint256 hash, const std::vector<uint256>& vMer
std::string CBlock::ToString() const
{
std::stringstream s;
s << strprintf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, hashNCCTrie=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n",
s << strprintf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, hashClaimTrie=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n",
GetHash().ToString(),
nVersion,
hashPrevBlock.ToString(),
hashMerkleRoot.ToString(),
hashNCCTrie.ToString(),
hashClaimTrie.ToString(),
nTime, nBits, nNonce,
vtx.size());
for (unsigned int i = 0; i < vtx.size(); i++)

View file

@ -25,7 +25,7 @@ public:
int32_t nVersion;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
uint256 hashNCCTrie;
uint256 hashClaimTrie;
uint32_t nTime;
uint32_t nBits;
uint32_t nNonce;
@ -43,7 +43,7 @@ public:
nVersion = this->nVersion;
READWRITE(hashPrevBlock);
READWRITE(hashMerkleRoot);
READWRITE(hashNCCTrie);
READWRITE(hashClaimTrie);
READWRITE(nTime);
READWRITE(nBits);
READWRITE(nNonce);
@ -54,7 +54,7 @@ public:
nVersion = CBlockHeader::CURRENT_VERSION;
hashPrevBlock.SetNull();
hashMerkleRoot.SetNull();
hashNCCTrie.SetNull();
hashClaimTrie.SetNull();
nTime = 0;
nBits = 0;
nNonce = 0;
@ -115,7 +115,7 @@ public:
block.nVersion = nVersion;
block.hashPrevBlock = hashPrevBlock;
block.hashMerkleRoot = hashMerkleRoot;
block.hashNCCTrie = hashNCCTrie;
block.hashClaimTrie = hashClaimTrie;
block.nTime = nTime;
block.nBits = nBits;
block.nNonce = nNonce;

View file

@ -65,7 +65,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
result.push_back(Pair("height", blockindex->nHeight));
result.push_back(Pair("version", block.nVersion));
result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex()));
result.push_back(Pair("nccroot", block.hashNCCTrie.GetHex()));
result.push_back(Pair("nameclaimroot", block.hashClaimTrie.GetHex()));
UniValue txs(UniValue::VARR);
BOOST_FOREACH(const CTransaction&tx, block.vtx)
{
@ -279,7 +279,7 @@ UniValue getblock(const UniValue& params, bool fHelp)
" \"height\" : n, (numeric) The block height or index\n"
" \"version\" : n, (numeric) The block version\n"
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
" \"nccroot\" : \"xxxx\", (string) The hash of the root of the NCC trie\n"
" \"nameclaimroot\" : \"xxxx\", (string) The hash of the root of the name claim trie\n"
" \"tx\" : [ (array of string) The transaction ids\n"
" \"transactionid\" (string) The transaction id\n"
" ,...\n"

View file

@ -1,13 +1,13 @@
#include "main.h"
#include "ncc.h"
#include "nameclaim.h"
#include "rpcserver.h"
#include "univalue/univalue.h"
UniValue getnametrie(const UniValue& params, bool fHelp)
UniValue getclaimtrie(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() > 0)
throw std::runtime_error(
"getnametrie\n"
"getclaimtrie\n"
"Return the entire name trie.\n"
"Arguments:\n"
"None\n"
@ -25,7 +25,7 @@ UniValue getnametrie(const UniValue& params, bool fHelp)
LOCK(cs_main);
UniValue ret(UniValue::VARR);
std::vector<namedNodeType> nodes = pnccTrie->flattenTrie();
std::vector<namedNodeType> nodes = pclaimTrie->flattenTrie();
for (std::vector<namedNodeType>::iterator it = nodes.begin(); it != nodes.end(); ++it)
{
UniValue node(UniValue::VOBJ);
@ -64,7 +64,7 @@ UniValue gettxinfoforname(const UniValue& params, bool fHelp)
UniValue ret(UniValue::VOBJ);
CNodeValue val;
if (pnccTrie->getInfoForName(name, val))
if (pclaimTrie->getInfoForName(name, val))
{
ret.push_back(Pair("txid", val.txhash.GetHex()));
ret.push_back(Pair("n", (int)val.nOut));
@ -89,7 +89,7 @@ UniValue getvalueforname(const UniValue& params, bool fHelp)
std::string name = params[0].get_str();
CNodeValue val;
UniValue ret(UniValue::VOBJ);
if (!pnccTrie->getInfoForName(name, val))
if (!pclaimTrie->getInfoForName(name, val))
return ret;
CCoinsViewCache view(pcoinsTip);
const CCoins* coin = view.AccessCoins(val.txhash);
@ -107,9 +107,9 @@ UniValue getvalueforname(const UniValue& params, bool fHelp)
int op;
std::vector<std::vector<unsigned char> > vvchParams;
if (!DecodeNCCScript(coin->vout[val.nOut].scriptPubKey, op, vvchParams))
if (!DecodeClaimScript(coin->vout[val.nOut].scriptPubKey, op, vvchParams))
{
LogPrintf("%s: the specified txout of %s does not have an NCC command\n", __func__, val.txhash.GetHex());
LogPrintf("%s: the specified txout of %s does not have a name claim command\n", __func__, val.txhash.GetHex());
}
std::string sValue(vvchParams[1].begin(), vvchParams[1].end());
ret.push_back(Pair("value", sValue));
@ -129,11 +129,11 @@ UniValue gettotalclaimednames(const UniValue& params, bool fHelp)
" names in the trie\n"
);
LOCK(cs_main);
if (!pnccTrie)
if (!pclaimTrie)
{
return -1;
}
unsigned int num_names = pnccTrie->getTotalNamesInTrie();
unsigned int num_names = pclaimTrie->getTotalNamesInTrie();
return int(num_names);
}
@ -149,11 +149,11 @@ UniValue gettotalclaims(const UniValue& params, bool fHelp)
" of active claims\n"
);
LOCK(cs_main);
if (!pnccTrie)
if (!pclaimTrie)
{
return -1;
}
unsigned int num_claims = pnccTrie->getTotalClaimsInTrie();
unsigned int num_claims = pclaimTrie->getTotalClaimsInTrie();
return int(num_claims);
}
@ -171,14 +171,14 @@ UniValue gettotalvalueofclaims(const UniValue& params, bool fHelp)
" claims in the trie\n"
);
LOCK(cs_main);
if (!pnccTrie)
if (!pclaimTrie)
{
return -1;
}
bool controlling_only = false;
if (params.size() == 1)
controlling_only = params[0].get_bool();
CAmount total_amount = pnccTrie->getTotalValueOfClaimsInTrie(controlling_only);
CAmount total_amount = pclaimTrie->getTotalValueOfClaimsInTrie(controlling_only);
return ValueFromAmount(total_amount);
}

View file

@ -94,8 +94,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "prioritisetransaction", 1 },
{ "prioritisetransaction", 2 },
{ "claimname", 2},
{ "updatename", 2},
{ "abandonname", 2},
{ "updateclaim", 2},
{ "abandonclaim", 2},
{ "listnameclaims", 0},
{ "listnameclaims", 1},
{ "gettotalvalueofclaims", 0},

View file

@ -368,8 +368,8 @@ static const CRPCCommand vRPCCommands[] =
{ "wallet", "sendmany", &sendmany, false },
{ "wallet", "claimname", &claimname, false },
{ "wallet", "listnameclaims", &listnameclaims, false },
{ "wallet", "updatename", &updatename, false },
{ "wallet", "abandonname", &abandonname, false },
{ "wallet", "updateclaim", &updateclaim, false },
{ "wallet", "abandonclaim", &abandonclaim, false },
{ "wallet", "sendtoaddress", &sendtoaddress, false },
{ "wallet", "setaccount", &setaccount, true },
{ "wallet", "settxfee", &settxfee, true },
@ -379,13 +379,13 @@ static const CRPCCommand vRPCCommands[] =
{ "wallet", "walletpassphrase", &walletpassphrase, true },
#endif // ENABLE_WALLET
/* NCC trie */
{ "nametrie", "getnametrie", &getnametrie, true },
{ "nametrie", "gettxinfoforname", &gettxinfoforname, true },
{ "nametrie", "getvalueforname", &getvalueforname, true },
{ "nametrie", "gettotalclaimednames", &gettotalclaimednames, true },
{ "nametrie", "gettotalclaims", &gettotalclaims, true },
{ "nametrie", "gettotalvalueofclaims", &gettotalvalueofclaims, true },
/* Claim trie */
{ "claimtrie", "getclaimtrie", &getclaimtrie, true },
{ "claimtrie", "gettxinfoforname", &gettxinfoforname, true },
{ "claimtrie", "getvalueforname", &getvalueforname, true },
{ "claimtrie", "gettotalclaimednames", &gettotalclaimednames, true },
{ "claimtrie", "gettotalclaims", &gettotalclaims, true },
{ "claimtrie", "gettotalvalueofclaims", &gettotalvalueofclaims, true },
};
CRPCTable::CRPCTable()
@ -1043,7 +1043,7 @@ std::string HelpExampleCli(const std::string& methodname, const std::string& arg
std::string HelpExampleRpc(const std::string& methodname, const std::string& args)
{
return "> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", "
"\"method\": \"" + methodname + "\", \"params\": [" + args + "] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n";
"\"method\": \"" + methodname + "\", \"params\": [" + args + "] }' -H 'content-type: text/plain;' http://127.0.0.1:9245/\n";
}
const CRPCTable tableRPC;

View file

@ -179,8 +179,8 @@ extern UniValue getaccount(const UniValue& params, bool fHelp);
extern UniValue getaddressesbyaccount(const UniValue& params, bool fHelp);
extern UniValue claimname(const UniValue& params, bool fHelp);
extern UniValue listnameclaims(const UniValue& params, bool fHelp);
extern UniValue updatename(const UniValue& params, bool fHelp);
extern UniValue abandonname(const UniValue& params, bool fHelp);
extern UniValue updateclaim(const UniValue& params, bool fHelp);
extern UniValue abandonclaim(const UniValue& params, bool fHelp);
extern UniValue sendtoaddress(const UniValue& params, bool fHelp);
extern UniValue signmessage(const UniValue& params, bool fHelp);
extern UniValue verifymessage(const UniValue& params, bool fHelp);
@ -241,7 +241,7 @@ extern UniValue getchaintips(const UniValue& params, bool fHelp);
extern UniValue invalidateblock(const UniValue& params, bool fHelp);
extern UniValue reconsiderblock(const UniValue& params, bool fHelp);
extern UniValue getnametrie(const UniValue& params, bool fHelp); // in rpcncctrie.cpp
extern UniValue getclaimtrie(const UniValue& params, bool fHelp); // in rpcclaimtrie.cpp
extern UniValue gettxinfoforname(const UniValue& params, bool fHelp);
extern UniValue getvalueforname(const UniValue& params, bool fHelp);
extern UniValue gettotalclaimednames(const UniValue& params, bool fHelp);

View file

@ -10,7 +10,7 @@
#include "keystore.h"
#include "script/standard.h"
#include "uint256.h"
#include "ncc.h"
#include "nameclaim.h"
#include <boost/foreach.hpp>
using namespace std;
@ -66,7 +66,7 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP
{
scriptSigRet.clear();
const CScript& strippedScriptPubKey = StripNCCScriptPrefix(scriptPubKey);
const CScript& strippedScriptPubKey = StripClaimScriptPrefix(scriptPubKey);
vector<valtype> vSolutions;
if (!Solver(strippedScriptPubKey, whichTypeRet, vSolutions))

View file

@ -6,7 +6,7 @@
#include "consensus/validation.h"
#include "primitives/transaction.h"
#include "miner.h"
#include "ncctrie.h"
#include "claimtrie.h"
#include "coins.h"
#include "streams.h"
#include <boost/test/unit_test.hpp>
@ -145,7 +145,7 @@ const unsigned int expire_nonces[] = {
};
const unsigned int support_nonces[] = {};
BOOST_FIXTURE_TEST_SUITE(ncctrie_tests, TestingSetup)
BOOST_FIXTURE_TEST_SUITE(claimtrie_tests, TestingSetup)
CMutableTransaction BuildTransaction(const uint256& prevhash)
{
@ -264,7 +264,7 @@ bool RemoveBlock(uint256& blockhash)
}
BOOST_AUTO_TEST_CASE(ncctrie_merkle_hash)
BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
{
int unused;
uint256 hash0(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
@ -287,13 +287,13 @@ BOOST_AUTO_TEST_CASE(ncctrie_merkle_hash)
uint256 hash4;
hash4.SetHex("6ec84089eb4ca1aeead6cf3538d4def78baebb44715c31be8790e627e0dcbc28");
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pclaimTrie->empty());
CNCCTrieCache ntState(pnccTrie);
CClaimTrieCache ntState(pclaimTrie);
ntState.insertClaimIntoTrie(std::string("test"), CNodeValue(tx1.GetHash(), 0, 50, 100, 200));
ntState.insertClaimIntoTrie(std::string("test2"), CNodeValue(tx2.GetHash(), 0, 50, 100, 200));
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!ntState.empty());
BOOST_CHECK(ntState.getMerkleHash() == hash1);
@ -306,11 +306,11 @@ BOOST_AUTO_TEST_CASE(ncctrie_merkle_hash)
BOOST_CHECK(ntState.getMerkleHash() == hash2);
ntState.flush();
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->getMerkleHash() == hash2);
BOOST_CHECK(pnccTrie->checkConsistency());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
BOOST_CHECK(pclaimTrie->checkConsistency());
CNCCTrieCache ntState1(pnccTrie);
CClaimTrieCache ntState1(pclaimTrie);
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);
@ -318,7 +318,7 @@ BOOST_AUTO_TEST_CASE(ncctrie_merkle_hash)
BOOST_CHECK(ntState1.getMerkleHash() == hash0);
CNCCTrieCache ntState2(pnccTrie);
CClaimTrieCache ntState2(pclaimTrie);
ntState2.insertClaimIntoTrie(std::string("abab"), CNodeValue(tx6.GetHash(), 0, 50, 100, 200));
ntState2.removeClaimFromTrie(std::string("test"), tx1.GetHash(), 0, unused);
@ -326,45 +326,45 @@ BOOST_AUTO_TEST_CASE(ncctrie_merkle_hash)
ntState2.flush();
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->getMerkleHash() == hash3);
BOOST_CHECK(pnccTrie->checkConsistency());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash3);
BOOST_CHECK(pclaimTrie->checkConsistency());
CNCCTrieCache ntState3(pnccTrie);
CClaimTrieCache ntState3(pclaimTrie);
ntState3.insertClaimIntoTrie(std::string("test"), CNodeValue(tx1.GetHash(), 0, 50, 100, 200));
BOOST_CHECK(ntState3.getMerkleHash() == hash4);
ntState3.flush();
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->getMerkleHash() == hash4);
BOOST_CHECK(pnccTrie->checkConsistency());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash4);
BOOST_CHECK(pclaimTrie->checkConsistency());
CNCCTrieCache ntState4(pnccTrie);
CClaimTrieCache ntState4(pclaimTrie);
ntState4.removeClaimFromTrie(std::string("abab"), tx6.GetHash(), 0, unused);
BOOST_CHECK(ntState4.getMerkleHash() == hash2);
ntState4.flush();
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->getMerkleHash() == hash2);
BOOST_CHECK(pnccTrie->checkConsistency());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
BOOST_CHECK(pclaimTrie->checkConsistency());
CNCCTrieCache ntState5(pnccTrie);
CClaimTrieCache ntState5(pclaimTrie);
ntState5.removeClaimFromTrie(std::string("test"), tx3.GetHash(), 0, unused);
BOOST_CHECK(ntState5.getMerkleHash() == hash2);
ntState5.flush();
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->getMerkleHash() == hash2);
BOOST_CHECK(pnccTrie->checkConsistency());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
BOOST_CHECK(pclaimTrie->checkConsistency());
CNCCTrieCache ntState6(pnccTrie);
CClaimTrieCache ntState6(pclaimTrie);
ntState6.insertClaimIntoTrie(std::string("test"), CNodeValue(tx3.GetHash(), 0, 50, 101, 201));
BOOST_CHECK(ntState6.getMerkleHash() == hash2);
ntState6.flush();
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->getMerkleHash() == hash2);
BOOST_CHECK(pnccTrie->checkConsistency());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
BOOST_CHECK(pclaimTrie->checkConsistency());
CNCCTrieCache ntState7(pnccTrie);
CClaimTrieCache ntState7(pclaimTrie);
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);
@ -372,17 +372,17 @@ BOOST_AUTO_TEST_CASE(ncctrie_merkle_hash)
BOOST_CHECK(ntState7.getMerkleHash() == hash0);
ntState7.flush();
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->getMerkleHash() == hash0);
BOOST_CHECK(pnccTrie->checkConsistency());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash0);
BOOST_CHECK(pclaimTrie->checkConsistency());
}
BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
{
int block_counter = 0;
//CNoncePrinter noncePrinter;
CNoncePrinter* pnp = NULL;//&noncePrinter;
BOOST_CHECK(pnccTrie->nCurrentHeight == chainActive.Height() + 1);
BOOST_CHECK(pclaimTrie->nCurrentHeight == chainActive.Height() + 1);
CBlockTemplate *pblocktemplate;
LOCK(cs_main);
@ -415,7 +415,7 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
delete pblocktemplate;
uint256 hash0(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
BOOST_CHECK(pnccTrie->getMerkleHash() == hash0);
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash0);
CMutableTransaction tx1 = BuildTransaction(coinbases[0]);
tx1.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE;
@ -463,8 +463,8 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
}
delete pblocktemplate;
BOOST_CHECK(!pnccTrie->getInfoForName(sName1, val));
BOOST_CHECK(!pnccTrie->getInfoForName(sName2, val));
BOOST_CHECK(!pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(!pclaimTrie->getInfoForName(sName2, val));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
@ -473,15 +473,15 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
// Verify tx1 and tx2 are in the trie
BOOST_CHECK(pnccTrie->getInfoForName(sName1, val));
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(pnccTrie->getInfoForName(sName2, val));
BOOST_CHECK(pclaimTrie->getInfoForName(sName2, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
// Verify tx7 is also in the trie
BOOST_CHECK(pnccTrie->haveClaim(sName1, tx7.GetHash(), 0));
BOOST_CHECK(pclaimTrie->haveClaim(sName1, tx7.GetHash(), 0));
// Spend tx1 with tx3, tx2 with tx4, and put in tx5.
@ -498,30 +498,30 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
// Verify tx1, tx2, and tx5 are not in the trie, but tx3 is in the trie.
BOOST_CHECK(pnccTrie->getInfoForName(sName1, val));
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx3.GetHash());
BOOST_CHECK(!pnccTrie->getInfoForName(sName2, val));
BOOST_CHECK(!pclaimTrie->getInfoForName(sName2, val));
// Roll back the last block, make sure tx1 and tx2 are put back in the trie
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pnccTrie->getInfoForName(sName1, val));
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
BOOST_CHECK(pnccTrie->getInfoForName(sName2, val));
BOOST_CHECK(pclaimTrie->getInfoForName(sName2, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
// Roll all the way back, make sure all txs are out of the trie
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pnccTrie->getInfoForName(sName1, val));
BOOST_CHECK(!pnccTrie->getInfoForName(sName2, val));
BOOST_CHECK(!pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(!pclaimTrie->getInfoForName(sName2, val));
mempool.clear();
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->getMerkleHash() == hash0);
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash0);
BOOST_CHECK(pclaimTrie->queueEmpty());
// Test undoing a claim before the claim gets into the trie
@ -541,8 +541,8 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
// Make sure it's not in the queue
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
mempool.clear();
// Test undoing a claim that has gotten into the trie
@ -558,8 +558,8 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
@ -569,25 +569,25 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
}
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, insert_nonces[block_counter++]));
delete pblocktemplate;
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pnccTrie->getInfoForName(sName1, val));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
// Remove it from the trie
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
mempool.clear();
// Test undoing a spend which involves a claim just inserted into the queue
@ -604,13 +604,13 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
mempool.clear();
// Test undoing a spend which involves a claim inserted into the queue by a previous block
@ -625,8 +625,8 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, insert_nonces[block_counter++]));
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
@ -635,8 +635,8 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, insert_nonces[block_counter++]));
}
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
// Spend tx2 with tx4, and then advance to where tx2 would be inserted into the trie and verify it hasn't happened
@ -648,8 +648,8 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, insert_nonces[block_counter++]));
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
@ -658,15 +658,15 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, insert_nonces[block_counter++]));
}
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
// Undo spending tx2 with tx4, and then advance and verify tx2 is inserted into the trie when it should be
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
mempool.clear();
@ -678,16 +678,16 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
}
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, insert_nonces[block_counter++]));
delete pblocktemplate;
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pnccTrie->getInfoForName(sName2, val));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName2, val));
BOOST_CHECK(val.txhash == tx2.GetHash());
// Test undoing a spend which involves a claim in the trie
@ -703,23 +703,23 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
// undo spending tx2 with tx4, and verify tx2 is back in the trie
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
mempool.clear();
// roll back to the beginning
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
mempool.clear();
// Test undoing a spent update which updated a claim still in the queue
@ -735,8 +735,8 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
// move forward some, but not far enough for the claim to get into the trie
@ -747,8 +747,8 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, insert_nonces[block_counter++]));
}
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
// update the original claim (tx3 spends tx1)
@ -761,8 +761,8 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
// spend the update (tx6 spends tx3)
@ -775,15 +775,15 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
// undo spending the update (undo tx6 spending tx3)
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
mempool.clear();
// make sure the update (tx3) still goes into effect in 100 blocks
@ -796,23 +796,23 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
}
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, insert_nonces[block_counter++]));
delete pblocktemplate;
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
// undo updating the original claim (tx3 spends tx1)
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
mempool.clear();
// Test undoing an spent update which updated the best claim to a name
@ -827,17 +827,17 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
}
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, insert_nonces[block_counter++]));
delete pblocktemplate;
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pnccTrie->getInfoForName(sName1, val));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx1.GetHash());
// update the original claim (tx3 spends tx1)
@ -850,9 +850,9 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, insert_nonces[block_counter++]));
delete pblocktemplate;
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pnccTrie->getInfoForName(sName1, val));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx3.GetHash());
// spend the update (tx6 spends tx3)
@ -866,33 +866,33 @@ BOOST_AUTO_TEST_CASE(ncctrie_insert_update_claim)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
// undo spending the update (undo tx6 spending tx3)
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pnccTrie->getInfoForName(sName1, val));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.txhash == tx3.GetHash());
// roll all the way back
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
//noncePrinter.printNonces();
}
BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
BOOST_AUTO_TEST_CASE(claimtrie_claim_expiration)
{
int block_counter = 0;
//CNoncePrinter noncePrinter;
CNoncePrinter* pnp = NULL;//&noncePrinter;
BOOST_CHECK(pnccTrie->nCurrentHeight == chainActive.Height() + 1);
BOOST_CHECK(pclaimTrie->nCurrentHeight == chainActive.Height() + 1);
CBlockTemplate *pblocktemplate;
LOCK(cs_main);
@ -925,7 +925,7 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
std::vector<uint256> blocks_to_invalidate;
// set expiration time to 100 blocks after the block becomes valid. (more correctly, 200 blocks after the block is created)
pnccTrie->setExpirationTime(200);
pclaimTrie->setExpirationTime(200);
// create a claim. verify no expiration event has been scheduled.
@ -938,9 +938,9 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(!pnccTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// advance until the claim is valid. verify the expiration event is scheduled.
@ -952,16 +952,16 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
}
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, expire_nonces[block_counter++]));
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(!pnccTrie->expirationQueueEmpty());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// advance until the expiration event occurs. verify the expiration event occurs on time.
@ -973,9 +973,9 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
}
delete pblocktemplate;
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(!pnccTrie->expirationQueueEmpty());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
@ -983,9 +983,9 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pnccTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->expirationQueueEmpty());
// roll forward a bit and then roll back to before the expiration event. verify the claim is reinserted. verify the expiration event is scheduled again.
@ -997,15 +997,15 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
}
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pnccTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->expirationQueueEmpty());
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(!pnccTrie->expirationQueueEmpty());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// advance until the expiration event occurs. verify the expiration event occurs on time.
@ -1015,25 +1015,25 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pnccTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->expirationQueueEmpty());
// roll back to before the expiration event. verify the claim is reinserted. verify the expiration event is scheduled again.
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(!pnccTrie->expirationQueueEmpty());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// roll back to before the claim is valid. verify the claim is removed but the expiration event still exists.
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(!pnccTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// advance until the claim is valid again. verify the expiration event is scheduled.
@ -1043,9 +1043,9 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(!pnccTrie->expirationQueueEmpty());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// advance until the expiration event occurs. verify the expiration event occurs on time.
@ -1059,9 +1059,9 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
}
delete pblocktemplate;
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(!pnccTrie->expirationQueueEmpty());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
@ -1069,25 +1069,25 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pnccTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->expirationQueueEmpty());
// roll back to before the expiration event. verify the expiration event is scheduled.
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(!pnccTrie->expirationQueueEmpty());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// roll back some.
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(!pnccTrie->expirationQueueEmpty());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// spend the claim. verify the expiration event is removed.
@ -1100,17 +1100,17 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pnccTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->expirationQueueEmpty());
// roll back the spend. verify the expiration event is returned.
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(!pnccTrie->expirationQueueEmpty());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
mempool.clear();
@ -1124,9 +1124,9 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
}
delete pblocktemplate;
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(!pnccTrie->expirationQueueEmpty());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
@ -1134,9 +1134,9 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pnccTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->expirationQueueEmpty());
// spend the expired claim
@ -1149,17 +1149,17 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pnccTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->expirationQueueEmpty());
// undo the spend. verify everything remains empty.
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pnccTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->expirationQueueEmpty());
mempool.clear();
@ -1167,9 +1167,9 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(!pnccTrie->expirationQueueEmpty());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// verify the expiration event happens at the right time again
@ -1179,45 +1179,45 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration)
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
delete pblocktemplate;
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pnccTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->expirationQueueEmpty());
// roll back to before the expiration event. verify it gets reinserted and expiration gets scheduled.
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(!pnccTrie->expirationQueueEmpty());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// roll back to before the claim is valid. verify the claim is removed but the expiration event is not.
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(!pnccTrie->queueEmpty());
BOOST_CHECK(!pnccTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// roll all the way back
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pnccTrie->empty());
BOOST_CHECK(pnccTrie->queueEmpty());
BOOST_CHECK(pnccTrie->expirationQueueEmpty());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->expirationQueueEmpty());
BOOST_CHECK(blocks_to_invalidate.empty());
//noncePrinter.printNonces();
}
BOOST_AUTO_TEST_CASE(ncctrie_supporting_claims)
BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
{
int block_counter = 0;
CNoncePrinter noncePrinter;
CNoncePrinter* pnp = &noncePrinter;
BOOST_CHECK(pnccTrie->nCurrentHeight == chainActive.Height() + 1);
BOOST_CHECK(pclaimTrie->nCurrentHeight == chainActive.Height() + 1);
CBlockTemplate *pblocktemplate;
LOCK(cs_main);
@ -1279,12 +1279,12 @@ BOOST_AUTO_TEST_CASE(ncctrie_supporting_claims)
// Verify name trie is empty
}
BOOST_AUTO_TEST_CASE(ncctrienode_serialize_unserialize)
BOOST_AUTO_TEST_CASE(claimtrienode_serialize_unserialize)
{
CDataStream ss(SER_DISK, 0);
CNCCTrieNode n1;
CNCCTrieNode n2;
CClaimTrieNode n1;
CClaimTrieNode n2;
CNodeValue throwaway;
ss << n1;

View file

@ -951,13 +951,13 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
BOOST_CHECK(combined == partial3c);
}
BOOST_AUTO_TEST_CASE(script_nccScript)
BOOST_AUTO_TEST_CASE(script_claimScript)
{
// Test the NCC scripts
// Test the claim scripts
// Outline:
// Spend normal tx to make NCC claim
// Spend NCC claim to update NCC claim
// Spend NCC updated claim to abandon name
// Spend normal tx to make claim
// Spend claim to update claim
// Spend updated claim to abandon name
CBasicKeyStore keystore;
vector<CKey> keys;
vector<CPubKey> pubkeys;
@ -977,21 +977,21 @@ BOOST_AUTO_TEST_CASE(script_nccScript)
CMutableTransaction txOrig = BuildCreditingTransaction(GetScriptForDestination(keys[0].GetPubKey().GetID()));
CMutableTransaction txNCC0 = BuildSpendingTransaction(CScript(), txOrig);
CScript txNCCOut0 = CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP;
txNCCOut0 = txNCCOut0 + GetScriptForDestination(keys[1].GetPubKey().GetID());
txNCC0.vout[0].scriptPubKey = txNCCOut0;
SignSignature(keystore, txOrig, txNCC0, 0);
CMutableTransaction txClaim0 = BuildSpendingTransaction(CScript(), txOrig);
CScript txClaimOut0 = CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP;
txClaimOut0 = txClaimOut0 + GetScriptForDestination(keys[1].GetPubKey().GetID());
txClaim0.vout[0].scriptPubKey = txClaimOut0;
SignSignature(keystore, txOrig, txClaim0, 0);
CMutableTransaction txNCC1 = BuildSpendingTransaction(CScript(), txNCC0);
CScript txNCCOut1 = CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP;
txNCCOut1 = txNCCOut1 + GetScriptForDestination(keys[2].GetPubKey().GetID());
txNCC1.vout[0].scriptPubKey = txNCCOut1;
SignSignature(keystore, txNCC0, txNCC1, 0);
CMutableTransaction txClaim1 = BuildSpendingTransaction(CScript(), txClaim0);
CScript txClaimOut1 = CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP;
txClaimOut1 = txClaimOut1 + GetScriptForDestination(keys[2].GetPubKey().GetID());
txClaim1.vout[0].scriptPubKey = txClaimOut1;
SignSignature(keystore, txClaim0, txClaim1, 0);
CMutableTransaction txFinal = BuildSpendingTransaction(CScript(), txNCC1);
CMutableTransaction txFinal = BuildSpendingTransaction(CScript(), txClaim1);
txFinal.vout[0].scriptPubKey = GetScriptForDestination(keys[3].GetPubKey().GetID());
SignSignature(keystore, txNCC1, txFinal, 0);
SignSignature(keystore, txClaim1, txFinal, 0);
}
BOOST_AUTO_TEST_CASE(script_standard_push)

View file

@ -52,7 +52,7 @@ TestingSetup::TestingSetup()
pblocktree = new CBlockTreeDB(1 << 20, true);
pcoinsdbview = new CCoinsViewDB(1 << 23, true);
pcoinsTip = new CCoinsViewCache(pcoinsdbview);
pnccTrie = new CNCCTrie(true);
pclaimTrie = new CClaimTrie(true);
InitBlockIndex();
#ifdef ENABLE_WALLET
bool fFirstRun;
@ -77,7 +77,7 @@ TestingSetup::~TestingSetup()
pwalletMain = NULL;
#endif
UnloadBlockIndex();
delete pnccTrie;
delete pclaimTrie;
delete pcoinsTip;
delete pcoinsdbview;
delete pblocktree;

View file

@ -375,7 +375,7 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
t.vout[1].scriptPubKey = CScript() << OP_RETURN;
BOOST_CHECK(!IsStandardTx(t, reason));
// NCC transactions
// Name claim transactions
t.vout.resize(1);
string sName = "testname";

View file

@ -219,7 +219,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
pindexNew->nUndoPos = diskindex.nUndoPos;
pindexNew->nVersion = diskindex.nVersion;
pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
pindexNew->hashNCCTrie = diskindex.hashNCCTrie;
pindexNew->hashClaimTrie = diskindex.hashClaimTrie;
pindexNew->nTime = diskindex.nTime;
pindexNew->nBits = diskindex.nBits;
pindexNew->nNonce = diskindex.nNonce;

View file

@ -7,7 +7,7 @@
#define BITCOIN_UNDO_H
#include "compressor.h"
#include "ncctrie.h"
#include "claimtrie.h"
#include "primitives/transaction.h"
#include "serialize.h"
@ -25,16 +25,16 @@ public:
bool fCoinBase; // if the outpoint was the last unspent: whether it belonged to a coinbase
unsigned int nHeight; // if the outpoint was the last unspent: its height
int nVersion; // if the outpoint was the last unspent: its version
unsigned int nNCCValidHeight; // If the outpoint was an NCC claim, the height at which the claim should be inserted into the trie
unsigned int nClaimValidHeight; // If the outpoint was a name claim, the height at which the claim should be inserted into the trie
CTxInUndo() : txout(), fLastUnspent(false), fCoinBase(false), nHeight(0), nVersion(0), nNCCValidHeight(0) {}
CTxInUndo(const CTxOut &txoutIn, bool fLastUnspent = false, bool fCoinBaseIn = false, unsigned int nHeightIn = 0, int nVersionIn = 0, unsigned int nNCCValidHeight = 0) : txout(txoutIn), fLastUnspent(fLastUnspent), fCoinBase(fCoinBaseIn), nHeight(nHeightIn), nVersion(nVersionIn), nNCCValidHeight(nNCCValidHeight) { }
CTxInUndo() : txout(), fLastUnspent(false), fCoinBase(false), nHeight(0), nVersion(0), nClaimValidHeight(0) {}
CTxInUndo(const CTxOut &txoutIn, bool fLastUnspent = false, bool fCoinBaseIn = false, unsigned int nHeightIn = 0, int nVersionIn = 0, unsigned int nClaimValidHeight = 0) : txout(txoutIn), fLastUnspent(fLastUnspent), fCoinBase(fCoinBaseIn), nHeight(nHeightIn), nVersion(nVersionIn), nClaimValidHeight(nClaimValidHeight) { }
unsigned int GetSerializeSize(int nType, int nVersion) const {
return ::GetSerializeSize(VARINT(nHeight*4+(fCoinBase ? 2 : 0)+(fLastUnspent ? 1: 0)), nType, nVersion) +
(fLastUnspent ? ::GetSerializeSize(VARINT(this->nVersion), nType, nVersion) : 0) +
::GetSerializeSize(CTxOutCompressor(REF(txout)), nType, nVersion) +
::GetSerializeSize(VARINT(nNCCValidHeight), nType, nVersion);
::GetSerializeSize(VARINT(nClaimValidHeight), nType, nVersion);
}
template<typename Stream>
@ -43,7 +43,7 @@ public:
if (fLastUnspent)
::Serialize(s, VARINT(this->nVersion), nType, nVersion);
::Serialize(s, CTxOutCompressor(REF(txout)), nType, nVersion);
::Serialize(s, VARINT(nNCCValidHeight), nType, nVersion);
::Serialize(s, VARINT(nClaimValidHeight), nType, nVersion);
}
template<typename Stream>
@ -56,7 +56,7 @@ public:
if (fLastUnspent)
::Unserialize(s, VARINT(this->nVersion), nType, nVersion);
::Unserialize(s, REF(CTxOutCompressor(REF(txout))), nType, nVersion);
::Unserialize(s, VARINT(nNCCValidHeight), nType, nVersion);
::Unserialize(s, VARINT(nClaimValidHeight), nType, nVersion);
}
};
@ -80,8 +80,8 @@ class CBlockUndo
{
public:
std::vector<CTxUndo> vtxundo; // for all but the coinbase
CNCCTrieQueueUndo insertUndo; // any claims that went from the queue to the trie
CNCCTrieQueueUndo expireUndo; // any claims that expired
CClaimTrieQueueUndo insertUndo; // any claims that went from the queue to the trie
CClaimTrieQueueUndo expireUndo; // any claims that expired
ADD_SERIALIZE_METHODS;

View file

@ -16,7 +16,7 @@
#include "utilmoneystr.h"
#include "wallet.h"
#include "walletdb.h"
#include "ncc.h"
#include "nameclaim.h"
#include <stdint.h>
@ -471,14 +471,14 @@ void UpdateName(const std::vector<unsigned char> vchName, const std::vector<unsi
}
UniValue updatename(const UniValue& params, bool fHelp)
UniValue updateclaim(const UniValue& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() != 3)
throw runtime_error(
"updatename \"txid\" \"value\" amount\n"
"updateclaim \"txid\" \"value\" amount\n"
"Create a transaction which issues a claim assigning a value to a name, spending the previous txout which issued a claim over the same name and therefore superseding that claim. The claim will be authoritative if the transaction amount is greater than the transaction amount of all other unspent transactions which issue a claim over the same name, and it will remain authoritative as long as it remains unspent and there are no greater unspent transactions issuing a claim over the same name.\n"
+ HelpRequiringPassphrase() +
"\nArguments:\n"
@ -497,7 +497,7 @@ UniValue updatename(const UniValue& params, bool fHelp)
std::vector<unsigned char> vchValue (sValue.begin(), sValue.end());
CAmount nAmount = AmountFromValue(params[2]);
isminefilter filter = ISMINE_NCC;
isminefilter filter = ISMINE_CLAIM;
UniValue entry;
if (!pwalletMain->mapWallet.count(hash))
@ -512,7 +512,7 @@ UniValue updatename(const UniValue& params, bool fHelp)
{
if ((filter & pwalletMain->IsMine(wtx.vout[i])))
{
if (DecodeNCCScript(wtx.vout[i].scriptPubKey, op, vvchParams))
if (DecodeClaimScript(wtx.vout[i].scriptPubKey, op, vvchParams))
{
vchName = vvchParams[0];
EnsureWalletIsUnlocked();
@ -522,7 +522,7 @@ UniValue updatename(const UniValue& params, bool fHelp)
}
}
if (!fFound)
throw runtime_error("Error: The given transaction contains no NCC scripts owned by this wallet");
throw runtime_error("Error: The given transaction contains no claim scripts owned by this wallet");
return wtxNew.GetHash().GetHex();
}
@ -565,14 +565,14 @@ void AbandonName(const CTxDestination &address, CAmount nAmount, CWalletTx& wtxN
throw JSONRPCError(RPC_WALLET_ERROR, "Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of a wallet.dat and coins were spent in the copy but not marked as spent here.");
}
UniValue abandonname(const UniValue& params, bool fHelp)
UniValue abandonclaim(const UniValue& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() != 3)
throw runtime_error(
"abandonname \"txid\" \"lbrycrdaddress\" \"amount\"\n"
"abandonclaim \"txid\" \"lbrycrdaddress\" \"amount\"\n"
"Create a transaction which spends a txout which assigned a value to a name, effectively abandoning that claim.\n"
+ HelpRequiringPassphrase() +
"\nArguments:\n"
@ -592,7 +592,7 @@ UniValue abandonname(const UniValue& params, bool fHelp)
CAmount nAmount = AmountFromValue(params[2]);
isminefilter filter = ISMINE_NCC;
isminefilter filter = ISMINE_CLAIM;
UniValue entry;
if (!pwalletMain->mapWallet.count(hash))
@ -607,7 +607,7 @@ UniValue abandonname(const UniValue& params, bool fHelp)
{
if ((filter & pwalletMain->IsMine(wtx.vout[i])))
{
if (DecodeNCCScript(wtx.vout[i].scriptPubKey, op, vvchParams))
if (DecodeClaimScript(wtx.vout[i].scriptPubKey, op, vvchParams))
{
EnsureWalletIsUnlocked();
AbandonName(address.Get(), nAmount, wtxNew, wtx, i);
@ -616,7 +616,7 @@ UniValue abandonname(const UniValue& params, bool fHelp)
}
}
if (!fFound)
throw runtime_error("Error: The given transaction contains no NCC scripts owned by this wallet");
throw runtime_error("Error: The given transaction contains no claim scripts owned by this wallet");
return wtxNew.GetHash().GetHex();
}
@ -646,9 +646,9 @@ void ListNameClaims(const CWalletTx& wtx, const string& strAccount, int nMinDept
const CScript& scriptPubKey = wtx.vout[s.vout].scriptPubKey;
int op;
vector<vector<unsigned char> > vvchParams;
if (!DecodeNCCScript(scriptPubKey, op, vvchParams))
if (!DecodeClaimScript(scriptPubKey, op, vvchParams))
{
LogPrintf("ListNameClaims(): Txout classified as NCC could not be decoded. Txid: %s", wtx.GetHash().ToString());
LogPrintf("ListNameClaims(): Txout classified as name claim could not be decoded. Txid: %s", wtx.GetHash().ToString());
continue;
}
else if (vvchParams.size() != 2)
@ -674,11 +674,11 @@ void ListNameClaims(const CWalletTx& wtx, const string& strAccount, int nMinDept
if (pindex)
{
entry.push_back(Pair("height", pindex->nHeight));
entry.push_back(Pair("expiration height", pindex->nHeight + pnccTrie->nExpirationTime));
if (pindex->nHeight + pnccTrie->nExpirationTime > chainActive.Height())
entry.push_back(Pair("expiration height", pindex->nHeight + pclaimTrie->nExpirationTime));
if (pindex->nHeight + pclaimTrie->nExpirationTime > chainActive.Height())
{
entry.push_back(Pair("expired", false));
entry.push_back(Pair("blocks to expiration", pindex->nHeight + pnccTrie->nExpirationTime - chainActive.Height()));
entry.push_back(Pair("blocks to expiration", pindex->nHeight + pclaimTrie->nExpirationTime - chainActive.Height()));
}
else
{
@ -688,13 +688,13 @@ void ListNameClaims(const CWalletTx& wtx, const string& strAccount, int nMinDept
}
entry.push_back(Pair("confirmations", wtx.GetDepthInMainChain()));
entry.push_back(Pair("is spent", pwalletMain->IsSpent(wtx.GetHash(), s.vout)));
entry.push_back(Pair("is in name trie", pnccTrie->haveClaim(sName, wtx.GetHash(), s.vout)));
entry.push_back(Pair("is in name trie", pclaimTrie->haveClaim(sName, wtx.GetHash(), s.vout)));
ret.push_back(entry);
}
}
}
}
UniValue listnameclaims(const UniValue& params, bool fHelp)
@ -739,7 +739,7 @@ UniValue listnameclaims(const UniValue& params, bool fHelp)
bool fListSpent = true;
if (params.size() > 0)
fListSpent = !params[0].get_bool();
isminefilter ncc_filter = ISMINE_NCC;
isminefilter claim_filter = ISMINE_CLAIM;
// Minimum confirmations
int nMinDepth = 1;
@ -755,7 +755,7 @@ UniValue listnameclaims(const UniValue& params, bool fHelp)
{
CWalletTx *const pwtx = (*it).second.first;
if (pwtx != 0 && pwtx->GetDepthInMainChain() >= nMinDepth)
ListNameClaims(*pwtx, strAccount, 0, ret, ncc_filter, fListSpent);
ListNameClaims(*pwtx, strAccount, 0, ret, claim_filter, fListSpent);
}
vector<UniValue> arrTmp = ret.getValues();

View file

@ -17,7 +17,7 @@
#include "timedata.h"
#include "util.h"
#include "utilmoneystr.h"
#include "ncc.h"
#include "nameclaim.h"
#include <assert.h>
@ -834,7 +834,7 @@ bool CWallet::IsChange(const CTxOut& txout) const
{
CTxDestination address;
const CScript& scriptPubKey = StripNCCScriptPrefix(txout.scriptPubKey);
const CScript& scriptPubKey = StripClaimScriptPrefix(txout.scriptPubKey);
if (!ExtractDestination(scriptPubKey, address))
return true;
@ -982,7 +982,7 @@ void CWalletTx::GetAmounts(list<COutputEntry>& listReceived,
// In either case, we need to get the destination address
CTxDestination address;
const CScript& scriptPubKey = StripNCCScriptPrefix(txout.scriptPubKey);
const CScript& scriptPubKey = StripClaimScriptPrefix(txout.scriptPubKey);
if (!ExtractDestination(scriptPubKey, address))
{
LogPrintf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
@ -993,7 +993,7 @@ void CWalletTx::GetAmounts(list<COutputEntry>& listReceived,
COutputEntry output = {address, txout.nValue, (int)i};
// If we are debited by the transaction, add the output as a "sent" entry
if (nDebit > 0 || filter == ISMINE_NCC)
if (nDebit > 0 || filter == ISMINE_CLAIM)
listSent.push_back(output);
// If we are receiving the output, add it as a "received" entry

View file

@ -9,7 +9,7 @@
#include "keystore.h"
#include "script/script.h"
#include "script/standard.h"
#include "ncc.h"
#include "nameclaim.h"
#include <boost/foreach.hpp>
@ -41,10 +41,10 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey)
txnouttype whichType;
isminetype spendable_type = ISMINE_SPENDABLE;
CScript strippedScriptPubKey = StripNCCScriptPrefix(scriptPubKey);
CScript strippedScriptPubKey = StripClaimScriptPrefix(scriptPubKey);
if (strippedScriptPubKey != scriptPubKey)
{
spendable_type = ISMINE_NCC;
spendable_type = ISMINE_CLAIM;
}

View file

@ -18,8 +18,8 @@ enum isminetype
ISMINE_NO = 0,
ISMINE_WATCH_ONLY = 1,
ISMINE_SPENDABLE = 2,
ISMINE_NCC = 4,
ISMINE_ALL = ISMINE_WATCH_ONLY | ISMINE_SPENDABLE | ISMINE_NCC
ISMINE_CLAIM = 4,
ISMINE_ALL = ISMINE_WATCH_ONLY | ISMINE_SPENDABLE | ISMINE_CLAIM
};
/** used for bitflags of isminetype */
typedef uint8_t isminefilter;