diff --git a/src/Makefile.am b/src/Makefile.am index e88e21a60..a030b6dc4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -155,6 +155,7 @@ BITCOIN_CORE_H = \ reverse_iterator.h \ reverselock.h \ rpc/blockchain.h \ + rpc/claimrpchelp.h \ rpc/client.h \ rpc/mining.h \ rpc/protocol.h \ diff --git a/src/claimtrie.cpp b/src/claimtrie.cpp index 4c977e7ba..9435610a8 100644 --- a/src/claimtrie.cpp +++ b/src/claimtrie.cpp @@ -391,45 +391,56 @@ bool CClaimTrieCacheBase::getInfoForName(const std::string& name, CClaimValue& c return base->find(name, claims) && claims.getBestClaim(claim); } -CClaimsForNameType CClaimTrieCacheBase::getClaimsForName(const std::string& name) const +template +void CClaimTrieCacheBase::insertRowsFromQueue(std::vector& result, const std::string& name) const +{ + supportedType(); + if (auto nameRows = getQueueCacheNameRow(name)) + for (auto& nameRow : *nameRows) + if (auto rows = getQueueCacheRow(nameRow.nHeight)) + for (auto& row : *rows) + if (row.first == name) + result.push_back(row.second); +} + +CClaimSupportToName CClaimTrieCacheBase::getClaimsForName(const std::string& name) const { claimEntryType claims; int nLastTakeoverHeight = 0; auto supports = getSupportsForName(name); + insertRowsFromQueue(supports, name); - CClaimTrieData data; if (auto it = nodesToAddOrUpdate.find(name)) { claims = it->claims; nLastTakeoverHeight = it->nHeightOfLastTakeover; - } - else if (!nodesToDelete.count(name) && base->find(name, data)) { - claims = data.claims; - nLastTakeoverHeight = data.nHeightOfLastTakeover; - } - return {std::move(claims), std::move(supports), nLastTakeoverHeight, name}; -} - -CAmount CClaimTrieCacheBase::getEffectiveAmountForClaim(const std::string& name, const uint160& claimId, std::vector* supports) const -{ - return getEffectiveAmountForClaim(getClaimsForName(name), claimId, supports); -} - -CAmount CClaimTrieCacheBase::getEffectiveAmountForClaim(const CClaimsForNameType& claims, const uint160& claimId, std::vector* supports) const -{ - CAmount effectiveAmount = 0; - for (const auto& claim : claims.claims) { - if (claim.claimId == claimId && claim.nValidAtHeight < nNextHeight) { - effectiveAmount += claim.nAmount; - for (const auto& support : claims.supports) { - if (support.supportedClaimId == claimId && support.nValidAtHeight < nNextHeight) { - effectiveAmount += support.nAmount; - if (supports) supports->push_back(support); - } - } - break; + } else if (!nodesToDelete.count(name)) { + CClaimTrieData data; + if (base->find(name, data)) { + claims = data.claims; + nLastTakeoverHeight = data.nHeightOfLastTakeover; } } - return effectiveAmount; + insertRowsFromQueue(claims, name); + + auto find = [&supports](decltype(supports)::iterator& it, const CClaimValue& claim) { + it = std::find_if(it, supports.end(), [&claim](const CSupportValue& support) { + return claim.claimId == support.supportedClaimId; + }); + return it != supports.end(); + }; + + // match support to claim + std::vector claimsNsupports; + for (const auto& claim : claims) { + CAmount nAmount = claim.nValidAtHeight < nNextHeight ? claim.nAmount : 0; + auto ic = claimsNsupports.emplace(claimsNsupports.end(), claim, nAmount); + for (auto it = supports.begin(); find(it, claim); it = supports.erase(it)) { + if (it->nValidAtHeight < nNextHeight) + ic->effectiveAmount += it->nAmount; + ic->supports.emplace_back(std::move(*it)); + } + } + return {name, nLastTakeoverHeight, std::move(claimsNsupports), std::move(supports)}; } void completeHash(uint256& partialHash, const std::string& key, std::size_t to) @@ -532,19 +543,6 @@ bool CClaimTrie::find(const std::string& key, CClaimTrieData &data) const { return db->Read(std::make_pair(TRIE_NODE_CLAIMS, key), data); } -bool CClaimTrieCacheBase::getClaimById(const uint160& claimId, std::string& name, CClaimValue& claim) const -{ - CClaimIndexElement element; - if (!base->db->Read(std::make_pair(CLAIM_BY_ID, claimId), element)) - return false; - if (element.claim.claimId == claimId) { - name = element.name; - claim = element.claim; - return true; - } - return false; -} - template void BatchWrite(CDBBatch& batch, uint8_t dbkey, const K& key, const std::vector& value) { diff --git a/src/claimtrie.h b/src/claimtrie.h index 6e360fc64..f4c443ce9 100644 --- a/src/claimtrie.h +++ b/src/claimtrie.h @@ -36,10 +36,10 @@ struct CClaimValue { COutPoint outPoint; uint160 claimId; - CAmount nAmount; - CAmount nEffectiveAmount; - int nHeight; - int nValidAtHeight; + CAmount nAmount = 0; + CAmount nEffectiveAmount = 0; + int nHeight = 0; + int nValidAtHeight = 0; CClaimValue() = default; @@ -94,9 +94,9 @@ struct CSupportValue { COutPoint outPoint; uint160 supportedClaimId; - CAmount nAmount; - int nHeight; - int nValidAtHeight; + CAmount nAmount = 0; + int nHeight = 0; + int nValidAtHeight = 0; CSupportValue() = default; @@ -213,7 +213,7 @@ struct CClaimTrieDataNode { struct COutPointHeightType { COutPoint outPoint; - int nHeight; + int nHeight = 0; COutPointHeightType() = default; @@ -236,7 +236,7 @@ struct CNameOutPointHeightType { std::string name; COutPoint outPoint; - int nHeight; + int nHeight = 0; CNameOutPointHeightType() = default; @@ -305,22 +305,63 @@ struct CClaimIndexElement CClaimValue claim; }; -struct CClaimsForNameType +struct CClaimNsupports { - claimEntryType claims; - supportEntryType supports; - int nLastTakeoverHeight; - std::string name; + CClaimNsupports() = default; + CClaimNsupports(CClaimNsupports&&) = default; + CClaimNsupports(const CClaimNsupports&) = default; - CClaimsForNameType(claimEntryType claims, supportEntryType supports, int nLastTakeoverHeight, std::string name) - : claims(std::move(claims)), supports(std::move(supports)), nLastTakeoverHeight(nLastTakeoverHeight), name(std::move(name)) + CClaimNsupports& operator=(CClaimNsupports&&) = default; + CClaimNsupports& operator=(const CClaimNsupports&) = default; + + CClaimNsupports(const CClaimValue& claim, CAmount effectiveAmount, const std::vector& supports = {}) + : claim(claim), effectiveAmount(effectiveAmount), supports(supports) { } - CClaimsForNameType(CClaimsForNameType&&) = default; - CClaimsForNameType(const CClaimsForNameType&) = default; - CClaimsForNameType& operator=(CClaimsForNameType&&) = default; - CClaimsForNameType& operator=(const CClaimsForNameType&) = default; + bool IsNull() const + { + return claim.claimId.IsNull(); + } + + CClaimValue claim; + CAmount effectiveAmount = 0; + std::vector supports; +}; + +static const CClaimNsupports invalid; + +struct CClaimSupportToName +{ + CClaimSupportToName(const std::string& name, int nLastTakeoverHeight, std::vector claimsNsupports, std::vector unmatchedSupports) + : name(name), nLastTakeoverHeight(nLastTakeoverHeight), claimsNsupports(std::move(claimsNsupports)), unmatchedSupports(std::move(unmatchedSupports)) + { + } + + const CClaimNsupports& find(const uint160& claimId) const + { + auto it = std::find_if(claimsNsupports.begin(), claimsNsupports.end(), [&claimId](const CClaimNsupports& value) { + return claimId == value.claim.claimId; + }); + return it != claimsNsupports.end() ? *it : invalid; + } + + const CClaimNsupports& find(const std::string& partialId) const + { + std::string lowered(partialId); + for (auto& c: lowered) + c = std::tolower(c); + + auto it = std::find_if(claimsNsupports.begin(), claimsNsupports.end(), [&lowered](const CClaimNsupports& value) { + return value.claim.claimId.GetHex().find(lowered) == 0; + }); + return it != claimsNsupports.end() ? *it : invalid; + } + + const std::string name; + const int nLastTakeoverHeight; + const std::vector claimsNsupports; + const std::vector unmatchedSupports; }; class CClaimTrie @@ -341,6 +382,8 @@ public: friend struct ClaimTrieChainFixture; friend class CClaimTrieCacheExpirationFork; friend class CClaimTrieCacheNormalizationFork; + friend bool getClaimById(const uint160&, std::string&, CClaimValue*); + friend bool getClaimById(const std::string&, std::string&, CClaimValue*); std::size_t getTotalNamesInTrie() const; std::size_t getTotalClaimsInTrie() const; @@ -475,8 +518,6 @@ public: uint256 getMerkleHash(); - bool getClaimById(const uint160& claimId, std::string& name, CClaimValue& claim) const; - bool flush(); bool empty() const; bool ReadFromDisk(const CBlockIndex* tip); @@ -517,10 +558,7 @@ public: virtual bool finalizeDecrement(std::vector>& takeoverHeightUndo); - virtual CClaimsForNameType getClaimsForName(const std::string& name) const; - - CAmount getEffectiveAmountForClaim(const std::string& name, const uint160& claimId, std::vector* supports = nullptr) const; - CAmount getEffectiveAmountForClaim(const CClaimsForNameType& claims, const uint160& claimId, std::vector* supports = nullptr) const; + virtual CClaimSupportToName getClaimsForName(const std::string& name) const; CClaimPrefixTrie::const_iterator begin() const; CClaimPrefixTrie::const_iterator end() const; @@ -594,6 +632,9 @@ private: bool validateTrieConsistency(const CBlockIndex* tip); + template + void insertRowsFromQueue(std::vector& result, const std::string& name) const; + template std::vector>* getQueueCacheRow(int nHeight, bool createIfNotExists); @@ -704,7 +745,7 @@ public: bool getProofForName(const std::string& name, CClaimTrieProof& proof) override; bool getInfoForName(const std::string& name, CClaimValue& claim) const override; - CClaimsForNameType getClaimsForName(const std::string& name) const override; + CClaimSupportToName getClaimsForName(const std::string& name) const override; std::string adjustNameForValidHeight(const std::string& name, int validHeight) const override; protected: @@ -733,7 +774,7 @@ public: explicit CClaimTrieCacheHashFork(CClaimTrie* base); bool getProofForName(const std::string& name, CClaimTrieProof& proof) override; - bool getProofForName(const std::string& name, CClaimTrieProof& proof, const uint160& claimId); + bool getProofForName(const std::string& name, CClaimTrieProof& proof, const std::function& comp); void initializeIncrement() override; bool finalizeDecrement(std::vector>& takeoverHeightUndo) override; diff --git a/src/claimtrieforks.cpp b/src/claimtrieforks.cpp index 4c79a885a..def94092f 100644 --- a/src/claimtrieforks.cpp +++ b/src/claimtrieforks.cpp @@ -246,7 +246,7 @@ bool CClaimTrieCacheNormalizationFork::getInfoForName(const std::string& name, C return CClaimTrieCacheExpirationFork::getInfoForName(normalizeClaimName(name), claim); } -CClaimsForNameType CClaimTrieCacheNormalizationFork::getClaimsForName(const std::string& name) const +CClaimSupportToName CClaimTrieCacheNormalizationFork::getClaimsForName(const std::string& name) const { return CClaimTrieCacheExpirationFork::getClaimsForName(normalizeClaimName(name)); } @@ -408,10 +408,10 @@ std::vector ComputeMerklePath(const std::vector& hashes, uint3 bool CClaimTrieCacheHashFork::getProofForName(const std::string& name, CClaimTrieProof& proof) { - return getProofForName(name, proof, uint160()); + return getProofForName(name, proof, nullptr); } -bool CClaimTrieCacheHashFork::getProofForName(const std::string& name, CClaimTrieProof& proof, const uint160& claimId) +bool CClaimTrieCacheHashFork::getProofForName(const std::string& name, CClaimTrieProof& proof, const std::function& comp) { if (nNextHeight < Params().GetConsensus().nAllClaimsInMerkleForkHeight) return CClaimTrieCacheNormalizationFork::getProofForName(name, proof); @@ -445,10 +445,7 @@ bool CClaimTrieCacheHashFork::getProofForName(const std::string& name, CClaimTri if (it.key() == name) { uint32_t nClaimIndex = 0; auto& claims = it->claims; - auto itClaim = claimId.IsNull() ? claims.begin() : - std::find_if(claims.begin(), claims.end(), [&claimId](const CClaimValue& claim) { - return claim.claimId == claimId; - }); + auto itClaim = !comp ? claims.begin() : std::find_if(claims.begin(), claims.end(), comp); if (itClaim != claims.end()) { proof.hasValue = true; proof.outPoint = itClaim->outPoint; diff --git a/src/rpc/claimrpchelp.h b/src/rpc/claimrpchelp.h new file mode 100644 index 000000000..d308bd870 --- /dev/null +++ b/src/rpc/claimrpchelp.h @@ -0,0 +1,345 @@ + +#ifndef CLAIMRPCHELP_H +#define CLAIMRPCHELP_H + +// always keep defines T_ + value in upper case +#define T_NORMALIZEDNAME "normalizedName" +#define T_BLOCKHASH "blockhash" +#define T_CLAIMS "claims" +#define T_CLAIMID "claimId" +#define T_TXID "txId" +#define T_N "n" +#define T_AMOUNT "amount" +#define T_HEIGHT "height" +#define T_VALUE "value" +#define T_NAME "name" +#define T_VALIDATHEIGHT "validAtHeight" +#define T_NAMES "names" +#define T_EFFECTIVEAMOUNT "effectiveAmount" +#define T_LASTTAKEOVERHEIGHT "lastTakeoverHeight" +#define T_SUPPORTS "supports" +#define T_SUPPORTSWITHOUTCLAIM "supportsWithoutClaim" +#define T_TOTALNAMES "totalNames" +#define T_TOTALCLAIMS "totalClaims" +#define T_TOTALVALUE "totalValue" +#define T_CONTROLLINGONLY "controllingOnly" +#define T_CLAIMTYPE "claimType" +#define T_DEPTH "depth" +#define T_INCLAIMTRIE "inClaimTrie" +#define T_ISCONTROLLING "isControlling" +#define T_INSUPPORTMAP "inSupportMap" +#define T_INQUEUE "inQueue" +#define T_BLOCKSTOVALID "blocksToValid" +#define T_NODES "nodes" +#define T_CHILDREN "children" +#define T_CHARACTER "character" +#define T_NODEHASH "nodeHash" +#define T_VALUEHASH "valueHash" +#define T_PAIRS "pairs" +#define T_ODD "odd" +#define T_HASH "hash" +#define T_BID "bid" +#define T_SEQUENCE "sequence" +#define T_CLAIMSADDEDORUPDATED "claimsAddedOrUpdated" +#define T_SUPPORTSADDEDORUPDATED "supportsAddedOrUpdated" +#define T_CLAIMSREMOVED "claimsRemoved" +#define T_SUPPORTSREMOVED "supportsRemoved" +#define T_ADDRESS "address" +#define T_PENDINGAMOUNT "pendingAmount" + +enum { + GETCLAIMSINTRIE = 0, + GETNAMESINTRIE, + GETVALUEFORNAME, + GETCLAIMSFORNAME, + GETCLAIMBYID, + GETTOTALCLAIMEDNAMES, + GETTOTALCLAIMS, + GETTOTALVALUEOFCLAIMS, + GETCLAIMSFORTX, + GETNAMEPROOF, + CHECKNORMALIZATION, + GETCLAIMBYBID, + GETCLAIMBYSEQ, + GETCLAIMPROOFBYBID, + GETCLAIMPROOFBYSEQ, + GETCHANGESINBLOCK, +}; + +#define S3_(pre, name, def) pre "\"" name "\"" def "\n" +#define S3(pre, name, def) S3_(pre, name, def) +#define S1(str) str "\n" + +#define NAME_TEXT " (string) the name to look up" +#define BLOCKHASH_TEXT " (string, optional) get claims in the trie\n" \ +" at the block specified\n" \ +" by this block hash.\n" \ +" If none is given,\n" \ +" the latest active\n" \ +" block will be used." + +#define CLAIM_OUTPUT \ +S3(" ", T_NORMALIZEDNAME, " (string) the name of the claim (after normalization)") \ +S3(" ", T_NAME, " (string) the original name of this claim (before normalization)") \ +S3(" ", T_VALUE, " (string) the value of this claim") \ +S3(" ", T_ADDRESS, " (string) the destination address of this claim") \ +S3(" ", T_CLAIMID, " (string) the claimId of the claim") \ +S3(" ", T_TXID, " (string) the txid of the claim") \ +S3(" ", T_N, " (numeric) the index of the claim in the transaction's list of outputs") \ +S3(" ", T_HEIGHT, " (numeric) the height of the block in which this transaction is located") \ +S3(" ", T_VALIDATHEIGHT, " (numeric) the height at which the support became/becomes valid") \ +S3(" ", T_AMOUNT, " (numeric) the amount of the claim") \ +S3(" ", T_EFFECTIVEAMOUNT, " (numeric) the amount plus amount from all supports associated with the claim") \ +S3(" ", T_PENDINGAMOUNT, " (numeric) expected amount when claim and its supports are all valid") \ +S3(" ", T_SUPPORTS, ": [ (array of object) supports for this claim") \ +S3(" ", T_VALUE, " (string) the metadata of the support if any") \ +S3(" ", T_ADDRESS, " (string) the destination address of the support") \ +S3(" ", T_TXID, " (string) the txid of the support") \ +S3(" ", T_N, " (numeric) the index of the support in the transaction's list of outputs") \ +S3(" ", T_HEIGHT, " (numeric) the height of the block in which this transaction is located") \ +S3(" ", T_VALIDATHEIGHT, " (numeric) the height at which the support became/becomes valid") \ +S3(" ", T_AMOUNT, " (numeric) the amount of the support") \ +S1(" ]") \ +S3(" ", T_LASTTAKEOVERHEIGHT, " (numeric) the last height at which ownership of the name changed") \ +S3(" ", T_BID, " (numeric) lower value means a higher bid rate, ordered by effective amount") \ +S3(" ", T_SEQUENCE, " (numeric) lower value means an older one in sequence, ordered by height of insertion") + +#define PROOF_OUTPUT \ +S3(" ", T_NODES, ": [ (array of object, pre-fork) full nodes\n" \ +" (i.e. those which lead to the requested name)") \ +S3(" ", T_CHILDREN, ": [ (array of object) the children of the node") \ +S3(" ", T_CHARACTER, " (string) the character which leads from the parent to this child node") \ +S3(" ", T_NODEHASH, " (string, if exists) the hash of the node if this is a leaf node") \ +S1(" ]") \ +S3(" ", T_VALUEHASH, " (string, if exists) the hash of this node's value, if" \ +" it has one. If this is the requested name this\n" \ +" will not exist whether the node has a value or not") \ +S1(" ]") \ +S3(" ", T_PAIRS, ": [ (array of pairs, post-fork) hash can be validated by" \ +" hashing claim from the bottom up") \ +S3(" ", T_ODD, " (boolean) this value goes on the right of hash") \ +S3(" ", T_HASH, " (string) the hash to be mixed in") \ +S1(" ]") \ +S3(" ", T_TXID, " (string, if exists) the txid of the claim which controls" \ +" this name, if there is one.") \ +S3(" ", T_N, " (numeric) the index of the claim in the transaction's list of outputs") \ +S3(" ", T_LASTTAKEOVERHEIGHT, " (numeric) the last height at which ownership of the name changed") + +static const char* const rpc_help[] = { + +// GETCLAIMSINTRIE +S1(R"(getclaimsintrie +Return all claims in the name trie. Deprecated +Arguments:)") +S3("1. ", T_BLOCKHASH, BLOCKHASH_TEXT) +S1("Result: [") +S3(" ", T_NORMALIZEDNAME, " (string) the name of the claim(s) (after normalization)") +S3(" ", T_CLAIMS, ": [ (array of object) the claims for this name") +S3(" ", T_NAME, " (string) the original name of this claim (before normalization)") +S3(" ", T_VALUE, " (string) the value of this claim") +S3(" ", T_ADDRESS, " (string) the destination address of this claim") +S3(" ", T_CLAIMID, " (string) the claimId of the claim") +S3(" ", T_TXID, " (string) the txid of the claim") +S3(" ", T_N, " (numeric) the index of the claim in the transaction's list of outputs") +S3(" ", T_HEIGHT, " (numeric) the height of the block in which this transaction is located") +S3(" ", T_VALIDATHEIGHT, " (numeric) the height at which the claim became/becomes valid") +S3(" ", T_AMOUNT, " (numeric) the amount of the claim") +S1(" ]") +"]", + +// GETNAMESINTRIE +S1(R"(getnamesintrie +Return all claim names in the trie. +Arguments:)") +S3("1. ", T_BLOCKHASH, BLOCKHASH_TEXT) +S1("Result: [") +S3(" ", T_NAMES, " all names in the trie that have claims") +"]", + +// GETVALUEFORNAME +S1(R"(getvalueforname +Return the winning or specified by claimId value associated with a name +Arguments:)") +S3("1. ", T_NAME, NAME_TEXT) +S3("2. ", T_BLOCKHASH, BLOCKHASH_TEXT) +S3("3. ", T_CLAIMID, " (string, optional) can be partial one") +S1("Result: [") +CLAIM_OUTPUT +"]", + +// GETCLAIMSFORNAME +S1(R"(getclaimsforname +Return all claims and supports for a name +Arguments:)") +S3("1. ", T_NAME, NAME_TEXT) +S3("2. ", T_BLOCKHASH, BLOCKHASH_TEXT) +S1("Result: [") +S3(" ", T_NORMALIZEDNAME, " (string) the name of the claim(s) (after normalization)") +S3(" ", T_CLAIMS, ": [ (array of object) the claims for this name") +S3(" ", T_NAME, " (string) the original name of this claim (before normalization)") +S3(" ", T_VALUE, " (string) the value of this claim") +S3(" ", T_ADDRESS, " (string) the destination address of this claim") +S3(" ", T_CLAIMID, " (string) the claimId of the claim") +S3(" ", T_TXID, " (string) the txid of the claim") +S3(" ", T_N, " (numeric) the index of the claim in the transaction's list of outputs") +S3(" ", T_HEIGHT, " (numeric) the height of the block in which this transaction is located") +S3(" ", T_VALIDATHEIGHT, " (numeric) the height at which the claim became/becomes valid") +S3(" ", T_AMOUNT, " (numeric) the amount of the claim") +S3(" ", T_EFFECTIVEAMOUNT, " (numeric) the amount plus amount from all supports associated with the claim") +S3(" ", T_PENDINGAMOUNT, " (numeric) expected amount when claim and its support got valid") +S3(" ", T_SUPPORTS, ": [ (array of object) supports for this claim") +S3(" ", T_VALUE, " (string) the metadata of the support if any") +S3(" ", T_ADDRESS, " (string) the destination address of the support") +S3(" ", T_TXID, " (string) the txid of the support") +S3(" ", T_N, " (numeric) the index of the support in the transaction's list of outputs") +S3(" ", T_HEIGHT, " (numeric) the height of the block in which this transaction is located") +S3(" ", T_VALIDATHEIGHT, " (numeric) the height at which the support became/becomes valid") +S3(" ", T_AMOUNT, " (numeric) the amount of the support") +S1(" ]") +S3(" ", T_BID, " (numeric) lower value means a higher bid rate, ordered by effective amount") +S3(" ", T_SEQUENCE, " (numeric) lower value means an older one in sequence, ordered by height of insertion") +S1(" ]") +S3(" ", T_LASTTAKEOVERHEIGHT, " (numeric) the last height at which ownership of the name changed") +S3(" ", T_SUPPORTSWITHOUTCLAIM, ": [") +S3(" ", T_TXID, " (string) the txid of the support") +S3(" ", T_N, " (numeric) the index of the support in the transaction's list of outputs") +S3(" ", T_HEIGHT, " (numeric) the height of the block in which this transaction is located") +S3(" ", T_VALIDATHEIGHT, " (numeric) the height at which the support became/becomes valid") +S3(" ", T_AMOUNT, " (numeric) the amount of the support") +S1(" ]") +"]", + +// GETCLAIMBYID +S1(R"(getclaimbyid +Get a claim by claim id +Arguments:)") +S3("1. ", T_CLAIMID, " (string) the claimId of this claim or patial id (at least 3 chars)") +S1("Result: [") +CLAIM_OUTPUT +"]", + +// GETTOTALCLAIMEDNAMES +S1(R"(gettotalclaimednames +Return the total number of names that have been +Arguments:)") +S1("Result:") +S3(" ", T_TOTALNAMES, " (numeric) the total number of names in the trie") +, + +// GETTOTALCLAIMS +S1(R"(gettotalclaims +Return the total number of active claims in the trie +Arguments:)") +S1("Result:") +S3(" ", T_TOTALCLAIMS, " (numeric) the total number of active claims") +, + +// GETTOTALVALUEOFCLAIMS +S1(R"(gettotalvalueofclaims +Return the total value of the claims in the trie +Arguments:)") +S3("1. ", T_CONTROLLINGONLY, " (boolean) only include the value of controlling claims") +S1("Result:") +S3(" ", T_TOTALVALUE, " (numeric) the total value of the claims in the trie") +, + +// GETCLAIMSFORTX +S1(R"(getclaimsfortx +Return any claims or supports found in a transaction +Arguments:)") +S3("1. ", T_TXID, " (string) the txid of the transaction to check for unspent claims") +S1("Result: [") +S3(" ", T_N, " (numeric) the index of the claim in the transaction's list of outputs") +S3(" ", T_CLAIMTYPE, " (string) claim or support") +S3(" ", T_NAME, " (string) the name claimed or supported") +S3(" ", T_CLAIMID, " (string) if a claim, its ID") +S3(" ", T_VALUE, " (string) if a claim, its value") +S3(" ", T_DEPTH, " (numeric) the depth of the transaction in the main chain") +S3(" ", T_INCLAIMTRIE, " (boolean) if a name claim, whether the claim is active, i.e. has made it into the trie") +S3(" ", T_ISCONTROLLING, " (boolean) if a name claim, whether the claim is the current controlling claim for the name") +S3(" ", T_INSUPPORTMAP, " (boolean) if a support, whether the support is active, i.e. has made it into the support map") +S3(" ", T_INQUEUE, " (boolean) whether the claim is in a queue waiting to be inserted into the trie or support map") +S3(" ", T_BLOCKSTOVALID, " (numeric) if in a queue, the number of blocks until it's inserted into the trie or support map") +"]", + +// GETNAMEPROOF +S1(R"(getnameproof +Return the cryptographic proof that a name maps to a value or doesn't. +Arguments:)") +S3("1. ", T_NAME, NAME_TEXT) +S3("2. ", T_BLOCKHASH, BLOCKHASH_TEXT) +S3("3. ", T_CLAIMID, R"( (string, optional, post-fork) for validating a specific claim + can be partial one)") +S1("Result: [") +PROOF_OUTPUT +"]", + +// CHECKNORMALIZATION +S1(R"(checknormalization +Given an unnormalized name of a claim, return normalized version of it +Arguments:)") +S3("1. ", T_NAME, " (string) the name to normalize") +S1("Result:") +S3(" ", T_NORMALIZEDNAME, " (string) normalized name") +, + +// GETCLAIMBYBID +S1(R"(getclaimbybid +Get a claim by bid +Arguments:)") +S3("1. ", T_NAME, NAME_TEXT) +S3("2. ", T_BID, " (numeric) bid number") +S3("3. ", T_BLOCKHASH, BLOCKHASH_TEXT) +S1("Result: [") +CLAIM_OUTPUT +"]", + +// GETCLAIMBYSEQ +S1(R"(getclaimbyseq +Get a claim by sequence +Arguments:)") +S3("1. ", T_NAME, NAME_TEXT) +S3("2. ", T_SEQUENCE, " (numeric) sequence number") +S3("3. ", T_BLOCKHASH, BLOCKHASH_TEXT) +S1("Result: [") +CLAIM_OUTPUT +"]", + +// GETCLAIMPROOFBYBID +S1(R"(getclaimproofbyid +Return the cryptographic proof that a name maps to a value or doesn't by a bid. +Arguments:)") +S3("1. ", T_NAME, NAME_TEXT) +S3("2. ", T_BID, " (numeric) bid number") +S3("3. ", T_BLOCKHASH, BLOCKHASH_TEXT) +S1("Result: [") +PROOF_OUTPUT +"]", + +// GETCLAIMPROOFBYSEQ +S1(R"(getclaimproofbyseq +Return the cryptographic proof that a name maps to a value or doesn't by a sequence. +Arguments:)") +S3("1. ", T_NAME, NAME_TEXT) +S3("2. ", T_SEQUENCE, " (numeric) sequence number") +S3("3. ", T_BLOCKHASH, BLOCKHASH_TEXT) +S1("Result: [") +PROOF_OUTPUT +"]", + +// GETCHANGESINBLOCK +S1(R"(getchangesinblock +Return the list of claims added, updated, and removed as pulled from the queued work for that block." +Use this method to determine which claims or supports went live on a given block." +Arguments:)") +S3("1. ", T_BLOCKHASH, BLOCKHASH_TEXT) +S1("Result: [") +S3(" ", T_CLAIMSADDEDORUPDATED, " (array of string) claimIDs added or updated in the trie") +S3(" ", T_CLAIMSREMOVED, " (array of string) claimIDs that were removed from the trie") +S3(" ", T_SUPPORTSADDEDORUPDATED, " (array of string) IDs of supports added or updated") +S3(" ", T_SUPPORTSREMOVED, " (array of string) IDs that were removed from the trie") +"]", + +}; + +#endif // CLAIMRPCHELP_H diff --git a/src/rpc/claimtrie.cpp b/src/rpc/claimtrie.cpp index defb31bb9..12e9b5e74 100644 --- a/src/rpc/claimtrie.cpp +++ b/src/rpc/claimtrie.cpp @@ -1,12 +1,16 @@ #include #include #include +#include #include #include +#include #include +#include