From 40735d9e8fa49707671b69cf1215cb48470ef48e Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Sun, 10 Jul 2016 22:25:24 -0400 Subject: [PATCH 1/7] make regtest generate blocks faster so that tests run in a reasonable amount of time --- src/chainparams.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 10734b969..fcd363a1f 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -291,8 +291,8 @@ public: consensus.BIP34Height = -1; // BIP34 has not necessarily activated on regtest consensus.BIP34Hash = uint256(); consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - consensus.nPowTargetTimespan = 150;//14 * 24 * 60 * 60; // two weeks - consensus.nPowTargetSpacing = 150; + consensus.nPowTargetTimespan = 1;//14 * 24 * 60 * 60; // two weeks + consensus.nPowTargetSpacing = 1; consensus.fPowAllowMinDifficultyBlocks = false; consensus.fPowNoRetargeting = false; consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains -- 2.45.3 From 31008a84b2662adc2469e45c2fd62e2fa88f902d Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Mon, 11 Jul 2016 00:08:01 -0400 Subject: [PATCH 2/7] begin updating wallet rpc to use claimids --- src/wallet/rpcwallet.cpp | 47 ++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index bfa0623fb..6e23e42ff 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -442,7 +442,7 @@ UniValue claimname(const UniValue& params, bool fHelp) } -void UpdateName(const std::vector vchName, const std::vector vchValue, CAmount nAmount, CWalletTx& wtxNew, CWalletTx wtxIn, unsigned int nTxOut) +void UpdateName(const std::vector vchName, const uint160 claimId, const std::vector vchValue, CAmount nAmount, CWalletTx& wtxNew, CWalletTx wtxIn, unsigned int nTxOut) { // Check amount if (nAmount <= 0) @@ -464,8 +464,9 @@ void UpdateName(const std::vector vchName, const std::vectorGetKeyFromPool(newKey)) throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first"); + std::vector vchClaimId(claimId.begin(), claimId.end()); CScript scriptPubKey = GetScriptForDestination(CTxDestination(newKey.GetID())); - CScript claimScript = CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP; + CScript claimScript = CScript() << OP_UPDATE_CLAIM << vchName << vchClaimId << vchValue << OP_2DROP << OP_2DROP; claimScript = claimScript + scriptPubKey; vector vecSend; @@ -501,7 +502,7 @@ UniValue updateclaim(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 LBRYcrd to send. eg 0.1\n" + "3. \"amount\" (numeric, required) The amount in LBRYcrd to use to bid for the name. eg 0.1\n" "\nResult:\n" "\"transactionid\" (string) The new transaction id.\n" ); @@ -523,6 +524,7 @@ UniValue updateclaim(const UniValue& params, bool fHelp) const CWalletTx& wtx = pwalletMain->mapWallet[hash]; int op; std::vector > vvchParams; + uint160 claimId; CWalletTx wtxNew; bool fFound = false; for (unsigned int i = 0; !fFound && i < wtx.vout.size(); i++) @@ -533,7 +535,15 @@ UniValue updateclaim(const UniValue& params, bool fHelp) { vchName = vvchParams[0]; EnsureWalletIsUnlocked(); - UpdateName(vchName, vchValue, nAmount, wtxNew, wtx, i); + if (op == OP_CLAIM_NAME) + { + claimId = ClaimIdHash(wtx.GetHash(), i); + } + else if (op == OP_UPDATE_CLAIM) + { + claimId = uint160(vvchParams[1]); + } + UpdateName(vchName, claimId, vchValue, nAmount, wtxNew, wtx, i); fFound = true; } } @@ -677,15 +687,15 @@ void ListNameClaims(const CWalletTx& wtx, const string& strAccount, int nMinDept entry.push_back(Pair("name", sName)); if (op == OP_CLAIM_NAME) { + uint160 claimId = ClaimIdHash(wtx.GetHash(), s.vout); + entry.push_back(Pair("claimId", claimId.GetHex())); string sValue (vvchParams[1].begin(), vvchParams[1].end()); entry.push_back(Pair("value", sValue)); } else if (op == OP_SUPPORT_CLAIM) { - uint256 txhash(vvchParams[1]); - entry.push_back(Pair("supported_txid", txhash.GetHex())); - int32_t nOut = vch_to_uint32_t(vvchParams[2]); - entry.push_back(Pair("supported_nOut", nOut)); + uint256 claimId(vvchParams[1]); + entry.push_back(Pair("supported_claimid", claimId.GetHex())); } entry.push_back(Pair("txid", wtx.GetHash().ToString())); entry.push_back(Pair("account", strSentAccount)); @@ -748,6 +758,7 @@ UniValue listnameclaims(const UniValue& params, bool fHelp) " {\n" " \"name\":\"claimedname\", (string) The name that is claimed.\n" " \"claimtype\":\"claimtype\", (string) CLAIM or SUPPORT.\n" + " \"claimId\":\"claimId\", (string) The claimId of the claim.\n" " \"value\":\"value\" (string) The value assigned to the name, if claimtype is CLAIM.\n" " \"account\":\"accountname\", (string) The account name associated with the transaction. \n" " It will be \"\" for the default account.\n" @@ -813,34 +824,32 @@ UniValue supportclaim(const UniValue& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - if (fHelp || params.size() != 4) + if (fHelp || params.size() != 3) throw runtime_error( "supportclaim \"name\" \"txid\" nout amount\n" "Increase the value of a claim. Whichever claim has the greatest value, including all support values, will be the authoritative claim, according to the rest of the rules. The name is the name which is claimed by the claim that will be supported, the txid is the txid of the claim that will be supported, nout is the transaction output which contains the claim to be supported, and amount is the amount which will be added to the value of the claim. If the claim is currently the authoritative claim, this support will go into effect immediately. Otherwise, it will go into effect after 100 blocks. The support will be in effect until it is spent, and will lose its effect when the claim is spent or expires. The amount is a real and is rounded to the nearest .00000001\n" + HelpRequiringPassphrase() + "\nArguments:\n" "1. \"name\" (string, required) The name claimed by the claim to support.\n" - "2. \"txid\" (string, required) The transaction id of the claim to support.\n" - "3. \"nout\" (integer, required) The transaction output of the transaction which contains the claim to be supported.\n" - "4. \"amount\" (numeric, required) The amount in LBC to use to support the claim.\n" + "2. \"claimid\" (string, required) The claimid of the claim to support. This can be obtained by TODO PUT IN PLACE THAT SHOWS THIS.\n" + "3. \"amount\" (numeric, required) The amount in LBC to use to support the claim.\n" "\nResult:\n" "\"transactionid\" (string) The transaction id of the support.\n" ); string sName = params[0].get_str(); - string sTxid = params[1].get_str(); - uint256 txid; - txid.SetHex(sTxid); + string sClaimId = params[1].get_str(); + uint160 claimId; + claimId.SetHex(sClaimId); std::vector vchName (sName.begin(), sName.end()); - std::vector vchTxid (txid.begin(), txid.end()); - std::vector vchnOut = uint32_t_to_vch(params[2].get_int()); - CAmount nAmount = AmountFromValue(params[3]); + std::vector vchClaimId (claimId.begin(), claimId.end()); + CAmount nAmount = AmountFromValue(params[2]); CWalletTx wtx; EnsureWalletIsUnlocked(); - CScript supportScript = CScript() << OP_SUPPORT_CLAIM << vchName << vchTxid << vchnOut << OP_2DROP << OP_2DROP; + CScript supportScript = CScript() << OP_SUPPORT_CLAIM << vchName << vchClaimId << OP_2DROP << OP_2DROP; CreateClaim(supportScript, nAmount, wtx); -- 2.45.3 From 0551e881f507f328939e356ad0f5e065aa926417 Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Mon, 11 Jul 2016 23:37:17 -0400 Subject: [PATCH 3/7] fix supports and fix printing of claimid and value for updates --- src/rpc/claimtrie.cpp | 10 +++++++++- src/wallet/rpcwallet.cpp | 11 +++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/rpc/claimtrie.cpp b/src/rpc/claimtrie.cpp index 1307a1c6f..38c178127 100644 --- a/src/rpc/claimtrie.cpp +++ b/src/rpc/claimtrie.cpp @@ -164,7 +164,15 @@ UniValue getvalueforname(const UniValue& params, bool fHelp) { LogPrintf("%s: the specified txout of %s does not have a name claim command\n", __func__, claim.outPoint.hash.GetHex()); } - std::string sValue(vvchParams[1].begin(), vvchParams[1].end()); + std::string sValue; + if (op == OP_CLAIM_NAME) + { + sValue = std::string(vvchParams[1].begin(), vvchParams[1].end()); + } + else if (op == OP_UPDATE_CLAIM) + { + sValue = std::string(vvchParams[2].begin(), vvchParams[2].end()); + } ret.push_back(Pair("value", sValue)); ret.push_back(Pair("txid", claim.outPoint.hash.GetHex())); ret.push_back(Pair("n", (int)claim.outPoint.n)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6e23e42ff..5b9d2b51e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -692,9 +692,16 @@ void ListNameClaims(const CWalletTx& wtx, const string& strAccount, int nMinDept string sValue (vvchParams[1].begin(), vvchParams[1].end()); entry.push_back(Pair("value", sValue)); } + else if (op == OP_UPDATE_CLAIM) + { + uint160 claimId(vvchParams[1]); + entry.push_back(Pair("claimId", claimId.GetHex())); + string sValue(vvchParams[2].begin(), vvchParams[2].end()); + entry.push_back(Pair("value", sValue)); + } else if (op == OP_SUPPORT_CLAIM) { - uint256 claimId(vvchParams[1]); + uint160 claimId(vvchParams[1]); entry.push_back(Pair("supported_claimid", claimId.GetHex())); } entry.push_back(Pair("txid", wtx.GetHash().ToString())); @@ -849,7 +856,7 @@ UniValue supportclaim(const UniValue& params, bool fHelp) EnsureWalletIsUnlocked(); - CScript supportScript = CScript() << OP_SUPPORT_CLAIM << vchName << vchClaimId << OP_2DROP << OP_2DROP; + CScript supportScript = CScript() << OP_SUPPORT_CLAIM << vchName << vchClaimId << OP_2DROP << OP_DROP; CreateClaim(supportScript, nAmount, wtx); -- 2.45.3 From e713501a5d56ce7281fbb642d0bf56f6d70889b2 Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Thu, 14 Jul 2016 23:11:31 -0400 Subject: [PATCH 4/7] start making getclaimsforname rpc command --- src/claimtrie.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++ src/claimtrie.h | 12 ++++++++ src/rpc/claimtrie.cpp | 29 +++++++++++++++++++ 3 files changed, 108 insertions(+) diff --git a/src/claimtrie.cpp b/src/claimtrie.cpp index 1473ef59c..5bc04348a 100644 --- a/src/claimtrie.cpp +++ b/src/claimtrie.cpp @@ -458,6 +458,73 @@ bool CClaimTrie::getLastTakeoverForName(const std::string& name, int& lastTakeov return false; } +claimsForNameType CClaimTrie::getClaimsForName(const std::string& name) const +{ + std::vector claims; + std::vector supports; + int nLastTakeoverHeight = 0; + const CClaimTrieNode* current = getNodeForName(name); + if (current) + { + if (!current->claims.empty()) + { + nLastTakeoverHeight = current->nHeightOfLastTakeover; + } + for (std::vector::const_iterator itClaims = current->claims.begin(); itClaims != current->claims.end(); ++itClaims) + { + claims.push_back(*itClaims); + } + } + supportMapEntryType supportNode; + if (getSupportNode(name, supportNode)) + { + for (std::vector::const_iterator itSupports = supportNode.begin(); itSupports != supportNode.end(); ++itSupports) + { + supports.push_back(*itSupports); + } + } + queueNameRowType namedClaimRow; + if (getQueueNameRow(name, namedClaimRow)) + { + for (queueNameRowType::const_iterator itClaimsForName = namedClaimRow.begin(); itClaimsForName != namedClaimRow.end(); ++itClaimsForName) + { + claimQueueRowType claimRow; + if (getQueueRow(itClaimsForName->nHeight, claimRow)) + { + for (claimQueueRowType::const_iterator itClaimRow = claimRow.begin(); itClaimRow != claimRow.end(); ++itClaimRow) + { + if (itClaimRow->first == name && itClaimRow->second.outPoint == itClaimsForName->outPoint) + { + claims.push_back(itClaimRow->second); + break; + } + } + } + } + } + queueNameRowType namedSupportRow; + if (getSupportQueueNameRow(name, namedSupportRow)) + { + for (queueNameRowType::const_iterator itSupportsForName = namedSupportRow.begin(); itSupportsForName != namedSupportRow.end(); ++itSupportsForName) + { + supportQueueRowType supportRow; + if (getSupportQueueRow(itSupportsForName->nHeight, supportRow)) + { + for (supportQueueRowType::const_iterator itSupportRow = supportRow.begin(); itSupportRow != supportRow.end(); ++itSupportRow) + { + if (itSupportRow->first == name && itSupportRow->second.outPoint == itSupportsForName->outPoint) + { + supports.push_back(itSupportRow->second); + break; + } + } + } + } + } + claimsForNameType allClaims(claims, supports, nLastTakeoverHeight); + return allClaims; +} + bool CClaimTrie::checkConsistency() const { if (empty()) diff --git a/src/claimtrie.h b/src/claimtrie.h index 6cd28b7b2..6d6396ba7 100644 --- a/src/claimtrie.h +++ b/src/claimtrie.h @@ -265,6 +265,16 @@ typedef std::map nodeCacheType; typedef std::map hashMapType; +struct claimsForNameType +{ + std::vector claims; + std::vector supports; + int nLastTakeoverHeight; + + claimsForNameType(std::vector claims, std::vector supports, int nLastTakeoverHeight) + : claims(claims), supports(supports), nLastTakeoverHeight(nLastTakeoverHeight) {} +}; + class CClaimTrieCache; class CClaimTrie @@ -290,6 +300,8 @@ public: std::vector flattenTrie() const; bool getInfoForName(const std::string& name, CClaimValue& claim) const; bool getLastTakeoverForName(const std::string& name, int& lastTakeoverHeight) const; + + claimsForNameType getClaimsForName(const std::string& name) const; bool queueEmpty() const; bool supportEmpty() const; diff --git a/src/rpc/claimtrie.cpp b/src/rpc/claimtrie.cpp index 38c178127..da2289ba9 100644 --- a/src/rpc/claimtrie.cpp +++ b/src/rpc/claimtrie.cpp @@ -181,6 +181,34 @@ UniValue getvalueforname(const UniValue& params, bool fHelp) return ret; } +UniValue getclaimsforname(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw std::runtime_error( + "getclaimsforname\n" + "Return a whole bunch of stuff, I tell you what" + ); + + LOCK(cs_main); + std::string name = params[0].get_str(); + claimsForNameType claimsForName = pclaimTrie->getClaimsForName(name); + UniValue ret(UniValue::VARR); + for (std::vector::const_iterator itClaims = claimsForName.claims.begin(); itClaims != claimsForName.claims.end(); ++itClaims) + { + UniValue claim(UniValue::VOBJ); + claim.push_back(Pair("txid", itClaims->outPoint.hash.GetHex())); + ret.push_back(claim); + } + for (std::vector::const_iterator itSupports = claimsForName.supports.begin(); itSupports != claimsForName.supports.end(); ++itSupports) + { + UniValue support(UniValue::VOBJ); + support.push_back(Pair("txid", itSupports->outPoint.hash.GetHex())); + ret.push_back(support); + } + return ret; +} + + UniValue gettotalclaimednames(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 0) @@ -535,6 +563,7 @@ static const CRPCCommand commands[] = { "Claimtrie", "getclaimsintrie", &getclaimsintrie, true }, { "Claimtrie", "getclaimtrie", &getclaimtrie, true }, { "Claimtrie", "getvalueforname", &getvalueforname, true }, + { "Claimtrie", "getclaimsforname", &getclaimsforname, true }, { "Claimtrie", "gettotalclaimednames", &gettotalclaimednames, true }, { "Claimtrie", "gettotalclaims", &gettotalclaims, true }, { "Claimtrie", "gettotalvalueofclaims", &gettotalvalueofclaims, true }, -- 2.45.3 From 80bb42c9126d2047b0b49bead721c88b2d8134ed Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Mon, 18 Jul 2016 22:37:30 -0400 Subject: [PATCH 5/7] make getclaimsforname show useful info and group together supports --- src/rpc/claimtrie.cpp | 165 +++++++++++++++++++++++++++++++++--------- 1 file changed, 130 insertions(+), 35 deletions(-) diff --git a/src/rpc/claimtrie.cpp b/src/rpc/claimtrie.cpp index da2289ba9..d61a6ea62 100644 --- a/src/rpc/claimtrie.cpp +++ b/src/rpc/claimtrie.cpp @@ -123,6 +123,41 @@ UniValue getclaimtrie(const UniValue& params, bool fHelp) return ret; } +bool getValueForClaim(const COutPoint& out, std::string& sValue) +{ + CCoinsViewCache view(pcoinsTip); + const CCoins* coin = view.AccessCoins(out.hash); + if (!coin) + { + LogPrintf("%s: %s does not exist in the coins view, despite being associated with a name\n", + __func__, out.hash.GetHex()); + return true; + } + if (coin->vout.size() < out.n || coin->vout[out.n].IsNull()) + { + LogPrintf("%s: the specified txout of %s appears to have been spent\n", __func__, out.hash.GetHex()); + return true; + } + + int op; + std::vector > vvchParams; + if (!DecodeClaimScript(coin->vout[out.n].scriptPubKey, op, vvchParams)) + { + LogPrintf("%s: the specified txout of %s does not have a name claim command\n", __func__, out.hash.GetHex()); + return false; + } + if (op == OP_CLAIM_NAME) + { + sValue = std::string(vvchParams[1].begin(), vvchParams[1].end()); + } + else if (op == OP_UPDATE_CLAIM) + { + sValue = std::string(vvchParams[2].begin(), vvchParams[2].end()); + } + return true; +} + + UniValue getvalueforname(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 1) @@ -144,35 +179,9 @@ UniValue getvalueforname(const UniValue& params, bool fHelp) UniValue ret(UniValue::VOBJ); if (!pclaimTrie->getInfoForName(name, claim)) return ret; - CCoinsViewCache view(pcoinsTip); - const CCoins* coin = view.AccessCoins(claim.outPoint.hash); - if (!coin) - { - LogPrintf("%s: %s does not exist in the coins view, despite being associated with a name\n", - __func__, claim.outPoint.hash.GetHex()); - return ret; - } - if (coin->vout.size() < claim.outPoint.n || coin->vout[claim.outPoint.n].IsNull()) - { - LogPrintf("%s: the specified txout of %s appears to have been spent\n", __func__, claim.outPoint.hash.GetHex()); - return ret; - } - - int op; - std::vector > vvchParams; - if (!DecodeClaimScript(coin->vout[claim.outPoint.n].scriptPubKey, op, vvchParams)) - { - LogPrintf("%s: the specified txout of %s does not have a name claim command\n", __func__, claim.outPoint.hash.GetHex()); - } std::string sValue; - if (op == OP_CLAIM_NAME) - { - sValue = std::string(vvchParams[1].begin(), vvchParams[1].end()); - } - else if (op == OP_UPDATE_CLAIM) - { - sValue = std::string(vvchParams[2].begin(), vvchParams[2].end()); - } + if (!getValueForClaim(claim.outPoint, sValue)) + return ret; ret.push_back(Pair("value", sValue)); ret.push_back(Pair("txid", claim.outPoint.hash.GetHex())); ret.push_back(Pair("n", (int)claim.outPoint.n)); @@ -181,6 +190,72 @@ UniValue getvalueforname(const UniValue& params, bool fHelp) return ret; } +typedef std::pair > claimAndSupportsType; +typedef std::map claimSupportMapType; +typedef std::map > supportsWithoutClaimsMapType; + +UniValue claimsAndSupportsToJSON(claimSupportMapType::const_iterator itClaimsAndSupports, int nCurrentHeight) +{ + UniValue ret(UniValue::VOBJ); + const CClaimValue claim = itClaimsAndSupports->second.first; + const std::vector supports = itClaimsAndSupports->second.second; + CAmount nEffectiveAmount = 0; + UniValue supportObjs(UniValue::VARR); + for (std::vector::const_iterator itSupports = supports.begin(); itSupports != supports.end(); ++itSupports) + { + UniValue supportObj(UniValue::VOBJ); + supportObj.push_back(Pair("txid", itSupports->outPoint.hash.GetHex())); + supportObj.push_back(Pair("n", (int)itSupports->outPoint.n)); + supportObj.push_back(Pair("nHeight", itSupports->nHeight)); + supportObj.push_back(Pair("nValidAtHeight", itSupports->nValidAtHeight)); + if (itSupports->nValidAtHeight < nCurrentHeight) + { + nEffectiveAmount += itSupports->nAmount; + } + supportObj.push_back(Pair("nAmount", itSupports->nAmount)); + supportObjs.push_back(supportObj); + } + ret.push_back(Pair("claimId", itClaimsAndSupports->first.GetHex())); + ret.push_back(Pair("txid", claim.outPoint.hash.GetHex())); + ret.push_back(Pair("n", (int)claim.outPoint.n)); + ret.push_back(Pair("nHeight", claim.nHeight)); + ret.push_back(Pair("nValidAtHeight", claim.nValidAtHeight)); + if (claim.nValidAtHeight < nCurrentHeight) + { + nEffectiveAmount += claim.nAmount; + } + ret.push_back(Pair("nAmount", claim.nAmount)); + std::string sValue; + if (getValueForClaim(claim.outPoint, sValue)) + { + ret.push_back(Pair("value", sValue)); + } + ret.push_back(Pair("nEffectiveAmount", nEffectiveAmount)); + ret.push_back(Pair("supports", supportObjs)); + + return ret; +} + +UniValue supportsWithoutClaimsToJSON(supportsWithoutClaimsMapType::const_iterator itSupportsWithoutClaims, int nCurrentHeight) +{ + const std::vector supports = itSupportsWithoutClaims->second; + UniValue ret(UniValue::VOBJ); + UniValue supportObjs(UniValue::VARR); + ret.push_back(Pair("claimId (no matching claim)", itSupportsWithoutClaims->first.GetHex())); + for (std::vector::const_iterator itSupports = supports.begin(); itSupports != supports.end(); ++itSupports) + { + UniValue supportObj(UniValue::VOBJ); + supportObj.push_back(Pair("txid", itSupports->outPoint.hash.GetHex())); + supportObj.push_back(Pair("n", (int)itSupports->outPoint.n)); + supportObj.push_back(Pair("nHeight", itSupports->nHeight)); + supportObj.push_back(Pair("nValidAtHeight", itSupports->nValidAtHeight)); + supportObj.push_back(Pair("nAmount", itSupports->nAmount)); + supportObjs.push_back(supportObj); + } + ret.push_back(Pair("supports", supportObjs)); + return ret; +} + UniValue getclaimsforname(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 1) @@ -192,18 +267,38 @@ UniValue getclaimsforname(const UniValue& params, bool fHelp) LOCK(cs_main); std::string name = params[0].get_str(); claimsForNameType claimsForName = pclaimTrie->getClaimsForName(name); - UniValue ret(UniValue::VARR); + int nCurrentHeight = chainActive.Height(); + + claimSupportMapType claimSupportMap; + supportsWithoutClaimsMapType supportsWithoutClaims; for (std::vector::const_iterator itClaims = claimsForName.claims.begin(); itClaims != claimsForName.claims.end(); ++itClaims) { - UniValue claim(UniValue::VOBJ); - claim.push_back(Pair("txid", itClaims->outPoint.hash.GetHex())); - ret.push_back(claim); + claimAndSupportsType claimAndSupports = std::make_pair(*itClaims, std::vector()); + claimSupportMap.insert(std::pair(itClaims->claimId, claimAndSupports)); } for (std::vector::const_iterator itSupports = claimsForName.supports.begin(); itSupports != claimsForName.supports.end(); ++itSupports) { - UniValue support(UniValue::VOBJ); - support.push_back(Pair("txid", itSupports->outPoint.hash.GetHex())); - ret.push_back(support); + claimSupportMapType::iterator itClaimAndSupports = claimSupportMap.find(itSupports->supportedClaimId); + if (itClaimAndSupports == claimSupportMap.end()) + { + std::pair ret = supportsWithoutClaims.insert(std::pair >(itSupports->supportedClaimId, std::vector())); + ret.first->second.push_back(*itSupports); + } + else + { + itClaimAndSupports->second.second.push_back(*itSupports); + } + } + UniValue ret(UniValue::VARR); + for (claimSupportMapType::const_iterator itClaimsAndSupports = claimSupportMap.begin(); itClaimsAndSupports != claimSupportMap.end(); ++itClaimsAndSupports) + { + UniValue claimAndSupportsObj = claimsAndSupportsToJSON(itClaimsAndSupports, nCurrentHeight); + ret.push_back(claimAndSupportsObj); + } + for (supportsWithoutClaimsMapType::const_iterator itSupportsWithoutClaims = supportsWithoutClaims.begin(); itSupportsWithoutClaims != supportsWithoutClaims.end(); ++itSupportsWithoutClaims) + { + UniValue supportsObj = supportsWithoutClaimsToJSON(itSupportsWithoutClaims, nCurrentHeight); + ret.push_back(supportsObj); } return ret; } -- 2.45.3 From a186aaa073f01fe29bf8e7f8b35ade7243beb268 Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Mon, 18 Jul 2016 23:29:41 -0400 Subject: [PATCH 6/7] put useful documentation, also report the last takeover height --- src/rpc/claimtrie.cpp | 46 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/rpc/claimtrie.cpp b/src/rpc/claimtrie.cpp index d61a6ea62..cdbc82cb3 100644 --- a/src/rpc/claimtrie.cpp +++ b/src/rpc/claimtrie.cpp @@ -261,7 +261,40 @@ UniValue getclaimsforname(const UniValue& params, bool fHelp) if (fHelp || params.size() != 1) throw std::runtime_error( "getclaimsforname\n" - "Return a whole bunch of stuff, I tell you what" + "Return all claims and supports for a name\n" + "Arguments: \n" + "1. \"name\" (string) the name for which to get claims and supports\n" + "Result:\n" + "{\n" + " \"nLastTakeoverheight\" (numeric) the last height at which ownership of the name changed\n" + " \"claims\": [ (array of object) claims for this name\n" + " {\n" + " \"claimId\" (string) the claimId of this claim\n" + " \"txid\" (string) the txid of this claim\n" + " \"n\" (numeric) the index of the claim in the transaction's list of outputs\n" + " \"nHeight\" (numeric) the height at which the claim was included in the blockchain\n" + " \"nValidAtHeight\" (numeric) the height at which the claim became/becomes valid\n" + " \"nAmount\" (numeric) the amount of the claim\n" + " \"nEffectiveAmount\" (numeric) the total effective amount of the claim, taking into effect whether the claim or support has reached its nValidAtHeight\n" + " \"supports\" : [ (array of object) supports for this claim\n" + " \"txid\" (string) the txid of the support\n" + " \"n\" (numeric) the index of the support in the transaction's list of outputs\n" + " \"nHeight\" (numeric) the height at which the support was included in the blockchain\n" + " \"nValidAtHeight\" (numeric) the height at which the support became/becomes valid\n" + " \"nAmount\" (numeric) the amount of the support\n" + " ]\n" + " }\n" + " ],\n" + " \"unmatched supports\": [ (array of object) supports that did not match a claim for this name\n" + " {\n" + " \"txid\" (string) the txid of the support\n" + " \"n\" (numeric) the index of the support in the transaction's list of outputs\n" + " \"nHeight\" (numeric) the height at which the support was included in the blockchain\n" + " \"nValidAtHeight\" (numeric) the height at which the support became/becomes valid\n" + " \"nAmount\" (numeric) the amount of the support\n" + " }\n" + " ]\n" + "}\n" ); LOCK(cs_main); @@ -289,17 +322,22 @@ UniValue getclaimsforname(const UniValue& params, bool fHelp) itClaimAndSupports->second.second.push_back(*itSupports); } } - UniValue ret(UniValue::VARR); + UniValue ret(UniValue::VOBJ); + UniValue claimObjs(UniValue::VARR); + ret.push_back(Pair("nLastTakeoverHeight", claimsForName.nLastTakeoverHeight)); for (claimSupportMapType::const_iterator itClaimsAndSupports = claimSupportMap.begin(); itClaimsAndSupports != claimSupportMap.end(); ++itClaimsAndSupports) { UniValue claimAndSupportsObj = claimsAndSupportsToJSON(itClaimsAndSupports, nCurrentHeight); - ret.push_back(claimAndSupportsObj); + claimObjs.push_back(claimAndSupportsObj); } + ret.push_back(Pair("claims", claimObjs)); + UniValue unmatchedSupports(UniValue::VARR); for (supportsWithoutClaimsMapType::const_iterator itSupportsWithoutClaims = supportsWithoutClaims.begin(); itSupportsWithoutClaims != supportsWithoutClaims.end(); ++itSupportsWithoutClaims) { UniValue supportsObj = supportsWithoutClaimsToJSON(itSupportsWithoutClaims, nCurrentHeight); - ret.push_back(supportsObj); + unmatchedSupports.push_back(supportsObj); } + ret.push_back(Pair("supports without claims", unmatchedSupports)); return ret; } -- 2.45.3 From ec3801f07aa36c0817bd68b22c3663b71fe5a799 Mon Sep 17 00:00:00 2001 From: kkurokawa Date: Mon, 1 Aug 2016 21:31:20 -0400 Subject: [PATCH 7/7] fixing listclaimnames not showing supports, updating help messages for rpc commands --- src/wallet/rpcwallet.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5b9d2b51e..ebc7729f8 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -678,7 +678,8 @@ void ListNameClaims(const CWalletTx& wtx, const string& strAccount, int nMinDept LogPrintf("%s(): Txout classified as name claim could not be decoded. Txid: %s", __func__, wtx.GetHash().ToString()); continue; } - else if (((op == OP_CLAIM_NAME) && (vvchParams.size() != 2)) || ((op == OP_SUPPORT_CLAIM) && (vvchParams.size() != 3))) + else if (((op == OP_CLAIM_NAME || op == OP_SUPPORT_CLAIM) && (vvchParams.size() != 2)) || + ((op == OP_UPDATE_CLAIM) && (vvchParams.size() != 3))) { LogPrintf("%s(): Wrong number of params to name claim script. Got %d, expected %d. Txid: %s", __func__, vvchParams.size(), ((op == OP_CLAIM_NAME) ? 2 : 3), wtx.GetHash().ToString()); continue; @@ -754,7 +755,7 @@ UniValue listnameclaims(const UniValue& params, bool fHelp) if (fHelp || params.size() > 3) throw runtime_error( - "listnameclaims activeonly minconf\n" + "listnameclaims includesuppports activeonly minconf\n" "Return a list of all transactions claiming names.\n" "\nArguments\n" "1. includesupports (bool, optional) Whether to also include claim supports. Default is true.\n" @@ -833,7 +834,7 @@ UniValue supportclaim(const UniValue& params, bool fHelp) if (fHelp || params.size() != 3) throw runtime_error( - "supportclaim \"name\" \"txid\" nout amount\n" + "supportclaim \"name\" \"claimid\" \"amount\"\n" "Increase the value of a claim. Whichever claim has the greatest value, including all support values, will be the authoritative claim, according to the rest of the rules. The name is the name which is claimed by the claim that will be supported, the txid is the txid of the claim that will be supported, nout is the transaction output which contains the claim to be supported, and amount is the amount which will be added to the value of the claim. If the claim is currently the authoritative claim, this support will go into effect immediately. Otherwise, it will go into effect after 100 blocks. The support will be in effect until it is spent, and will lose its effect when the claim is spent or expires. The amount is a real and is rounded to the nearest .00000001\n" + HelpRequiringPassphrase() + "\nArguments:\n" -- 2.45.3