|
19 | 19 | #include "rpc/server.h" |
20 | 20 | #include "util.h" |
21 | 21 | #include "utilmoneystr.h" |
| 22 | +#include "txmempool.h" |
| 23 | + |
| 24 | +#include "evo/specialtx.h" |
| 25 | +#include "evo/deterministicmns.h" |
22 | 26 |
|
23 | 27 | #include <fstream> |
24 | 28 | #include <iomanip> |
@@ -573,6 +577,91 @@ UniValue masternode_genkey(const JSONRPCRequest& request) |
573 | 577 | return CBitcoinSecret(secret).ToString(); |
574 | 578 | } |
575 | 579 |
|
| 580 | +void masternode_info_help() |
| 581 | +{ |
| 582 | + throw std::runtime_error( |
| 583 | + "masternode info \"proTxHash\"\n" |
| 584 | + "Print masternode information of specified masternode\n" |
| 585 | + "\nArguments:\n" |
| 586 | + "1. proTxHash (string, required) proTxHash of masternode\n" |
| 587 | + ); |
| 588 | +} |
| 589 | + |
| 590 | +UniValue masternode_info(const JSONRPCRequest& request) |
| 591 | +{ |
| 592 | + if(request.fHelp || request.params.size() != 2) |
| 593 | + masternode_info_help(); |
| 594 | + |
| 595 | + std::string strProTxHash = request.params[1].get_str(); |
| 596 | + if (!IsHex(strProTxHash) || strProTxHash.size() != 64) |
| 597 | + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid \"proTxHash\""); |
| 598 | + |
| 599 | + uint256 proTxHash; |
| 600 | + proTxHash.SetHex(strProTxHash); |
| 601 | + |
| 602 | + CTransactionRef tx; |
| 603 | + uint256 hashBlock; |
| 604 | + bool fromMempool = false; |
| 605 | + |
| 606 | + auto dmn = deterministicMNManager->GetListAtChainTip().GetMN(proTxHash); |
| 607 | + if (!dmn) { |
| 608 | + tx = mempool.get(proTxHash); |
| 609 | + if (tx) { |
| 610 | + fromMempool = true; |
| 611 | + if (tx->nVersion < 3 || tx->nType != TRANSACTION_PROVIDER_REGISTER) |
| 612 | + throw JSONRPCError(RPC_INVALID_PARAMETER, "TX is not a ProTx"); |
| 613 | + CProRegTx tmpProTx; |
| 614 | + if (!GetTxPayload(*tx, tmpProTx)) |
| 615 | + throw JSONRPCError(RPC_INVALID_PARAMETER, "TX is not a valid ProTx"); |
| 616 | + dmn = std::make_shared<CDeterministicMN>(tx->GetHash(), tmpProTx); |
| 617 | + } else { |
| 618 | + throw JSONRPCError(RPC_INVALID_PARAMETER, "ProTx not found"); |
| 619 | + } |
| 620 | + } else { |
| 621 | + if (!GetTransaction(proTxHash, tx, Params().GetConsensus(), hashBlock, true)) |
| 622 | + throw JSONRPCError(RPC_INVALID_PARAMETER, "Parent transaction of ProTx not found"); |
| 623 | + |
| 624 | + if (!mapBlockIndex.count(hashBlock)) |
| 625 | + throw JSONRPCError(RPC_INVALID_PARAMETER, "Parent transaction of ProTx not found"); |
| 626 | + } |
| 627 | + |
| 628 | + UniValue obj(UniValue::VOBJ); |
| 629 | + |
| 630 | + UniValue stateObj; |
| 631 | + dmn->pdmnState->ToJson(stateObj); |
| 632 | + obj.push_back(Pair("state", stateObj)); |
| 633 | + |
| 634 | + if (!hashBlock.IsNull()) { |
| 635 | + UniValue blockObj(UniValue::VOBJ); |
| 636 | + blockObj.push_back(Pair("blockhash", hashBlock.GetHex())); |
| 637 | + |
| 638 | + LOCK(cs_main); |
| 639 | + BlockMap::iterator mi = mapBlockIndex.find(hashBlock); |
| 640 | + if (mi != mapBlockIndex.end() && (*mi).second) { |
| 641 | + CBlockIndex *pindex = (*mi).second; |
| 642 | + if (chainActive.Contains(pindex)) { |
| 643 | + blockObj.push_back(Pair("height", pindex->nHeight)); |
| 644 | + blockObj.push_back(Pair("confirmations", 1 + chainActive.Height() - pindex->nHeight)); |
| 645 | + blockObj.push_back(Pair("time", pindex->GetBlockTime())); |
| 646 | + blockObj.push_back(Pair("blocktime", pindex->GetBlockTime())); |
| 647 | + } else { |
| 648 | + blockObj.push_back(Pair("height", -1)); |
| 649 | + blockObj.push_back(Pair("confirmations", 0)); |
| 650 | + } |
| 651 | + } |
| 652 | + obj.push_back(Pair("block", blockObj)); |
| 653 | + |
| 654 | + if (GetUTXOHeight(COutPoint(proTxHash, dmn->nCollateralIndex)) < 0) { |
| 655 | + obj.push_back(Pair("isSpent", true)); |
| 656 | + } |
| 657 | + |
| 658 | + } else { |
| 659 | + obj.push_back(Pair("fromMempool", true)); |
| 660 | + } |
| 661 | + |
| 662 | + return obj; |
| 663 | +} |
| 664 | + |
576 | 665 | void masternode_list_conf_help() |
577 | 666 | { |
578 | 667 | throw std::runtime_error( |
@@ -804,6 +893,8 @@ UniValue masternode(const JSONRPCRequest& request) |
804 | 893 | #endif // ENABLE_WALLET |
805 | 894 | } else if (strCommand == "genkey") { |
806 | 895 | return masternode_genkey(request); |
| 896 | + } else if (strCommand == "info") { |
| 897 | + return masternode_info(request); |
807 | 898 | } else if (strCommand == "list-conf") { |
808 | 899 | return masternode_list_conf(request); |
809 | 900 | #ifdef ENABLE_WALLET |
|
0 commit comments