Skip to content

Commit

Permalink
checkifmncollateral rpc added (firoorg#1427)
Browse files Browse the repository at this point in the history
* checkifmncollateral rpc added

* review comments applied
  • Loading branch information
levonpetrosyan93 authored May 11, 2024
1 parent 7fb07bf commit 065a60a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "txdb.h"

#include "masternode-sync.h"
#include "evo/deterministicmns.h"

#include <stdint.h>

Expand Down Expand Up @@ -1430,6 +1431,42 @@ UniValue getsparklatestcoinid(const JSONRPCRequest& request)
return UniValue(latestCoinId);
}

UniValue checkifmncollateral(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 2)
throw std::runtime_error(
"checkifmncollateral\n"
"\nReturns bool value.\n"
"\nArguments:\n"
" \"txHash\"\n"
" \"index\"\n"
+ HelpExampleCli("checkifmncollateral", "\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"" "\"0\" ")
+ HelpExampleRpc("checkifmncollateral", "\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"" "\"0\" ")
);

std::string strTxId;
int index;

try {
strTxId = request.params[0].get_str();
index = std::stol(request.params[1].get_str());
} catch (std::logic_error const & e) {
throw std::runtime_error(std::string("An exception occurred while parsing parameters: ") + e.what());
}

uint256 txid = uint256S(strTxId);

CTransactionRef tx;
uint256 hashBlock;
if(!GetTransaction(txid, tx, Params().GetConsensus(), hashBlock, true))
throw std::runtime_error("Unknown transaction.");

auto mnList = deterministicMNManager->GetListAtChainTip();
COutPoint o(txid, index);
bool fMnExists = deterministicMNManager->IsProTxWithCollateral(tx, index) || mnList.HasMNByCollateral(o);
return UniValue(fMnExists);
}

UniValue getaddresstxids(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 1)
Expand Down Expand Up @@ -1727,6 +1764,7 @@ static const CRPCCommand commands[] =
{ "mobile", "getusedcoinstags", &getusedcoinstags, false },
{ "mobile", "getsparklatestcoinid", &getsparklatestcoinid, true },

{ "mobile", "checkifmncollateral", &checkifmncollateral, false },

{ "hidden", "setmocktime", &setmocktime, true, {"timestamp"}},
{ "hidden", "echo", &echo, true, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}},
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ static const CRPCCommand vRPCCommands[] =
{ "mobile", "getusedcoinstags", &getusedcoinstags, false },
{ "mobile", "getsparklatestcoinid", &getsparklatestcoinid, true },

{ "mobile", "checkifmncollateral", &checkifmncollateral, false },

};

CRPCTable::CRPCTable()
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ extern UniValue getsparkmintmetadata(const JSONRPCRequest& params);
extern UniValue getusedcoinstags(const JSONRPCRequest& params);
extern UniValue getsparklatestcoinid(const JSONRPCRequest& params);

extern UniValue checkifmncollateral(const JSONRPCRequest& params);

extern UniValue znode(const JSONRPCRequest &request);
extern UniValue znodelist(const JSONRPCRequest &request);
extern UniValue znodebroadcast(const JSONRPCRequest &request);
Expand Down

0 comments on commit 065a60a

Please sign in to comment.