From d84f1e5e9daaa62a27e7ee4c32235fa4af39378e Mon Sep 17 00:00:00 2001 From: levonpetrosyan93 Date: Wed, 5 Jun 2024 06:31:00 +0400 Subject: [PATCH 1/7] Mobile mempool support --- src/rpc/misc.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++++ src/rpc/server.cpp | 3 ++ src/rpc/server.h | 2 + 3 files changed, 101 insertions(+) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index ad96886540..d65ed5340a 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1431,6 +1431,100 @@ UniValue getsparklatestcoinid(const JSONRPCRequest& request) return UniValue(latestCoinId); } +UniValue getmempooltxids(const JSONRPCRequest& request) +{ + if (request.fHelp || request.params.size() != 0) + throw std::runtime_error( + "getmempooltxids\n" + "\nReturns all mempool transaction ids.\n" + ); + + UniValue result(UniValue::VARR); + std::vector txs = mempool.infoAll(); + for (auto it = txs.begin(); it != txs.end(); it++) { + if (!it->tx->IsSparkTransaction()) + continue; + UniValue txid(UniValue::VOBJ); + txid.push_back(EncodeBase64(it->tx->GetHash().begin(), it->tx->GetHash().size())); + result.push_back(txid); + } + + return result; +} + +UniValue getmempooltxs(const JSONRPCRequest& request) +{ + if (request.fHelp || request.params.size() != 1) + throw std::runtime_error( + "getmempooltxs\n" + "\nReturns spark data for each transaction.\n" + "\nArguments:\n" + " \"txids\"\n" + " [\n" + " {\n" + " \"txid\" (string) The transaction hash\n" + " }\n" + " ,...\n" + " ]\n" + "\nResult:\n" + "{\n" + " \"txdata\" (Pair) nHeight and id for each coin\n" + "}\n" + + HelpExampleCli("getmempooltxs", "'{[\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\",\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"]}'") + + HelpExampleRpc("getmempooltxs", "{[\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\",\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"]}") + + ); + + UniValue txids = request.params[0].get_obj(); + + UniValue result(UniValue::VARR); + for(UniValue const & element : txids.getValues()){ + uint256 txid; + txid.SetHex(element.get_str()); + CTransactionRef tx = mempool.get(txid); + if (tx == nullptr || !tx->IsSparkTransaction()) + continue; + + UniValue data(UniValue::VARR); + std::vector lTags_; + if (tx->IsSparkSpend()) + { + try { + spark::SpendTransaction spend = spark::ParseSparkSpend(*tx); + auto lTags = spend.getUsedLTags(); + for ( auto it = lTags.begin(); it != lTags.end(); ++it) { + std::vector serialized; + serialized.resize(34); + it->serialize(serialized.data()); + lTags_.push_back(EncodeBase64(serialized.data(), 34)); + } + } catch (const std::exception &) { + continue; + } + } else { + lTags_.push_back("MintTX"); + } + data.push_backV(lTags_); // Spend lTags for corresponding tx, + + std::vector serial_context = spark::getSerialContext(*tx); + data.push_back(EncodeBase64(serial_context.data(), serial_context.size())); // spark serial context + + + std::vector coins = spark::GetSparkMintCoins(*tx); + std::vector serialized_coins; + for (auto& coin: coins) { + CDataStream serializedCoin(SER_NETWORK, PROTOCOL_VERSION); + serializedCoin << coin; + std::vector vch(serializedCoin.begin(), serializedCoin.end()); + serialized_coins.push_back(EncodeBase64(vch.data(), size_t(vch.size()))); // coi + } + data.push_backV(serialized_coins); + result.push_back(Pair(EncodeBase64(txid.begin(), txid.size()), data)); + } + + return result; +} + UniValue checkifmncollateral(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() != 2) @@ -1763,6 +1857,8 @@ static const CRPCCommand commands[] = { "mobile", "getsparkmintmetadata", &getsparkmintmetadata, true }, { "mobile", "getusedcoinstags", &getusedcoinstags, false }, { "mobile", "getsparklatestcoinid", &getsparklatestcoinid, true }, + { "mobile", "getmempooltxids", &getmempooltxids, true }, + { "mobile", "getmempooltxs", &getmempooltxs, true }, { "mobile", "checkifmncollateral", &checkifmncollateral, false }, diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 04870a06bc..0b6a580b20 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -343,6 +343,9 @@ static const CRPCCommand vRPCCommands[] = { "mobile", "getsparkmintmetadata", &getsparkmintmetadata, true }, { "mobile", "getusedcoinstags", &getusedcoinstags, false }, { "mobile", "getsparklatestcoinid", &getsparklatestcoinid, true }, + { "mobile", "getmempooltxids", &getmempooltxids, true }, + { "mobile", "getmempooltxs", &getmempooltxs, true }, + { "mobile", "checkifmncollateral", &checkifmncollateral, false }, diff --git a/src/rpc/server.h b/src/rpc/server.h index b16f0f4e95..1f1e142929 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -217,6 +217,8 @@ extern UniValue getsparkanonymityset(const JSONRPCRequest& params); extern UniValue getsparkmintmetadata(const JSONRPCRequest& params); extern UniValue getusedcoinstags(const JSONRPCRequest& params); extern UniValue getsparklatestcoinid(const JSONRPCRequest& params); +extern UniValue getmempooltxids(const JSONRPCRequest& params); +extern UniValue getmempooltxs(const JSONRPCRequest& params); extern UniValue checkifmncollateral(const JSONRPCRequest& params); From ef9390857d7821c8ff9f5afda9b8d1f664b7ddb3 Mon Sep 17 00:00:00 2001 From: levonpetrosyan93 Date: Sat, 8 Jun 2024 01:32:35 +0400 Subject: [PATCH 2/7] getmempooltxids bug fixed --- src/rpc/misc.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index d65ed5340a..521ee71a0a 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1444,9 +1444,7 @@ UniValue getmempooltxids(const JSONRPCRequest& request) for (auto it = txs.begin(); it != txs.end(); it++) { if (!it->tx->IsSparkTransaction()) continue; - UniValue txid(UniValue::VOBJ); - txid.push_back(EncodeBase64(it->tx->GetHash().begin(), it->tx->GetHash().size())); - result.push_back(txid); + result.push_back(EncodeBase64(it->tx->GetHash().begin(), it->tx->GetHash().size())); } return result; From 40d9bf05b47cf766d83eefd33acbe96e632bf6f8 Mon Sep 17 00:00:00 2001 From: levonpetrosyan93 Date: Sun, 9 Jun 2024 05:33:38 +0400 Subject: [PATCH 3/7] Tx ids with lTags --- src/chain.h | 4 ++++ src/rpc/misc.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++ src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/spark/state.cpp | 24 ++++++++++++++++++- src/spark/state.h | 5 ++++ src/txdb.cpp | 1 + 7 files changed, 93 insertions(+), 1 deletion(-) diff --git a/src/chain.h b/src/chain.h index c6fc34832c..a62f14cb41 100644 --- a/src/chain.h +++ b/src/chain.h @@ -261,6 +261,8 @@ class CBlockIndex sigma::spend_info_container sigmaSpentSerials; std::unordered_map lelantusSpentSerials; std::unordered_map spentLTags; + // linking tag hash mapped to tx hash + std::unordered_map ltagTxhash; //! list of disabling sporks active at this block height //! std::map {feature name} -> {block number when feature is re-enabled again, parameter} @@ -303,6 +305,7 @@ class CBlockIndex sparkMintedCoins.clear(); sparkSetHash.clear(); spentLTags.clear(); + ltagTxhash.clear(); sparkTxHashContext.clear(); sigmaSpentSerials.clear(); lelantusSpentSerials.clear(); @@ -563,6 +566,7 @@ class CDiskBlockIndex : public CBlockIndex if (GetBoolArg("-mobile", false)) { READWRITE(sparkTxHashContext); + READWRITE(ltagTxhash); } } diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 521ee71a0a..c5f8234270 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1404,6 +1404,63 @@ UniValue getusedcoinstags(const JSONRPCRequest& request) return ret; } +UniValue getusedcoinstagstxhashes(const JSONRPCRequest& request) +{ + if (request.fHelp || request.params.size() != 1) + throw std::runtime_error( + "getusedcoinstagstxhashes\n" + "\nReturns the set of used coin tags.\n" + "\nArguments:\n" + "{\n" + " \"startNumber \" (int) Number of elements already existing on user side\n" + "}\n" + "\nResult:\n" + "{\n" + " \"tags\" (std::string[]) array of Serialized GroupElements paired with unit256 (tx ids) \n" + "}\n" + ); + + int startNumber; + try { + startNumber = std::stol(request.params[0].get_str()); + } catch (std::logic_error const & e) { + throw std::runtime_error(std::string("An exception occurred while parsing parameters: ") + e.what()); + } + + spark::CSparkState* sparkState = spark::CSparkState::GetState(); + std::unordered_map tags; + std::unordered_map ltagTxhash; + { + LOCK(cs_main); + tags = sparkState->GetSpends(); + ltagTxhash = sparkState->GetSpendTxIds(); + } + UniValue serializedTagsTxIds(UniValue::VARR); + int i = 0; + for ( auto it = tags.begin(); it != tags.end(); ++it, ++i) { + if ((tags.size() - i - 1) < startNumber) + continue; + std::vector serialized; + serialized.resize(34); + it->first.serialize(serialized.data()); + std::vector data; + data.push_back(EncodeBase64(serialized.data(), 34)); + uint256 txid; + uint256 ltagHash = primitives::GetLTagHash(it->first); + if (ltagTxhash.count(ltagHash) > 0) + txid = ltagTxhash[ltagHash]; + data.push_back(EncodeBase64(txid.begin(), txid.size())); + UniValue entity(UniValue::VARR); + entity.push_backV(data); + serializedTagsTxIds.push_back(entity); + } + + UniValue ret(UniValue::VOBJ); + ret.push_back(Pair("tagsandtxids", serializedTagsTxIds)); + + return ret; +} + UniValue getsparklatestcoinid(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() != 0) @@ -1854,6 +1911,7 @@ static const CRPCCommand commands[] = { "mobile", "getsparkanonymityset", &getsparkanonymityset, false }, { "mobile", "getsparkmintmetadata", &getsparkmintmetadata, true }, { "mobile", "getusedcoinstags", &getusedcoinstags, false }, + { "mobile", "getusedcoinstagstxhashes", &getusedcoinstagstxhashes, false }, { "mobile", "getsparklatestcoinid", &getsparklatestcoinid, true }, { "mobile", "getmempooltxids", &getmempooltxids, true }, { "mobile", "getmempooltxs", &getmempooltxs, true }, diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 0b6a580b20..015517ec1d 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -342,6 +342,7 @@ static const CRPCCommand vRPCCommands[] = { "mobile", "getsparkanonymityset", &getsparkanonymityset, false }, { "mobile", "getsparkmintmetadata", &getsparkmintmetadata, true }, { "mobile", "getusedcoinstags", &getusedcoinstags, false }, + { "mobile", "getusedcoinstagstxhashes", &getusedcoinstagstxhashes, false }, { "mobile", "getsparklatestcoinid", &getsparklatestcoinid, true }, { "mobile", "getmempooltxids", &getmempooltxids, true }, { "mobile", "getmempooltxs", &getmempooltxs, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 1f1e142929..62bae12bfb 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -216,6 +216,7 @@ extern UniValue getlatestcoinid(const JSONRPCRequest& params); extern UniValue getsparkanonymityset(const JSONRPCRequest& params); extern UniValue getsparkmintmetadata(const JSONRPCRequest& params); extern UniValue getusedcoinstags(const JSONRPCRequest& params); +extern UniValue getusedcoinstagstxhashes(const JSONRPCRequest& params); extern UniValue getsparklatestcoinid(const JSONRPCRequest& params); extern UniValue getmempooltxids(const JSONRPCRequest& params); extern UniValue getmempooltxs(const JSONRPCRequest& params); diff --git a/src/spark/state.cpp b/src/spark/state.cpp index 5359a7a9a0..4eebb613e4 100644 --- a/src/spark/state.cpp +++ b/src/spark/state.cpp @@ -265,10 +265,16 @@ bool ConnectBlockSpark( } if (!fJustCheck) { - BOOST_FOREACH(auto& lTag, pblock->sparkTxInfo->spentLTags) { + BOOST_FOREACH (auto& lTag, pblock->sparkTxInfo->spentLTags) { pindexNew->spentLTags.insert(lTag); sparkState.AddSpend(lTag.first, lTag.second); } + if (GetBoolArg("-mobile", false)) { + BOOST_FOREACH (auto& lTag, pblock->sparkTxInfo->ltagTxhash) { + pindexNew->ltagTxhash.insert(lTag); + sparkState.AddLTagTxHash(lTag.first, lTag.second); + } + } } else { return true; @@ -693,6 +699,9 @@ bool CheckSparkSpendTransaction( if (sparkTxInfo && !sparkTxInfo->fInfoIsComplete) { for (size_t i = 0; i < lTags.size(); i++) { sparkTxInfo->spentLTags.insert(std::make_pair(lTags[i], ids[i])); + if (GetBoolArg("-mobile", false)) { + sparkTxInfo->ltagTxhash.insert(std::make_pair(primitives::GetLTagHash(lTags[i]), hashTx)); + } } } } @@ -1038,6 +1047,10 @@ void CSparkState::AddSpend(const GroupElement& lTag, int coinGroupId) { } } +void CSparkState::AddLTagTxHash(const uint256& lTagHash, const uint256& txHash) { + ltagTxhash[lTagHash] = txHash; +} + void CSparkState::RemoveSpend(const GroupElement& lTag) { auto iter = usedLTags.find(lTag); if (iter != usedLTags.end()) { @@ -1074,6 +1087,11 @@ void CSparkState::AddBlock(CBlockIndex *index) { for (auto const &lTags : index->spentLTags) { AddSpend(lTags.first, lTags.second); } + if (GetBoolArg("-mobile", false)) { + for (auto const &elem : index->ltagTxhash) { + AddLTagTxHash(elem.first, elem.second); + } + } } void CSparkState::RemoveBlock(CBlockIndex *index) { @@ -1320,6 +1338,10 @@ std::unordered_map const & CSparkState::Get return usedLTags; } +std::unordered_map const& CSparkState::GetSpendTxIds() const { + return ltagTxhash; +} + std::unordered_map const& CSparkState::GetCoinGroups() const { return coinGroups; } diff --git a/src/spark/state.h b/src/spark/state.h index 3820cb1a1d..c8883875ef 100644 --- a/src/spark/state.h +++ b/src/spark/state.h @@ -26,6 +26,7 @@ class CSparkTxInfo { // linking tag for every spend (map from lTag to coin group id) std::unordered_map spentLTags; + std::unordered_map ltagTxhash; // information about transactions in the block is complete bool fInfoIsComplete; @@ -168,6 +169,7 @@ class CSparkState { void AddMintsToStateAndBlockIndex(CBlockIndex *index, const CBlock* pblock); void AddSpend(const GroupElement& lTag, int coinGroupId); + void AddLTagTxHash(const uint256& lTagHash, const uint256& txHash); void RemoveSpend(const GroupElement& lTag); // Add everything from the block to the state void AddBlock(CBlockIndex *index); @@ -213,6 +215,7 @@ class CSparkState { std::unordered_map const & GetMints() const; std::unordered_map const & GetSpends() const; + std::unordered_map const& GetSpendTxIds() const; std::unordered_map const & GetCoinGroups() const; std::unordered_map const & GetMempoolLTags() const; @@ -238,6 +241,8 @@ class CSparkState { std::unordered_map mintedCoins; // Set of all used coin linking tags. std::unordered_map usedLTags; + // linking tag hash mapped to tx hash + std::unordered_map ltagTxhash; typedef std::map metainfo_container_t; metainfo_container_t extendedMintMetaInfo, mintMetaInfo, spendMetaInfo; diff --git a/src/txdb.cpp b/src/txdb.cpp index acb6463381..2ba448dffa 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -425,6 +425,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts(boost::functionsparkSetHash = diskindex.sparkSetHash; pindexNew->spentLTags = diskindex.spentLTags; pindexNew->sparkTxHashContext = diskindex.sparkTxHashContext; + pindexNew->ltagTxhash = diskindex.ltagTxhash; pindexNew->activeDisablingSporks = diskindex.activeDisablingSporks; From c76d8622ab0c105ebdebcf03d67d88b4fb5b6f94 Mon Sep 17 00:00:00 2001 From: levonpetrosyan93 Date: Wed, 12 Jun 2024 16:07:07 +0400 Subject: [PATCH 4/7] getmempooltxs rpc interface fixed --- src/rpc/client.cpp | 1 + src/rpc/misc.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index bfbdf2f22f..629dde9a14 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -194,6 +194,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "getusedcoinserials", 0 }, { "getlatestcoinids", 0 }, { "getsparkmintmetadata", 0 }, + { "getmempooltxs", 0 }, //Lelantus { "mintspark", 0 }, diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index c5f8234270..53b1c816c3 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1525,12 +1525,12 @@ UniValue getmempooltxs(const JSONRPCRequest& request) "{\n" " \"txdata\" (Pair) nHeight and id for each coin\n" "}\n" - + HelpExampleCli("getmempooltxs", "'{[\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\",\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"]}'") - + HelpExampleRpc("getmempooltxs", "{[\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\",\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"]}") + + HelpExampleCli("getmempooltxs", "'{\"txids\": [\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\",\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"]}'") + + HelpExampleRpc("getmempooltxs", "{\"txids\": [\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\",\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"]}") ); - UniValue txids = request.params[0].get_obj(); + UniValue txids = find_value(request.params[0].get_obj(), "txids"); UniValue result(UniValue::VARR); for(UniValue const & element : txids.getValues()){ From 973eefe5f931bf3e7db8d8d621320f6f2b0880b1 Mon Sep 17 00:00:00 2001 From: levonpetrosyan93 Date: Thu, 13 Jun 2024 05:39:45 +0400 Subject: [PATCH 5/7] Fix getmempooltxs --- src/rpc/misc.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 53b1c816c3..7212672a85 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1532,7 +1532,7 @@ UniValue getmempooltxs(const JSONRPCRequest& request) UniValue txids = find_value(request.params[0].get_obj(), "txids"); - UniValue result(UniValue::VARR); + UniValue result(UniValue::VOBJ); for(UniValue const & element : txids.getValues()){ uint256 txid; txid.SetHex(element.get_str()); @@ -1540,8 +1540,9 @@ UniValue getmempooltxs(const JSONRPCRequest& request) if (tx == nullptr || !tx->IsSparkTransaction()) continue; - UniValue data(UniValue::VARR); + UniValue data(UniValue::VOBJ); std::vector lTags_; + UniValue lTags_json(UniValue::VARR); if (tx->IsSparkSpend()) { try { @@ -1559,21 +1560,27 @@ UniValue getmempooltxs(const JSONRPCRequest& request) } else { lTags_.push_back("MintTX"); } - data.push_backV(lTags_); // Spend lTags for corresponding tx, + lTags_json.push_backV(lTags_); - std::vector serial_context = spark::getSerialContext(*tx); - data.push_back(EncodeBase64(serial_context.data(), serial_context.size())); // spark serial context + data.push_back(Pair("lTags ", lTags_json)); // Spend lTags for corresponding tx, + std::vector serial_context = spark::getSerialContext(*tx); + UniValue serial_context_json(UniValue::VARR); + serial_context_json.push_back(EncodeBase64(serial_context.data(), serial_context.size())); + data.push_back(Pair("Serial_context", serial_context_json)); // spark serial context std::vector coins = spark::GetSparkMintCoins(*tx); std::vector serialized_coins; + UniValue serialized_json(UniValue::VARR); for (auto& coin: coins) { CDataStream serializedCoin(SER_NETWORK, PROTOCOL_VERSION); serializedCoin << coin; std::vector vch(serializedCoin.begin(), serializedCoin.end()); serialized_coins.push_back(EncodeBase64(vch.data(), size_t(vch.size()))); // coi } - data.push_backV(serialized_coins); + serialized_json.push_backV(serialized_coins); + data.push_back(Pair("Coins", serialized_json)); + result.push_back(Pair(EncodeBase64(txid.begin(), txid.size()), data)); } From e7f6931a66d9504305a2e232b6aed4bfdbc05b7c Mon Sep 17 00:00:00 2001 From: levonpetrosyan93 Date: Tue, 18 Jun 2024 03:26:59 +0400 Subject: [PATCH 6/7] Review comments applied --- src/rpc/misc.cpp | 16 ++++++++-------- src/rpc/server.cpp | 4 ++-- src/rpc/server.h | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 7212672a85..ac2fd8cbad 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1488,11 +1488,11 @@ UniValue getsparklatestcoinid(const JSONRPCRequest& request) return UniValue(latestCoinId); } -UniValue getmempooltxids(const JSONRPCRequest& request) +UniValue getmempoolsparktxids(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() != 0) throw std::runtime_error( - "getmempooltxids\n" + "getmempoolsparktxids\n" "\nReturns all mempool transaction ids.\n" ); @@ -1507,11 +1507,11 @@ UniValue getmempooltxids(const JSONRPCRequest& request) return result; } -UniValue getmempooltxs(const JSONRPCRequest& request) +UniValue getmempoolsparktxs(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() != 1) throw std::runtime_error( - "getmempooltxs\n" + "getmempoolsparktxs\n" "\nReturns spark data for each transaction.\n" "\nArguments:\n" " \"txids\"\n" @@ -1525,8 +1525,8 @@ UniValue getmempooltxs(const JSONRPCRequest& request) "{\n" " \"txdata\" (Pair) nHeight and id for each coin\n" "}\n" - + HelpExampleCli("getmempooltxs", "'{\"txids\": [\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\",\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"]}'") - + HelpExampleRpc("getmempooltxs", "{\"txids\": [\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\",\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"]}") + + HelpExampleCli("getmempoolsparktxs", "'{\"txids\": [\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\",\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"]}'") + + HelpExampleRpc("getmempoolsparktxs", "{\"txids\": [\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\",\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"]}") ); @@ -1920,8 +1920,8 @@ static const CRPCCommand commands[] = { "mobile", "getusedcoinstags", &getusedcoinstags, false }, { "mobile", "getusedcoinstagstxhashes", &getusedcoinstagstxhashes, false }, { "mobile", "getsparklatestcoinid", &getsparklatestcoinid, true }, - { "mobile", "getmempooltxids", &getmempooltxids, true }, - { "mobile", "getmempooltxs", &getmempooltxs, true }, + { "mobile", "getmempoolsparktxids", &getmempoolsparktxids, true }, + { "mobile", "getmempoolsparktxs", &getmempoolsparktxs, true }, { "mobile", "checkifmncollateral", &checkifmncollateral, false }, diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 015517ec1d..0f07787f1b 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -344,8 +344,8 @@ static const CRPCCommand vRPCCommands[] = { "mobile", "getusedcoinstags", &getusedcoinstags, false }, { "mobile", "getusedcoinstagstxhashes", &getusedcoinstagstxhashes, false }, { "mobile", "getsparklatestcoinid", &getsparklatestcoinid, true }, - { "mobile", "getmempooltxids", &getmempooltxids, true }, - { "mobile", "getmempooltxs", &getmempooltxs, true }, + { "mobile", "getmempoolsparktxids", &getmempoolsparktxids, true }, + { "mobile", "getmempoolsparktxs", &getmempoolsparktxs, true }, { "mobile", "checkifmncollateral", &checkifmncollateral, false }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 62bae12bfb..dbf98839b9 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -218,8 +218,8 @@ extern UniValue getsparkmintmetadata(const JSONRPCRequest& params); extern UniValue getusedcoinstags(const JSONRPCRequest& params); extern UniValue getusedcoinstagstxhashes(const JSONRPCRequest& params); extern UniValue getsparklatestcoinid(const JSONRPCRequest& params); -extern UniValue getmempooltxids(const JSONRPCRequest& params); -extern UniValue getmempooltxs(const JSONRPCRequest& params); +extern UniValue getmempoolsparktxids(const JSONRPCRequest& params); +extern UniValue getmempoolsparktxs(const JSONRPCRequest& params); extern UniValue checkifmncollateral(const JSONRPCRequest& params); From f7415c73dd39cebd524e21724c33488df41e9eb0 Mon Sep 17 00:00:00 2001 From: levonpetrosyan93 Date: Tue, 18 Jun 2024 15:43:29 +0400 Subject: [PATCH 7/7] Help strings improved --- src/rpc/misc.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index ac2fd8cbad..8f73698fa0 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1409,7 +1409,7 @@ UniValue getusedcoinstagstxhashes(const JSONRPCRequest& request) if (request.fHelp || request.params.size() != 1) throw std::runtime_error( "getusedcoinstagstxhashes\n" - "\nReturns the set of used coin tags.\n" + "\nReturns the set of used coin tags paired with tx ids in which it was spent, this rpc required -mobile argument, \n" "\nArguments:\n" "{\n" " \"startNumber \" (int) Number of elements already existing on user side\n" @@ -1493,7 +1493,7 @@ UniValue getmempoolsparktxids(const JSONRPCRequest& request) if (request.fHelp || request.params.size() != 0) throw std::runtime_error( "getmempoolsparktxids\n" - "\nReturns all mempool transaction ids.\n" + "\nReturns spark transaction ids existing in the mempool.\n" ); UniValue result(UniValue::VARR); @@ -1512,7 +1512,7 @@ UniValue getmempoolsparktxs(const JSONRPCRequest& request) if (request.fHelp || request.params.size() != 1) throw std::runtime_error( "getmempoolsparktxs\n" - "\nReturns spark data for each transaction.\n" + "\nReturns spark metadata for each transaction id, in case tx already was removed from mempool, nothing will be returned for specific id.\n" "\nArguments:\n" " \"txids\"\n" " [\n" @@ -1522,8 +1522,10 @@ UniValue getmempoolsparktxs(const JSONRPCRequest& request) " ,...\n" " ]\n" "\nResult:\n" - "{\n" - " \"txdata\" (Pair) nHeight and id for each coin\n" + "txid , {\n" + " \"lTags\" Array of GroupElements, or a string 'MintTX' in case it is mint tx\n" + " \"serial_context\" byte array which is used to identify the output spark coins, it is unique for each ix\n" + " \"coins\" Array of serialized spar::Coin elements, the output coins of the tx\n" "}\n" + HelpExampleCli("getmempoolsparktxs", "'{\"txids\": [\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\",\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"]}'") + HelpExampleRpc("getmempoolsparktxs", "{\"txids\": [\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\",\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"]}") @@ -1567,7 +1569,7 @@ UniValue getmempoolsparktxs(const JSONRPCRequest& request) std::vector serial_context = spark::getSerialContext(*tx); UniValue serial_context_json(UniValue::VARR); serial_context_json.push_back(EncodeBase64(serial_context.data(), serial_context.size())); - data.push_back(Pair("Serial_context", serial_context_json)); // spark serial context + data.push_back(Pair("serial_context", serial_context_json)); // spark serial context std::vector coins = spark::GetSparkMintCoins(*tx); std::vector serialized_coins; @@ -1579,7 +1581,7 @@ UniValue getmempoolsparktxs(const JSONRPCRequest& request) serialized_coins.push_back(EncodeBase64(vch.data(), size_t(vch.size()))); // coi } serialized_json.push_backV(serialized_coins); - data.push_back(Pair("Coins", serialized_json)); + data.push_back(Pair("coins", serialized_json)); result.push_back(Pair(EncodeBase64(txid.begin(), txid.size()), data)); }