Claim name returned is strange #172
6 changed files with 916 additions and 484 deletions
File diff suppressed because it is too large
Load diff
461
src/claimtrie.h
461
src/claimtrie.h
|
@ -1,31 +1,27 @@
|
||||||
#ifndef BITCOIN_ClaimTRIE_H
|
#ifndef BITCOIN_CLAIMTRIE_H
|
||||||
#define BITCOIN_ClaimTRIE_H
|
#define BITCOIN_CLAIMTRIE_H
|
||||||
|
|
||||||
#include "amount.h"
|
#include "amount.h"
|
||||||
#include "serialize.h"
|
#include "serialize.h"
|
||||||
#include "coins.h"
|
|
||||||
#include "hash.h"
|
|
||||||
#include "uint256.h"
|
#include "uint256.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "leveldbwrapper.h"
|
#include "leveldbwrapper.h"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#define DEFAULT_DELAY 100
|
|
||||||
|
|
||||||
// leveldb keys
|
// leveldb keys
|
||||||
#define HASH_BLOCK 'h'
|
#define HASH_BLOCK 'h'
|
||||||
#define CURRENT_HEIGHT 't'
|
#define CURRENT_HEIGHT 't'
|
||||||
#define TRIE_NODE 'n'
|
#define TRIE_NODE 'n'
|
||||||
#define QUEUE_ROW 'r'
|
#define CLAIM_QUEUE_ROW 'r'
|
||||||
|
#define CLAIM_QUEUE_NAME_ROW 'm'
|
||||||
#define EXP_QUEUE_ROW 'e'
|
#define EXP_QUEUE_ROW 'e'
|
||||||
#define SUPPORT 's'
|
#define SUPPORT 's'
|
||||||
#define SUPPORT_QUEUE 'u'
|
#define SUPPORT_QUEUE_ROW 'u'
|
||||||
|
#define SUPPORT_QUEUE_NAME_ROW 'p'
|
||||||
|
|
||||||
class CNodeValue
|
class CClaimValue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint256 txhash;
|
uint256 txhash;
|
||||||
|
@ -34,10 +30,83 @@ public:
|
||||||
CAmount nEffectiveAmount;
|
CAmount nEffectiveAmount;
|
||||||
int nHeight;
|
int nHeight;
|
||||||
int nValidAtHeight;
|
int nValidAtHeight;
|
||||||
CNodeValue() {};
|
|
||||||
CNodeValue(uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight, int nValidAtHeight) : txhash(txhash), nOut(nOut), nAmount(nAmount), nEffectiveAmount(nAmount), nHeight(nHeight), nValidAtHeight(nValidAtHeight) {}
|
bool fIsUpdate;
|
||||||
|
uint256 updateToTxhash;
|
||||||
|
uint32_t updateToNOut;
|
||||||
|
|
||||||
|
CClaimValue() {};
|
||||||
|
|
||||||
|
CClaimValue(uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight,
|
||||||
|
int nValidAtHeight)
|
||||||
|
: txhash(txhash), nOut(nOut)
|
||||||
|
, nAmount(nAmount), nEffectiveAmount(nAmount)
|
||||||
|
, nHeight(nHeight), nValidAtHeight(nValidAtHeight)
|
||||||
|
, fIsUpdate(false)
|
||||||
|
{}
|
||||||
|
|
||||||
|
CClaimValue(uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight,
|
||||||
|
int nValidAtHeight, uint256 updateToTxhash,
|
||||||
|
uint32_t updateToNOut)
|
||||||
|
: txhash(txhash), nOut(nOut)
|
||||||
|
, nAmount(nAmount), nEffectiveAmount(nAmount)
|
||||||
|
, nHeight(nHeight), nValidAtHeight(nValidAtHeight)
|
||||||
|
, fIsUpdate(true), updateToTxhash(updateToTxhash)
|
||||||
|
, updateToNOut(updateToNOut)
|
||||||
|
{}
|
||||||
|
|
||||||
uint256 GetHash() const;
|
uint256 GetHash() const;
|
||||||
ADD_SERIALIZE_METHODS;
|
|
||||||
|
unsigned int GetSerializeSize(int nType, int nVersion) const
|
||||||
|
{
|
||||||
|
unsigned int nSize = 0;
|
||||||
|
nSize += ::GetSerializeSize(txhash, nType, nVersion);
|
||||||
|
nSize += ::GetSerializeSize(nOut, nType, nVersion);
|
||||||
|
nSize += ::GetSerializeSize(nAmount, nType, nVersion);
|
||||||
|
nSize += ::GetSerializeSize(nHeight, nType, nVersion);
|
||||||
|
nSize += ::GetSerializeSize(nValidAtHeight, nType, nVersion);
|
||||||
|
nSize += ::GetSerializeSize(fIsUpdate, nType, nVersion);
|
||||||
|
if (fIsUpdate)
|
||||||
|
{
|
||||||
|
nSize += ::GetSerializeSize(updateToTxhash, nType, nVersion);
|
||||||
|
nSize += ::GetSerializeSize(updateToNOut, nType, nVersion);
|
||||||
|
}
|
||||||
|
return nSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream>
|
||||||
|
void Serialize(Stream& s, int nType, int nVersion) const
|
||||||
|
{
|
||||||
|
::Serialize(s, txhash, nType, nVersion);
|
||||||
|
::Serialize(s, nOut, nType, nVersion);
|
||||||
|
::Serialize(s, nAmount, nType, nVersion);
|
||||||
|
::Serialize(s, nHeight, nType, nVersion);
|
||||||
|
::Serialize(s, nValidAtHeight, nType, nVersion);
|
||||||
|
::Serialize(s, fIsUpdate, nType, nVersion);
|
||||||
|
if (fIsUpdate)
|
||||||
|
{
|
||||||
|
::Serialize(s, updateToTxhash, nType, nVersion);
|
||||||
|
::Serialize(s, updateToNOut, nType, nVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream>
|
||||||
|
void Unserialize(Stream& s, int nType, int nVersion)
|
||||||
|
{
|
||||||
|
::Unserialize(s, txhash, nType, nVersion);
|
||||||
|
::Unserialize(s, nOut, nType, nVersion);
|
||||||
|
::Unserialize(s, nAmount, nType, nVersion);
|
||||||
|
::Unserialize(s, nHeight, nType, nVersion);
|
||||||
|
::Unserialize(s, nValidAtHeight, nType, nVersion);
|
||||||
|
::Unserialize(s, fIsUpdate, nType, nVersion);
|
||||||
|
if (fIsUpdate)
|
||||||
|
{
|
||||||
|
::Unserialize(s, updateToTxhash, nType, nVersion);
|
||||||
|
::Unserialize(s, updateToNOut, nType, nVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
template <typename Stream, typename Operation>
|
template <typename Stream, typename Operation>
|
||||||
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||||
|
@ -46,9 +115,9 @@ public:
|
||||||
READWRITE(nAmount);
|
READWRITE(nAmount);
|
||||||
READWRITE(nHeight);
|
READWRITE(nHeight);
|
||||||
READWRITE(nValidAtHeight);
|
READWRITE(nValidAtHeight);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
bool operator<(const CNodeValue& other) const
|
bool operator<(const CClaimValue& other) const
|
||||||
{
|
{
|
||||||
if (nEffectiveAmount < other.nEffectiveAmount)
|
if (nEffectiveAmount < other.nEffectiveAmount)
|
||||||
return true;
|
return true;
|
||||||
|
@ -67,17 +136,19 @@ public:
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool operator==(const CNodeValue& other) const
|
|
||||||
|
bool operator==(const CClaimValue& other) const
|
||||||
{
|
{
|
||||||
return txhash == other.txhash && nOut == other.nOut && nAmount == other.nAmount && nHeight == other.nHeight && nValidAtHeight == other.nValidAtHeight;
|
return txhash == other.txhash && nOut == other.nOut && nAmount == other.nAmount && nHeight == other.nHeight && nValidAtHeight == other.nValidAtHeight;
|
||||||
}
|
}
|
||||||
bool operator!=(const CNodeValue& other) const
|
|
||||||
|
bool operator!=(const CClaimValue& other) const
|
||||||
{
|
{
|
||||||
return !(*this == other);
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CSupportNodeValue
|
class CSupportValue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint256 txhash;
|
uint256 txhash;
|
||||||
|
@ -87,8 +158,17 @@ public:
|
||||||
CAmount nAmount;
|
CAmount nAmount;
|
||||||
int nHeight;
|
int nHeight;
|
||||||
int nValidAtHeight;
|
int nValidAtHeight;
|
||||||
CSupportNodeValue() {};
|
|
||||||
CSupportNodeValue(uint256 txhash, uint32_t nOut, uint256 supportTxhash, uint32_t supportnOut, CAmount nAmount, int nHeight, int nValidAtHeight) : txhash(txhash), nOut(nOut), supportTxhash(supportTxhash), supportnOut(supportnOut), nAmount(nAmount), nHeight(nHeight), nValidAtHeight(nValidAtHeight) {}
|
CSupportValue() {};
|
||||||
|
CSupportValue(uint256 txhash, uint32_t nOut, uint256 supportTxhash,
|
||||||
|
uint32_t supportnOut, CAmount nAmount, int nHeight,
|
||||||
|
int nValidAtHeight)
|
||||||
|
: txhash(txhash), nOut(nOut)
|
||||||
|
, supportTxhash(supportTxhash)
|
||||||
|
, supportnOut(supportnOut), nAmount(nAmount)
|
||||||
|
, nHeight(nHeight), nValidAtHeight(nValidAtHeight)
|
||||||
|
{}
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
template <typename Stream, typename Operation>
|
template <typename Stream, typename Operation>
|
||||||
|
@ -102,11 +182,11 @@ public:
|
||||||
READWRITE(nValidAtHeight);
|
READWRITE(nValidAtHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const CSupportNodeValue& other) const
|
bool operator==(const CSupportValue& other) const
|
||||||
{
|
{
|
||||||
return txhash == other.txhash && nOut == other.nOut && supportTxhash == other.supportTxhash && supportnOut == other.supportnOut && nAmount == other.nAmount && nHeight == other.nHeight && nValidAtHeight == other.nValidAtHeight;
|
return txhash == other.txhash && nOut == other.nOut && supportTxhash == other.supportTxhash && supportnOut == other.supportnOut && nAmount == other.nAmount && nHeight == other.nHeight && nValidAtHeight == other.nValidAtHeight;
|
||||||
}
|
}
|
||||||
bool operator!=(const CSupportNodeValue& other) const
|
bool operator!=(const CSupportValue& other) const
|
||||||
{
|
{
|
||||||
return !(*this == other);
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
|
@ -115,7 +195,7 @@ public:
|
||||||
class CClaimTrieNode;
|
class CClaimTrieNode;
|
||||||
class CClaimTrie;
|
class CClaimTrie;
|
||||||
|
|
||||||
typedef std::vector<CSupportNodeValue> supportMapNodeType;
|
typedef std::vector<CSupportValue> supportMapEntryType;
|
||||||
|
|
||||||
typedef std::map<unsigned char, CClaimTrieNode*> nodeMapType;
|
typedef std::map<unsigned char, CClaimTrieNode*> nodeMapType;
|
||||||
|
|
||||||
|
@ -128,24 +208,27 @@ public:
|
||||||
CClaimTrieNode(uint256 hash) : hash(hash) {}
|
CClaimTrieNode(uint256 hash) : hash(hash) {}
|
||||||
uint256 hash;
|
uint256 hash;
|
||||||
nodeMapType children;
|
nodeMapType children;
|
||||||
std::vector<CNodeValue> values;
|
int nBlocksSinceTakeover;
|
||||||
bool insertValue(CNodeValue val);//, bool * fChanged = NULL);
|
std::vector<CClaimValue> claims;
|
||||||
bool removeValue(uint256& txhash, uint32_t nOut, CNodeValue& val);//, bool * fChanged = NULL);
|
|
||||||
bool getBestValue(CNodeValue& val) const;
|
bool insertClaim(CClaimValue claim);
|
||||||
bool empty() const {return children.empty() && values.empty();}
|
bool removeClaim(uint256& txhash, uint32_t nOut, CClaimValue& claim);
|
||||||
bool haveValue(const uint256& txhash, uint32_t nOut) const;
|
bool getBestClaim(CClaimValue& claim) const;
|
||||||
void reorderValues(supportMapNodeType& supports);
|
bool empty() const {return children.empty() && claims.empty();}
|
||||||
|
bool haveClaim(const uint256& txhash, uint32_t nOut) const;
|
||||||
|
void reorderClaims(supportMapEntryType& supports);
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
template <typename Stream, typename Operation>
|
template <typename Stream, typename Operation>
|
||||||
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||||
READWRITE(hash);
|
READWRITE(hash);
|
||||||
READWRITE(values);
|
READWRITE(claims);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const CClaimTrieNode& other) const
|
bool operator==(const CClaimTrieNode& other) const
|
||||||
{
|
{
|
||||||
return hash == other.hash && values == other.values;
|
return hash == other.hash && claims == other.claims;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const CClaimTrieNode& other) const
|
bool operator!=(const CClaimTrieNode& other) const
|
||||||
|
@ -164,47 +247,19 @@ struct nodenamecompare
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CValueQueueEntry
|
typedef std::pair<std::string, CClaimValue> claimQueueEntryType;
|
||||||
{
|
|
||||||
public:
|
|
||||||
CValueQueueEntry() {}
|
|
||||||
CValueQueueEntry(std::string name, CNodeValue val) : name(name), val(val) {}
|
|
||||||
std::string name;
|
|
||||||
CNodeValue val;
|
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
|
||||||
|
|
||||||
template <typename Stream, typename Operation>
|
typedef std::pair<std::string, CSupportValue> supportQueueEntryType;
|
||||||
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
||||||
READWRITE(name);
|
|
||||||
READWRITE(val);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class CSupportValueQueueEntry
|
typedef std::map<std::string, supportMapEntryType> supportMapType;
|
||||||
{
|
|
||||||
public:
|
|
||||||
CSupportValueQueueEntry() {}
|
|
||||||
CSupportValueQueueEntry(std::string name, CSupportNodeValue val) : name(name), val(val) {}
|
|
||||||
std::string name;
|
|
||||||
CSupportNodeValue val;
|
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
typedef std::vector<claimQueueEntryType> claimQueueRowType;
|
||||||
|
typedef std::map<int, claimQueueRowType> claimQueueType;
|
||||||
|
typedef std::map<std::string, std::vector<CClaimValue> > claimQueueNamesType;
|
||||||
|
|
||||||
template <typename Stream, typename Operation>
|
typedef std::vector<supportQueueEntryType> supportQueueRowType;
|
||||||
inline void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion) {
|
typedef std::map<int, supportQueueRowType> supportQueueType;
|
||||||
READWRITE(name);
|
typedef std::map<std::string, std::vector<CSupportValue> > supportQueueNamesType;
|
||||||
READWRITE(val);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::map<std::string, supportMapNodeType> supportMapType;
|
|
||||||
|
|
||||||
typedef std::map<int, std::vector<CValueQueueEntry> > valueQueueType;
|
|
||||||
typedef std::vector<CValueQueueEntry> CClaimTrieQueueUndo;
|
|
||||||
|
|
||||||
typedef std::map<int, std::vector<CSupportValueQueueEntry> > supportValueQueueType;
|
|
||||||
typedef std::vector<CSupportValueQueueEntry> CSupportValueQueueUndo;
|
|
||||||
|
|
||||||
typedef std::map<std::string, CClaimTrieNode*, nodenamecompare> nodeCacheType;
|
typedef std::map<std::string, CClaimTrieNode*, nodenamecompare> nodeCacheType;
|
||||||
|
|
||||||
|
@ -215,127 +270,259 @@ class CClaimTrieCache;
|
||||||
class CClaimTrie
|
class CClaimTrie
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CClaimTrie(bool fMemory = false, bool fWipe = false) : db(GetDataDir() / "claimtrie", 100, fMemory, fWipe, false), nCurrentHeight(0), nExpirationTime(262974), root(uint256S("0000000000000000000000000000000000000000000000000000000000000001")) {}
|
CClaimTrie(bool fMemory = false, bool fWipe = false)
|
||||||
|
: db(GetDataDir() / "claimtrie", 100, fMemory, fWipe, false)
|
||||||
|
, nCurrentHeight(0), nExpirationTime(262974)
|
||||||
|
, fConstantDelay(false), nConstantDelayHeight(100)
|
||||||
|
, nProportionalDelayBits(5)
|
||||||
|
, root(uint256S("0000000000000000000000000000000000000000000000000000000000000001"))
|
||||||
|
{}
|
||||||
|
|
||||||
uint256 getMerkleHash();
|
uint256 getMerkleHash();
|
||||||
CLevelDBWrapper db;
|
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
bool checkConsistency();
|
bool checkConsistency();
|
||||||
|
|
||||||
bool WriteToDisk();
|
bool WriteToDisk();
|
||||||
bool ReadFromDisk(bool check = false);
|
bool ReadFromDisk(bool check = false);
|
||||||
|
|
||||||
std::vector<namedNodeType> flattenTrie() const;
|
std::vector<namedNodeType> flattenTrie() const;
|
||||||
bool getInfoForName(const std::string& name, CNodeValue& val) const;
|
bool getInfoForName(const std::string& name, CClaimValue& claim) const;
|
||||||
int nCurrentHeight;
|
|
||||||
bool queueEmpty() const;
|
bool queueEmpty() const;
|
||||||
bool supportEmpty() const;
|
bool supportEmpty() const;
|
||||||
bool supportQueueEmpty() const;
|
bool supportQueueEmpty() const;
|
||||||
bool expirationQueueEmpty() const;
|
bool expirationQueueEmpty() const;
|
||||||
|
|
||||||
void setExpirationTime(int t);
|
void setExpirationTime(int t);
|
||||||
bool getQueueRow(int nHeight, std::vector<CValueQueueEntry>& row) const;
|
|
||||||
bool getExpirationQueueRow(int nHeight, std::vector<CValueQueueEntry>& row) const;
|
bool getQueueRow(int nHeight, claimQueueRowType& row) const;
|
||||||
bool getSupportNode(std::string name, supportMapNodeType& node) const;
|
bool getQueueNameRow(const std::string& name, std::vector<CClaimValue>& row) const;
|
||||||
bool getSupportQueueRow(int nHeight, std::vector<CSupportValueQueueEntry>& row) const;
|
bool getExpirationQueueRow(int nHeight, claimQueueRowType& row) const;
|
||||||
bool haveClaim(const std::string& name, const uint256& txhash, uint32_t nOut) const;
|
bool getSupportNode(std::string name, supportMapEntryType& node) const;
|
||||||
bool haveClaimInQueue(const std::string& name, const uint256& txhash, uint32_t nOut, int nHeight, int& nValidAtHeight) const;
|
bool getSupportQueueRow(int nHeight, supportQueueRowType& row) const;
|
||||||
bool haveClaimInQueueRow(const std::string& name, const uint256& txhash, uint32_t nOut, int nHeight, const std::vector<CValueQueueEntry>& row) const;
|
bool getSupportQueueNameRow(const std::string& name, std::vector<CSupportValue>& row) const;
|
||||||
bool haveSupport(const std::string& name, const uint256& txhash, uint32_t nOut) const;
|
|
||||||
bool haveSupportInQueue(const std::string& name, const uint256& txhash, uint32_t nOut, int nHeight, int& nValidAtHeight) const;
|
bool haveClaim(const std::string& name, const uint256& txhash,
|
||||||
bool haveSupportInQueueRow(const std::string& name, const uint256& txhash, uint32_t nOut, int nHeight, const std::vector<CSupportValueQueueEntry>& row) const;
|
uint32_t nOut) const;
|
||||||
|
bool haveClaimInQueue(const std::string& name, const uint256& txhash,
|
||||||
|
uint32_t nOut, int nHeight,
|
||||||
|
int& nValidAtHeight) const;
|
||||||
|
|
||||||
|
bool haveSupport(const std::string& name, const uint256& txhash,
|
||||||
|
uint32_t nOut) const;
|
||||||
|
bool haveSupportInQueue(const std::string& name, const uint256& txhash,
|
||||||
|
uint32_t nOut, int nHeight,
|
||||||
|
int& nValidAtHeight) const;
|
||||||
|
|
||||||
unsigned int getTotalNamesInTrie() const;
|
unsigned int getTotalNamesInTrie() const;
|
||||||
unsigned int getTotalClaimsInTrie() const;
|
unsigned int getTotalClaimsInTrie() const;
|
||||||
CAmount getTotalValueOfClaimsInTrie(bool fControllingOnly) const;
|
CAmount getTotalValueOfClaimsInTrie(bool fControllingOnly) const;
|
||||||
|
|
||||||
friend class CClaimTrieCache;
|
friend class CClaimTrieCache;
|
||||||
|
|
||||||
|
CLevelDBWrapper db;
|
||||||
|
int nCurrentHeight;
|
||||||
int nExpirationTime;
|
int nExpirationTime;
|
||||||
|
bool fConstantDelay;
|
||||||
|
int nConstantDelayHeight;
|
||||||
|
int nProportionalDelayBits;
|
||||||
private:
|
private:
|
||||||
void clear(CClaimTrieNode* current);
|
void clear(CClaimTrieNode* current);
|
||||||
bool update(nodeCacheType& cache, hashMapType& hashes, const uint256& hashBlock, valueQueueType& queueCache, valueQueueType& expirationQueueCache, int nNewHeight, supportMapType& supportCache, supportValueQueueType& supportQueueCache);
|
|
||||||
|
bool update(nodeCacheType& cache, hashMapType& hashes,
|
||||||
|
const uint256& hashBlock, claimQueueType& queueCache,
|
||||||
|
claimQueueNamesType& queueNameCache,
|
||||||
|
claimQueueType& expirationQueueCache, int nNewHeight,
|
||||||
|
supportMapType& supportCache,
|
||||||
|
supportQueueType& supportQueueCache,
|
||||||
|
supportQueueNamesType& supportQueueNameCache);
|
||||||
bool updateName(const std::string& name, CClaimTrieNode* updatedNode);
|
bool updateName(const std::string& name, CClaimTrieNode* updatedNode);
|
||||||
bool updateHash(const std::string& name, uint256& hash);
|
bool updateHash(const std::string& name, uint256& hash);
|
||||||
bool recursiveNullify(CClaimTrieNode* node, std::string& name);
|
bool recursiveNullify(CClaimTrieNode* node, std::string& name);
|
||||||
|
|
||||||
bool recursiveCheckConsistency(CClaimTrieNode* node);
|
bool recursiveCheckConsistency(CClaimTrieNode* node);
|
||||||
|
|
||||||
bool InsertFromDisk(const std::string& name, CClaimTrieNode* node);
|
bool InsertFromDisk(const std::string& name, CClaimTrieNode* node);
|
||||||
|
|
||||||
unsigned int getTotalNamesRecursive(const CClaimTrieNode* current) const;
|
unsigned int getTotalNamesRecursive(const CClaimTrieNode* current) const;
|
||||||
unsigned int getTotalClaimsRecursive(const CClaimTrieNode* current) const;
|
unsigned int getTotalClaimsRecursive(const CClaimTrieNode* current) const;
|
||||||
CAmount getTotalValueOfClaimsRecursive(const CClaimTrieNode* current, bool fControllingOnly) const;
|
CAmount getTotalValueOfClaimsRecursive(const CClaimTrieNode* current,
|
||||||
bool recursiveFlattenTrie(const std::string& name, const CClaimTrieNode* current, std::vector<namedNodeType>& nodes) const;
|
bool fControllingOnly) const;
|
||||||
CClaimTrieNode root;
|
bool recursiveFlattenTrie(const std::string& name,
|
||||||
//supportMapType support;
|
const CClaimTrieNode* current,
|
||||||
uint256 hashBlock;
|
std::vector<namedNodeType>& nodes) const;
|
||||||
valueQueueType dirtyQueueRows;
|
|
||||||
valueQueueType dirtyExpirationQueueRows;
|
|
||||||
supportValueQueueType dirtySupportQueueRows;
|
|
||||||
|
|
||||||
nodeCacheType dirtyNodes;
|
|
||||||
supportMapType dirtySupportNodes;
|
|
||||||
void markNodeDirty(const std::string& name, CClaimTrieNode* node);
|
void markNodeDirty(const std::string& name, CClaimTrieNode* node);
|
||||||
void updateQueueRow(int nHeight, std::vector<CValueQueueEntry>& row);
|
void updateQueueRow(int nHeight, claimQueueRowType& row);
|
||||||
void updateExpirationRow(int nHeight, std::vector<CValueQueueEntry>& row);
|
void updateQueueNameRow(const std::string& name,
|
||||||
void updateSupportMap(const std::string& name, supportMapNodeType& node);
|
std::vector<CClaimValue>& row);
|
||||||
void updateSupportQueue(int nHeight, std::vector<CSupportValueQueueEntry>& row);
|
void updateExpirationRow(int nHeight, claimQueueRowType& row);
|
||||||
void BatchWriteNode(CLevelDBBatch& batch, const std::string& name, const CClaimTrieNode* pNode) const;
|
void updateSupportMap(const std::string& name, supportMapEntryType& node);
|
||||||
|
void updateSupportQueue(int nHeight, supportQueueRowType& row);
|
||||||
|
void updateSupportNameQueue(const std::string& name,
|
||||||
|
std::vector<CSupportValue>& row);
|
||||||
|
|
||||||
|
void BatchWriteNode(CLevelDBBatch& batch, const std::string& name,
|
||||||
|
const CClaimTrieNode* pNode) const;
|
||||||
void BatchEraseNode(CLevelDBBatch& batch, const std::string& nome) const;
|
void BatchEraseNode(CLevelDBBatch& batch, const std::string& nome) const;
|
||||||
void BatchWriteQueueRows(CLevelDBBatch& batch);
|
void BatchWriteQueueRows(CLevelDBBatch& batch);
|
||||||
|
void BatchWriteQueueNameRows(CLevelDBBatch& batch);
|
||||||
void BatchWriteExpirationQueueRows(CLevelDBBatch& batch);
|
void BatchWriteExpirationQueueRows(CLevelDBBatch& batch);
|
||||||
void BatchWriteSupportNodes(CLevelDBBatch& batch);
|
void BatchWriteSupportNodes(CLevelDBBatch& batch);
|
||||||
void BatchWriteSupportQueueRows(CLevelDBBatch& batch);
|
void BatchWriteSupportQueueRows(CLevelDBBatch& batch);
|
||||||
|
void BatchWriteSupportQueueNameRows(CLevelDBBatch& batch);
|
||||||
template<typename K> bool keyTypeEmpty(char key, K& dummy) const;
|
template<typename K> bool keyTypeEmpty(char key, K& dummy) const;
|
||||||
|
|
||||||
|
CClaimTrieNode root;
|
||||||
|
uint256 hashBlock;
|
||||||
|
|
||||||
|
claimQueueType dirtyQueueRows;
|
||||||
|
claimQueueNamesType dirtyQueueNameRows;
|
||||||
|
claimQueueType dirtyExpirationQueueRows;
|
||||||
|
|
||||||
|
supportQueueType dirtySupportQueueRows;
|
||||||
|
supportQueueNamesType dirtySupportQueueNameRows;
|
||||||
|
|
||||||
|
nodeCacheType dirtyNodes;
|
||||||
|
supportMapType dirtySupportNodes;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CClaimTrieCache
|
class CClaimTrieCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CClaimTrieCache(CClaimTrie* base): base(base) {assert(base); nCurrentHeight = base->nCurrentHeight;}
|
CClaimTrieCache(CClaimTrie* base): base(base)
|
||||||
|
{
|
||||||
|
assert(base);
|
||||||
|
nCurrentHeight = base->nCurrentHeight;
|
||||||
|
}
|
||||||
|
|
||||||
uint256 getMerkleHash() const;
|
uint256 getMerkleHash() const;
|
||||||
|
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
bool flush();
|
bool flush();
|
||||||
bool dirty() const { return !dirtyHashes.empty(); }
|
bool dirty() const { return !dirtyHashes.empty(); }
|
||||||
bool addClaim(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight) const;
|
|
||||||
bool addClaim(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight, uint256 prevTxhash, uint32_t nPrevOut) const;
|
bool addClaim(const std::string name, uint256 txhash, uint32_t nOut,
|
||||||
bool undoAddClaim(const std::string name, uint256 txhash, uint32_t nOut, int nHeight) const;
|
CAmount nAmount, int nHeight) const;
|
||||||
bool spendClaim(const std::string name, uint256 txhash, uint32_t nOut, int nHeight, int& nValidAtHeight) const;
|
bool addClaim(const std::string name, uint256 txhash, uint32_t nOut,
|
||||||
bool undoSpendClaim(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight, int nValidAtHeight) const;
|
CAmount nAmount, int nHeight, uint256 prevTxhash,
|
||||||
bool addSupport(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, uint32_t supportednOut, int nHeight) const;
|
uint32_t nPrevOut) const;
|
||||||
bool undoAddSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, uint32_t supportednOut, int nHeight) const;
|
bool undoAddClaim(const std::string name, uint256 txhash, uint32_t nOut,
|
||||||
bool spendSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, uint32_t supportednOut, int nHeight, int& nValidAtHeight) const;
|
int nHeight) const;
|
||||||
bool undoSpendSupport(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, uint32_t supportednOut, int nHeight, int nValidAtHeight) const;
|
bool spendClaim(const std::string name, uint256 txhash, uint32_t nOut,
|
||||||
|
int nHeight, int& nValidAtHeight) const;
|
||||||
|
bool undoSpendClaim(const std::string name, uint256 txhash, uint32_t nOut,
|
||||||
|
CAmount nAmount, int nHeight,
|
||||||
|
int nValidAtHeight) const;
|
||||||
|
|
||||||
|
bool addSupport(const std::string name, uint256 txhash, uint32_t nOut,
|
||||||
|
CAmount nAmount, uint256 supportedTxhash,
|
||||||
|
uint32_t supportednOut, int nHeight) const;
|
||||||
|
bool undoAddSupport(const std::string name, uint256 txhash, uint32_t nOut,
|
||||||
|
uint256 supportedTxhash, uint32_t supportednOut,
|
||||||
|
int nHeight) const;
|
||||||
|
bool spendSupport(const std::string name, uint256 txhash, uint32_t nOut,
|
||||||
|
uint256 supportedTxhash, uint32_t supportednOut,
|
||||||
|
int nHeight, int& nValidAtHeight) const;
|
||||||
|
bool undoSpendSupport(const std::string name, uint256 txhash,
|
||||||
|
uint32_t nOut, CAmount nAmount,
|
||||||
|
uint256 supportedTxhash, uint32_t supportednOut,
|
||||||
|
int nHeight, int nValidAtHeight) const;
|
||||||
|
|
||||||
uint256 getBestBlock();
|
uint256 getBestBlock();
|
||||||
void setBestBlock(const uint256& hashBlock);
|
void setBestBlock(const uint256& hashBlock);
|
||||||
bool incrementBlock(CClaimTrieQueueUndo& insertUndo, CClaimTrieQueueUndo& expireUndo, CSupportValueQueueUndo& insertSupportUndo) const;
|
|
||||||
bool decrementBlock(CClaimTrieQueueUndo& insertUndo, CClaimTrieQueueUndo& expireUndo, CSupportValueQueueUndo& insertSupportUndo) const;
|
bool incrementBlock(claimQueueRowType& insertUndo,
|
||||||
|
claimQueueRowType& expireUndo,
|
||||||
|
supportQueueRowType& insertSupportUndo) const;
|
||||||
|
bool decrementBlock(claimQueueRowType& insertUndo,
|
||||||
|
claimQueueRowType& expireUndo,
|
||||||
|
supportQueueRowType& insertSupportUndo) const;
|
||||||
|
|
||||||
~CClaimTrieCache() { clear(); }
|
~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;
|
bool insertClaimIntoTrie(const std::string name, CClaimValue claim) const;
|
||||||
|
bool removeClaimFromTrie(const std::string name, uint256 txhash,
|
||||||
|
uint32_t nOut, int& nValidAtHeight) const;
|
||||||
private:
|
private:
|
||||||
CClaimTrie* base;
|
CClaimTrie* base;
|
||||||
|
|
||||||
mutable nodeCacheType cache;
|
mutable nodeCacheType cache;
|
||||||
mutable std::set<std::string> dirtyHashes;
|
mutable std::set<std::string> dirtyHashes;
|
||||||
mutable hashMapType cacheHashes;
|
mutable hashMapType cacheHashes;
|
||||||
mutable valueQueueType valueQueueCache;
|
mutable claimQueueType claimQueueCache;
|
||||||
mutable valueQueueType expirationQueueCache;
|
mutable claimQueueNamesType claimQueueNameCache;
|
||||||
|
mutable claimQueueType expirationQueueCache;
|
||||||
mutable supportMapType supportCache;
|
mutable supportMapType supportCache;
|
||||||
mutable supportValueQueueType supportQueueCache;
|
mutable supportQueueType supportQueueCache;
|
||||||
|
mutable supportQueueNamesType supportQueueNameCache;
|
||||||
mutable int nCurrentHeight; // Height of the block that is being worked on, which is
|
mutable int nCurrentHeight; // Height of the block that is being worked on, which is
|
||||||
// one greater than the height of the chain's tip
|
// one greater than the height of the chain's tip
|
||||||
uint256 computeHash() const;
|
|
||||||
bool reorderTrieNode(const std::string name) 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;
|
|
||||||
bool removeClaimFromQueue(const std::string name, uint256 txhash, uint32_t nOut, int nHeightToCheck, int& nValidAtHeight) const;
|
|
||||||
void addToExpirationQueue(CValueQueueEntry& entry) const;
|
|
||||||
void removeFromExpirationQueue(const std::string name, uint256 txhash, uint32_t nOut, int nHeight) const;
|
|
||||||
valueQueueType::iterator getQueueCacheRow(int nHeight, bool createIfNotExists) const;
|
|
||||||
valueQueueType::iterator getExpirationQueueCacheRow(int nHeight, bool createIfNotExists) const;
|
|
||||||
bool removeSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, uint32_t supportednOut, int nHeight, int& nValidAtHeight) const;
|
|
||||||
bool removeSupportFromMap(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, uint32_t supportednOut, int nHeight, int& nValidAtHeight) const;
|
|
||||||
bool insertSupportIntoMap(const std::string name, CSupportNodeValue val) const;
|
|
||||||
supportValueQueueType::iterator getSupportQueueCacheRow(int nHeight, bool createIfNotExists) const;
|
|
||||||
bool addSupportToQueue(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, uint32_t supportednOut, int nHeight, int nValidAtHeight) const;
|
|
||||||
bool removeSupportFromQueue(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, uint32_t supportednOut, int nHeightToCheck, int& nValidAtHeight) const;
|
|
||||||
uint256 hashBlock;
|
uint256 hashBlock;
|
||||||
bool getSupportsForName(const std::string name, supportMapNodeType& node) const;
|
|
||||||
|
uint256 computeHash() const;
|
||||||
|
|
||||||
|
bool reorderTrieNode(const std::string name) 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;
|
||||||
|
bool removeClaimFromQueue(const std::string name, uint256 txhash,
|
||||||
|
uint32_t nOut, int& nValidAtHeight) const;
|
||||||
|
void addToExpirationQueue(claimQueueEntryType& entry) const;
|
||||||
|
void removeFromExpirationQueue(const std::string name, uint256 txhash,
|
||||||
|
uint32_t nOut, int nHeight) const;
|
||||||
|
|
||||||
|
claimQueueType::iterator getQueueCacheRow(int nHeight,
|
||||||
|
bool createIfNotExists) const;
|
||||||
|
claimQueueNamesType::iterator getQueueCacheNameRow(const std::string& name,
|
||||||
|
bool createIfNotExists) const;
|
||||||
|
claimQueueType::iterator getExpirationQueueCacheRow(int nHeight,
|
||||||
|
bool createIfNotExists) const;
|
||||||
|
|
||||||
|
bool removeSupport(const std::string name, uint256 txhash, uint32_t nOut,
|
||||||
|
uint256 supportedTxhash, uint32_t supportednOut,
|
||||||
|
int nHeight, int& nValidAtHeight) const;
|
||||||
|
bool removeSupportFromMap(const std::string name, uint256 txhash,
|
||||||
|
uint32_t nOut, uint256 supportedTxhash,
|
||||||
|
uint32_t supportednOut, int nHeight,
|
||||||
|
int& nValidAtHeight) const;
|
||||||
|
|
||||||
|
bool insertSupportIntoMap(const std::string name,
|
||||||
|
CSupportValue support) const;
|
||||||
|
|
||||||
|
supportQueueType::iterator getSupportQueueCacheRow(int nHeight,
|
||||||
|
bool createIfNotExists) const;
|
||||||
|
supportQueueNamesType::iterator getSupportQueueCacheNameRow(const std::string& name,
|
||||||
|
bool createIfNotExists) const;
|
||||||
|
|
||||||
|
bool addSupportToQueue(const std::string name, uint256 txhash,
|
||||||
|
uint32_t nOut, CAmount nAmount,
|
||||||
|
uint256 supportedTxhash, uint32_t supportednOut,
|
||||||
|
int nHeight, int nValidAtHeight) const;
|
||||||
|
bool removeSupportFromQueue(const std::string name, uint256 txhash,
|
||||||
|
uint32_t nOut, uint256 supportedTxhash,
|
||||||
|
uint32_t supportednOut,
|
||||||
|
int& nValidAtHeight) const;
|
||||||
|
|
||||||
|
bool getSupportsForName(const std::string name,
|
||||||
|
supportMapEntryType& node) const;
|
||||||
|
|
||||||
|
int getDelayForName(const std::string name) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_ClaimTRIE_H
|
#endif // BITCOIN_CLAIMTRIE_H
|
||||||
|
|
|
@ -434,9 +434,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
|
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
|
||||||
pblock->nNonce = 0;
|
pblock->nNonce = 0;
|
||||||
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
|
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
|
||||||
CClaimTrieQueueUndo dummyInsertUndo;
|
claimQueueRowType dummyInsertUndo;
|
||||||
CClaimTrieQueueUndo dummyExpireUndo;
|
claimQueueRowType dummyExpireUndo;
|
||||||
CSupportValueQueueUndo dummyInsertSupportUndo;
|
supportQueueRowType dummyInsertSupportUndo;
|
||||||
trieCache.incrementBlock(dummyInsertUndo, dummyExpireUndo, dummyInsertSupportUndo);
|
trieCache.incrementBlock(dummyInsertUndo, dummyExpireUndo, dummyInsertSupportUndo);
|
||||||
pblock->hashClaimTrie = trieCache.getMerkleHash();
|
pblock->hashClaimTrie = trieCache.getMerkleHash();
|
||||||
|
|
||||||
|
|
|
@ -32,13 +32,13 @@ UniValue getclaimtrie(const UniValue& params, bool fHelp)
|
||||||
UniValue node(UniValue::VOBJ);
|
UniValue node(UniValue::VOBJ);
|
||||||
node.push_back(Pair("name", it->first));
|
node.push_back(Pair("name", it->first));
|
||||||
node.push_back(Pair("hash", it->second.hash.GetHex()));
|
node.push_back(Pair("hash", it->second.hash.GetHex()));
|
||||||
CNodeValue val;
|
CClaimValue claim;
|
||||||
if (it->second.getBestValue(val))
|
if (it->second.getBestClaim(claim))
|
||||||
{
|
{
|
||||||
node.push_back(Pair("txid", val.txhash.GetHex()));
|
node.push_back(Pair("txid", claim.txhash.GetHex()));
|
||||||
node.push_back(Pair("n", (int)val.nOut));
|
node.push_back(Pair("n", (int)claim.nOut));
|
||||||
node.push_back(Pair("value", ValueFromAmount(val.nAmount)));
|
node.push_back(Pair("value", ValueFromAmount(claim.nAmount)));
|
||||||
node.push_back(Pair("height", val.nHeight));
|
node.push_back(Pair("height", claim.nHeight));
|
||||||
}
|
}
|
||||||
ret.push_back(node);
|
ret.push_back(node);
|
||||||
}
|
}
|
||||||
|
@ -62,36 +62,36 @@ UniValue getvalueforname(const UniValue& params, bool fHelp)
|
||||||
);
|
);
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
std::string name = params[0].get_str();
|
std::string name = params[0].get_str();
|
||||||
CNodeValue val;
|
CClaimValue claim;
|
||||||
UniValue ret(UniValue::VOBJ);
|
UniValue ret(UniValue::VOBJ);
|
||||||
if (!pclaimTrie->getInfoForName(name, val))
|
if (!pclaimTrie->getInfoForName(name, claim))
|
||||||
return ret;
|
return ret;
|
||||||
CCoinsViewCache view(pcoinsTip);
|
CCoinsViewCache view(pcoinsTip);
|
||||||
const CCoins* coin = view.AccessCoins(val.txhash);
|
const CCoins* coin = view.AccessCoins(claim.txhash);
|
||||||
if (!coin)
|
if (!coin)
|
||||||
{
|
{
|
||||||
LogPrintf("%s: %s does not exist in the coins view, despite being associated with a name\n",
|
LogPrintf("%s: %s does not exist in the coins view, despite being associated with a name\n",
|
||||||
__func__, val.txhash.GetHex());
|
__func__, claim.txhash.GetHex());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if (coin->vout.size() < val.nOut || coin->vout[val.nOut].IsNull())
|
if (coin->vout.size() < claim.nOut || coin->vout[claim.nOut].IsNull())
|
||||||
{
|
{
|
||||||
LogPrintf("%s: the specified txout of %s appears to have been spent\n", __func__, val.txhash.GetHex());
|
LogPrintf("%s: the specified txout of %s appears to have been spent\n", __func__, claim.txhash.GetHex());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int op;
|
int op;
|
||||||
std::vector<std::vector<unsigned char> > vvchParams;
|
std::vector<std::vector<unsigned char> > vvchParams;
|
||||||
if (!DecodeClaimScript(coin->vout[val.nOut].scriptPubKey, op, vvchParams))
|
if (!DecodeClaimScript(coin->vout[claim.nOut].scriptPubKey, op, vvchParams))
|
||||||
{
|
{
|
||||||
LogPrintf("%s: the specified txout of %s does not have a name claim command\n", __func__, val.txhash.GetHex());
|
LogPrintf("%s: the specified txout of %s does not have a name claim command\n", __func__, claim.txhash.GetHex());
|
||||||
}
|
}
|
||||||
std::string sValue(vvchParams[1].begin(), vvchParams[1].end());
|
std::string sValue(vvchParams[1].begin(), vvchParams[1].end());
|
||||||
ret.push_back(Pair("value", sValue));
|
ret.push_back(Pair("value", sValue));
|
||||||
ret.push_back(Pair("txid", val.txhash.GetHex()));
|
ret.push_back(Pair("txid", claim.txhash.GetHex()));
|
||||||
ret.push_back(Pair("n", (int)val.nOut));
|
ret.push_back(Pair("n", (int)claim.nOut));
|
||||||
ret.push_back(Pair("amount", val.nAmount));
|
ret.push_back(Pair("amount", claim.nAmount));
|
||||||
ret.push_back(Pair("height", val.nHeight));
|
ret.push_back(Pair("height", claim.nHeight));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,12 +253,12 @@ UniValue getclaimsfortx(const UniValue& params, bool fHelp)
|
||||||
o.push_back(Pair("in claim trie", inClaimTrie));
|
o.push_back(Pair("in claim trie", inClaimTrie));
|
||||||
if (inClaimTrie)
|
if (inClaimTrie)
|
||||||
{
|
{
|
||||||
CNodeValue val;
|
CClaimValue claim;
|
||||||
if (!pclaimTrie->getInfoForName(sName, val))
|
if (!pclaimTrie->getInfoForName(sName, claim))
|
||||||
{
|
{
|
||||||
LogPrintf("HaveClaim was true but getInfoForName returned false.");
|
LogPrintf("HaveClaim was true but getInfoForName returned false.");
|
||||||
}
|
}
|
||||||
o.push_back(Pair("is controlling", (val.txhash == hash && val.nOut == i)));
|
o.push_back(Pair("is controlling", (claim.txhash == hash && claim.nOut == i)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -172,18 +172,18 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
|
||||||
BOOST_CHECK(pclaimTrie->empty());
|
BOOST_CHECK(pclaimTrie->empty());
|
||||||
|
|
||||||
CClaimTrieCache ntState(pclaimTrie);
|
CClaimTrieCache ntState(pclaimTrie);
|
||||||
ntState.insertClaimIntoTrie(std::string("test"), CNodeValue(tx1.GetHash(), 0, 50, 100, 200));
|
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1.GetHash(), 0, 50, 100, 200));
|
||||||
ntState.insertClaimIntoTrie(std::string("test2"), CNodeValue(tx2.GetHash(), 0, 50, 100, 200));
|
ntState.insertClaimIntoTrie(std::string("test2"), CClaimValue(tx2.GetHash(), 0, 50, 100, 200));
|
||||||
|
|
||||||
BOOST_CHECK(pclaimTrie->empty());
|
BOOST_CHECK(pclaimTrie->empty());
|
||||||
BOOST_CHECK(!ntState.empty());
|
BOOST_CHECK(!ntState.empty());
|
||||||
BOOST_CHECK(ntState.getMerkleHash() == hash1);
|
BOOST_CHECK(ntState.getMerkleHash() == hash1);
|
||||||
|
|
||||||
ntState.insertClaimIntoTrie(std::string("test"), CNodeValue(tx3.GetHash(), 0, 50, 101, 201));
|
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3.GetHash(), 0, 50, 101, 201));
|
||||||
BOOST_CHECK(ntState.getMerkleHash() == hash1);
|
BOOST_CHECK(ntState.getMerkleHash() == hash1);
|
||||||
ntState.insertClaimIntoTrie(std::string("tes"), CNodeValue(tx4.GetHash(), 0, 50, 100, 200));
|
ntState.insertClaimIntoTrie(std::string("tes"), CClaimValue(tx4.GetHash(), 0, 50, 100, 200));
|
||||||
BOOST_CHECK(ntState.getMerkleHash() == hash2);
|
BOOST_CHECK(ntState.getMerkleHash() == hash2);
|
||||||
ntState.insertClaimIntoTrie(std::string("testtesttesttest"), CNodeValue(tx5.GetHash(), 0, 50, 100, 200));
|
ntState.insertClaimIntoTrie(std::string("testtesttesttest"), CClaimValue(tx5.GetHash(), 0, 50, 100, 200));
|
||||||
ntState.removeClaimFromTrie(std::string("testtesttesttest"), tx5.GetHash(), 0, unused);
|
ntState.removeClaimFromTrie(std::string("testtesttesttest"), tx5.GetHash(), 0, unused);
|
||||||
BOOST_CHECK(ntState.getMerkleHash() == hash2);
|
BOOST_CHECK(ntState.getMerkleHash() == hash2);
|
||||||
ntState.flush();
|
ntState.flush();
|
||||||
|
@ -201,7 +201,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
|
||||||
BOOST_CHECK(ntState1.getMerkleHash() == hash0);
|
BOOST_CHECK(ntState1.getMerkleHash() == hash0);
|
||||||
|
|
||||||
CClaimTrieCache ntState2(pclaimTrie);
|
CClaimTrieCache ntState2(pclaimTrie);
|
||||||
ntState2.insertClaimIntoTrie(std::string("abab"), CNodeValue(tx6.GetHash(), 0, 50, 100, 200));
|
ntState2.insertClaimIntoTrie(std::string("abab"), CClaimValue(tx6.GetHash(), 0, 50, 100, 200));
|
||||||
ntState2.removeClaimFromTrie(std::string("test"), tx1.GetHash(), 0, unused);
|
ntState2.removeClaimFromTrie(std::string("test"), tx1.GetHash(), 0, unused);
|
||||||
|
|
||||||
BOOST_CHECK(ntState2.getMerkleHash() == hash3);
|
BOOST_CHECK(ntState2.getMerkleHash() == hash3);
|
||||||
|
@ -213,7 +213,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
|
||||||
BOOST_CHECK(pclaimTrie->checkConsistency());
|
BOOST_CHECK(pclaimTrie->checkConsistency());
|
||||||
|
|
||||||
CClaimTrieCache ntState3(pclaimTrie);
|
CClaimTrieCache ntState3(pclaimTrie);
|
||||||
ntState3.insertClaimIntoTrie(std::string("test"), CNodeValue(tx1.GetHash(), 0, 50, 100, 200));
|
ntState3.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1.GetHash(), 0, 50, 100, 200));
|
||||||
BOOST_CHECK(ntState3.getMerkleHash() == hash4);
|
BOOST_CHECK(ntState3.getMerkleHash() == hash4);
|
||||||
ntState3.flush();
|
ntState3.flush();
|
||||||
BOOST_CHECK(!pclaimTrie->empty());
|
BOOST_CHECK(!pclaimTrie->empty());
|
||||||
|
@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
|
||||||
BOOST_CHECK(pclaimTrie->checkConsistency());
|
BOOST_CHECK(pclaimTrie->checkConsistency());
|
||||||
|
|
||||||
CClaimTrieCache ntState6(pclaimTrie);
|
CClaimTrieCache ntState6(pclaimTrie);
|
||||||
ntState6.insertClaimIntoTrie(std::string("test"), CNodeValue(tx3.GetHash(), 0, 50, 101, 201));
|
ntState6.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3.GetHash(), 0, 50, 101, 201));
|
||||||
|
|
||||||
BOOST_CHECK(ntState6.getMerkleHash() == hash2);
|
BOOST_CHECK(ntState6.getMerkleHash() == hash2);
|
||||||
ntState6.flush();
|
ntState6.flush();
|
||||||
|
@ -302,7 +302,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
|
||||||
tx8.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE;
|
tx8.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE;
|
||||||
tx8.vout[0].nValue = tx8.vout[0].nValue - 1;
|
tx8.vout[0].nValue = tx8.vout[0].nValue - 1;
|
||||||
tx8.vout[1].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
|
tx8.vout[1].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
|
||||||
CNodeValue val;
|
CClaimValue val;
|
||||||
|
|
||||||
std::vector<uint256> blocks_to_invalidate;
|
std::vector<uint256> blocks_to_invalidate;
|
||||||
|
|
||||||
|
@ -974,7 +974,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
|
||||||
CMutableTransaction tx6 = BuildTransaction(tx3);
|
CMutableTransaction tx6 = BuildTransaction(tx3);
|
||||||
tx6.vout[0].scriptPubKey = CScript() << OP_TRUE;
|
tx6.vout[0].scriptPubKey = CScript() << OP_TRUE;
|
||||||
|
|
||||||
CNodeValue val;
|
CClaimValue val;
|
||||||
std::vector<uint256> blocks_to_invalidate;
|
std::vector<uint256> blocks_to_invalidate;
|
||||||
|
|
||||||
// Test 1: create 1 LBC claim (tx1), create 5 LBC support (tx3), create 5 LBC claim (tx2)
|
// Test 1: create 1 LBC claim (tx1), create 5 LBC support (tx3), create 5 LBC claim (tx2)
|
||||||
|
@ -1301,7 +1301,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
|
||||||
CMutableTransaction tx6 = BuildTransaction(tx3);
|
CMutableTransaction tx6 = BuildTransaction(tx3);
|
||||||
tx6.vout[0].scriptPubKey = CScript() << OP_TRUE;
|
tx6.vout[0].scriptPubKey = CScript() << OP_TRUE;
|
||||||
|
|
||||||
CNodeValue val;
|
CClaimValue val;
|
||||||
std::vector<uint256> blocks_to_invalidate;
|
std::vector<uint256> blocks_to_invalidate;
|
||||||
|
|
||||||
// Test 2: create 1 LBC claim (tx1), create 5 LBC claim (tx2), create 5 LBC support (tx3)
|
// Test 2: create 1 LBC claim (tx1), create 5 LBC claim (tx2), create 5 LBC support (tx3)
|
||||||
|
@ -1846,7 +1846,7 @@ BOOST_AUTO_TEST_CASE(claimtrienode_serialize_unserialize)
|
||||||
|
|
||||||
CClaimTrieNode n1;
|
CClaimTrieNode n1;
|
||||||
CClaimTrieNode n2;
|
CClaimTrieNode n2;
|
||||||
CNodeValue throwaway;
|
CClaimValue throwaway;
|
||||||
|
|
||||||
ss << n1;
|
ss << n1;
|
||||||
ss >> n2;
|
ss >> n2;
|
||||||
|
@ -1864,28 +1864,28 @@ BOOST_AUTO_TEST_CASE(claimtrienode_serialize_unserialize)
|
||||||
ss >> n2;
|
ss >> n2;
|
||||||
BOOST_CHECK(n1 == n2);
|
BOOST_CHECK(n1 == n2);
|
||||||
|
|
||||||
CNodeValue v1(uint256S("0000000000000000000000000000000000000000000000000000000000000001"), 0, 50, 0, 100);
|
CClaimValue v1(uint256S("0000000000000000000000000000000000000000000000000000000000000001"), 0, 50, 0, 100);
|
||||||
CNodeValue v2(uint256S("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), 1, 100, 1, 101);
|
CClaimValue v2(uint256S("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), 1, 100, 1, 101);
|
||||||
|
|
||||||
n1.insertValue(v1);
|
n1.insertClaim(v1);
|
||||||
BOOST_CHECK(n1 != n2);
|
BOOST_CHECK(n1 != n2);
|
||||||
ss << n1;
|
ss << n1;
|
||||||
ss >> n2;
|
ss >> n2;
|
||||||
BOOST_CHECK(n1 == n2);
|
BOOST_CHECK(n1 == n2);
|
||||||
|
|
||||||
n1.insertValue(v2);
|
n1.insertClaim(v2);
|
||||||
BOOST_CHECK(n1 != n2);
|
BOOST_CHECK(n1 != n2);
|
||||||
ss << n1;
|
ss << n1;
|
||||||
ss >> n2;
|
ss >> n2;
|
||||||
BOOST_CHECK(n1 == n2);
|
BOOST_CHECK(n1 == n2);
|
||||||
|
|
||||||
n1.removeValue(v1.txhash, v1.nOut, throwaway);
|
n1.removeClaim(v1.txhash, v1.nOut, throwaway);
|
||||||
BOOST_CHECK(n1 != n2);
|
BOOST_CHECK(n1 != n2);
|
||||||
ss << n1;
|
ss << n1;
|
||||||
ss >> n2;
|
ss >> n2;
|
||||||
BOOST_CHECK(n1 == n2);
|
BOOST_CHECK(n1 == n2);
|
||||||
|
|
||||||
n1.removeValue(v2.txhash, v2.nOut, throwaway);
|
n1.removeClaim(v2.txhash, v2.nOut, throwaway);
|
||||||
BOOST_CHECK(n1 != n2);
|
BOOST_CHECK(n1 != n2);
|
||||||
ss << n1;
|
ss << n1;
|
||||||
ss >> n2;
|
ss >> n2;
|
||||||
|
|
|
@ -80,9 +80,9 @@ class CBlockUndo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::vector<CTxUndo> vtxundo; // for all but the coinbase
|
std::vector<CTxUndo> vtxundo; // for all but the coinbase
|
||||||
CClaimTrieQueueUndo insertUndo; // any claims that went from the queue to the trie
|
claimQueueRowType insertUndo; // any claims that went from the queue to the trie
|
||||||
CClaimTrieQueueUndo expireUndo; // any claims that expired
|
claimQueueRowType expireUndo; // any claims that expired
|
||||||
CSupportValueQueueUndo insertSupportUndo; // any claims that went from the support queue to the support map
|
supportQueueRowType insertSupportUndo; // any claims that went from the support queue to the support map
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue