Serialize effective amount #231

Closed
bvbfan wants to merge 309 commits from serialize_effective_amount into master
9 changed files with 48 additions and 42 deletions
Showing only changes of commit d3df7747d7 - Show all commits

View file

@ -31,7 +31,7 @@ using namespace std;
class CMainParams : public CChainParams {
public:
CMainParams() {
strNetworkID = "newcc";
strNetworkID = "lbrycrd";
consensus.nSubsidyHalvingInterval = 2100000;
consensus.nMajorityEnforceBlockUpgrade = 750;
consensus.nMajorityRejectBlockOutdated = 950;

View file

@ -279,36 +279,26 @@ CAmount CNCCTrie::getTotalValueOfClaimsRecursive(const CNCCTrieNode* current, bo
return value_in_subtrie;
}
bool CNCCTrie::recursiveDumpToJSON(const std::string& name, const CNCCTrieNode* current, UniValue& ret) const
bool CNCCTrie::recursiveFlattenTrie(const std::string& name, const CNCCTrieNode* current, std::vector<namedNodeType>& nodes) const
{
UniValue objNode(UniValue::VOBJ);
objNode.push_back(Pair("name", name));
objNode.push_back(Pair("hash", current->hash.GetHex()));
CNodeValue val;
if (current->getBestValue(val))
{
objNode.push_back(Pair("txid", val.txhash.GetHex()));
objNode.push_back(Pair("n", (int)val.nOut));
objNode.push_back(Pair("value", val.nAmount));
objNode.push_back(Pair("height", val.nHeight));
}
ret.push_back(objNode);
namedNodeType node(name, *current);
nodes.push_back(node);
for (nodeMapType::const_iterator it = current->children.begin(); it != current->children.end(); ++it)
{
std::stringstream ss;
ss << name << it->first;
if (!recursiveDumpToJSON(ss.str(), it->second, ret))
if (!recursiveFlattenTrie(ss.str(), it->second, nodes))
return false;
}
return true;
}
UniValue CNCCTrie::dumpToJSON() const
std::vector<namedNodeType> CNCCTrie::flattenTrie() const
{
UniValue ret(UniValue::VARR);
if (!recursiveDumpToJSON("", &root, ret))
LogPrintf("%s: Something went wrong dumping to JSON", __func__);
return ret;
std::vector<namedNodeType> nodes;
if (!recursiveFlattenTrie("", &root, nodes))
LogPrintf("%s: Something went wrong flattening the trie", __func__);
return nodes;
}
bool CNCCTrie::getInfoForName(const std::string& name, CNodeValue& val) const

View file

@ -13,7 +13,6 @@
#include <string>
#include <algorithm>
#include <vector>
#include "univalue/univalue.h"
#define DEFAULT_DELAY 100
@ -73,6 +72,8 @@ class CNCCTrie;
typedef std::map<unsigned char, CNCCTrieNode*> nodeMapType;
typedef std::pair<std::string, CNCCTrieNode> namedNodeType;
class CNCCTrieNode
{
public:
@ -155,7 +156,7 @@ public:
bool checkConsistency();
bool WriteToDisk();
bool ReadFromDisk(bool check = false);
UniValue dumpToJSON() const;
std::vector<namedNodeType> flattenTrie() const;
bool getInfoForName(const std::string& name, CNodeValue& val) const;
int nCurrentHeight;
bool queueEmpty() const;
@ -180,7 +181,7 @@ private:
unsigned int getTotalNamesRecursive(const CNCCTrieNode* current) const;
unsigned int getTotalClaimsRecursive(const CNCCTrieNode* current) const;
CAmount getTotalValueOfClaimsRecursive(const CNCCTrieNode* current, bool fControllingOnly) const;
bool recursiveDumpToJSON(const std::string& name, const CNCCTrieNode* current, UniValue& ret) const;
bool recursiveFlattenTrie(const std::string& name, const CNCCTrieNode* current, std::vector<namedNodeType>& nodes) const;
CNCCTrieNode root;
uint256 hashBlock;
valueQueueType dirtyQueueRows;

View file

@ -17,7 +17,7 @@ static const struct {
const char *titleAddText;
} network_styles[] = {
{"main", QAPP_APP_NAME_DEFAULT, 0, 0, ""},
{"newcc", QAPP_APP_NAME_DEFAULT, 0, 0, ""},
{"lbrycrd", QAPP_APP_NAME_DEFAULT, 0, 0, ""},
{"test", QAPP_APP_NAME_TESTNET, 70, 30, QT_TRANSLATE_NOOP("SplashScreen", "[testnet]")},
{"regtest", QAPP_APP_NAME_TESTNET, 160, 30, "[regtest]"}
};

View file

@ -3,12 +3,12 @@
#include "rpcserver.h"
#include "univalue/univalue.h"
UniValue getncctrie(const UniValue& params, bool fHelp)
UniValue getnametrie(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() > 0)
throw std::runtime_error(
"getncctrie\n"
"Return the entire NCC trie.\n"
"getnametrie\n"
"Return the entire name trie.\n"
"Arguments:\n"
"None\n"
"Result: \n"
@ -23,9 +23,24 @@ UniValue getncctrie(const UniValue& params, bool fHelp)
);
LOCK(cs_main);
UniValue ret(UniValue::VARR);
UniValue ret = pnccTrie->dumpToJSON();
std::vector<namedNodeType> nodes = pnccTrie->flattenTrie();
for (std::vector<namedNodeType>::iterator it = nodes.begin(); it != nodes.end(); ++it)
{
UniValue node(UniValue::VOBJ);
node.push_back(Pair("name", it->first));
node.push_back(Pair("hash", it->second.hash.GetHex()));
CNodeValue val;
if (it->second.getBestValue(val))
{
node.push_back(Pair("txid", val.txhash.GetHex()));
node.push_back(Pair("n", (int)val.nOut));
node.push_back(Pair("value", ValueFromAmount(val.nAmount)));
node.push_back(Pair("height", val.nHeight));
}
ret.push_back(node);
}
return ret;
}

View file

@ -380,12 +380,12 @@ static const CRPCCommand vRPCCommands[] =
#endif // ENABLE_WALLET
/* NCC trie */
{ "ncctrie", "getncctrie", &getncctrie, true },
{ "ncctrie", "gettxinfoforname", &gettxinfoforname, true },
{ "ncctrie", "getvalueforname", &getvalueforname, true },
{ "ncctrie", "gettotalclaimednames", &gettotalclaimednames, true },
{ "ncctrie", "gettotalclaims", &gettotalclaims, true },
{ "ncctrie", "gettotalvalueofclaims", &gettotalvalueofclaims, true },
{ "nametrie", "getnametrie", &getnametrie, true },
{ "nametrie", "gettxinfoforname", &gettxinfoforname, true },
{ "nametrie", "getvalueforname", &getvalueforname, true },
{ "nametrie", "gettotalclaimednames", &gettotalclaimednames, true },
{ "nametrie", "gettotalclaims", &gettotalclaims, true },
{ "nametrie", "gettotalvalueofclaims", &gettotalvalueofclaims, true },
};
CRPCTable::CRPCTable()

View file

@ -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 getncctrie(const UniValue& params, bool fHelp); // in rpcncctrie.cpp
extern UniValue getnametrie(const UniValue& params, bool fHelp); // in rpcncctrie.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

@ -416,7 +416,7 @@ boost::filesystem::path GetDefaultDataDir()
return pathRet / "Bitcoin";
#else
// Unix
return pathRet / ".newcc";
return pathRet / ".lbrycrd";
#endif
#endif
}

View file

@ -405,7 +405,7 @@ UniValue claimname(const UniValue& params, bool fHelp)
"\nArguments:\n"
"1. \"name\" (string, required) The name to be assigned the value.\n"
"2. \"value\" (string, required) The value to assign to the name.\n"
"3. \"amount\" (numeric, required) The amount in ncc to send. eg 0.1\n"
"3. \"amount\" (numeric, required) The amount in LBRYcrd to send. eg 0.1\n"
"\nResult:\n"
"\"transactionid\" (string) The transaction id.\n"
);
@ -484,7 +484,7 @@ UniValue updatename(const UniValue& params, bool fHelp)
"\nArguments:\n"
"1. \"txid\" (string, required) The transaction containing the unspent txout which should be spent.\n"
"2. \"value\" (string, required) The value to assign to the name.\n"
"3. \"amount\" (numeric, required) The amount in ncc to send. eg 0.1\n"
"3. \"amount\" (numeric, required) The amount in LBRYcrd to send. eg 0.1\n"
"\nResult:\n"
"\"transactionid\" (string) The new transaction id.\n"
);
@ -663,7 +663,7 @@ void ListNameClaims(const CWalletTx& wtx, const string& strAccount, int nMinDept
entry.push_back(Pair("txid", wtx.GetHash().ToString()));
entry.push_back(Pair("account", strSentAccount));
MaybePushAddress(entry, s.destination);
entry.push_back(Pair("category", "ncc"));
entry.push_back(Pair("category", "name"));
entry.push_back(Pair("amount", ValueFromAmount(s.amount)));
entry.push_back(Pair("vout", s.vout));
entry.push_back(Pair("fee", ValueFromAmount(nFee)));
@ -688,7 +688,7 @@ 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 ncc trie", pnccTrie->haveClaim(sName, wtx.GetHash(), s.vout)));
entry.push_back(Pair("is in name trie", pnccTrie->haveClaim(sName, wtx.GetHash(), s.vout)));
ret.push_back(entry);
}
}
@ -717,7 +717,7 @@ UniValue listnameclaims(const UniValue& params, bool fHelp)
" \"account\":\"accountname\", (string) The account name associated with the transaction. \n"
" It will be \"\" for the default account.\n"
" \"address\":\"bitcoinaddress\", (string) The bitcoin address of the transaction.\n"
" \"category\":\"ncc\" (string) Always ncc\n"
" \"category\":\"name\" (string) Always name\n"
" \"amount\": x.xxx, (numeric) The amount in btc.\n"
" \"vout\": n, (numeric) The vout value\n"
" \"fee\": x.xxx, (numeric) The amount of the fee in btc.\n"