2021-04-20 21:33:02 +02:00
|
|
|
// Copyright (c) 2014-2021 The Dash Core developers
|
2014-12-09 02:17:57 +01:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <evo/deterministicmns.h>
|
2020-12-11 23:38:08 +01:00
|
|
|
#include <governance/governance-classes.h>
|
2021-05-25 12:48:04 +02:00
|
|
|
#include <index/txindex.h>
|
2021-04-23 00:32:03 +02:00
|
|
|
#include <masternode/activemasternode.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <masternode/masternode-payments.h>
|
2021-04-23 00:32:03 +02:00
|
|
|
#include <net.h>
|
|
|
|
#include <netbase.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <rpc/server.h>
|
2021-04-23 00:32:03 +02:00
|
|
|
#include <validation.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <wallet/coincontrol.h>
|
|
|
|
#include <wallet/rpcwallet.h>
|
2017-12-01 19:53:34 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <wallet/wallet.h>
|
2017-12-01 19:53:34 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2019-12-31 15:22:17 +01:00
|
|
|
#include <fstream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <univalue.h>
|
2016-11-21 21:40:56 +01:00
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static UniValue masternodelist(const JSONRPCRequest& request);
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static void masternode_list_help()
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
|
|
|
throw std::runtime_error(
|
2019-05-30 10:01:16 +02:00
|
|
|
"masternodelist ( \"mode\" \"filter\" )\n"
|
|
|
|
"Get a list of masternodes in different modes. This call is identical to 'masternode list' call.\n"
|
2018-08-29 13:36:35 +02:00
|
|
|
"\nArguments:\n"
|
|
|
|
"1. \"mode\" (string, optional/required to use filter, defaults = json) The mode to run list in\n"
|
|
|
|
"2. \"filter\" (string, optional) Filter results. Partial match by outpoint by default in all modes,\n"
|
|
|
|
" additional matches in some modes are also available\n"
|
|
|
|
"\nAvailable modes:\n"
|
|
|
|
" addr - Print ip address associated with a masternode (can be additionally filtered, partial match)\n"
|
2018-12-17 13:20:16 +01:00
|
|
|
" full - Print info in format 'status payee lastpaidtime lastpaidblock IP'\n"
|
2018-08-29 13:36:35 +02:00
|
|
|
" (can be additionally filtered, partial match)\n"
|
2018-12-17 13:20:16 +01:00
|
|
|
" info - Print info in format 'status payee IP'\n"
|
2018-08-29 13:36:35 +02:00
|
|
|
" (can be additionally filtered, partial match)\n"
|
|
|
|
" json - Print info in JSON format (can be additionally filtered, partial match)\n"
|
|
|
|
" lastpaidblock - Print the last block height a node was paid on the network\n"
|
|
|
|
" lastpaidtime - Print the last time a node was paid on the network\n"
|
2019-01-11 11:05:58 +01:00
|
|
|
" owneraddress - Print the masternode owner Dash address\n"
|
|
|
|
" payee - Print the masternode payout Dash address (can be additionally filtered,\n"
|
2018-08-29 13:36:35 +02:00
|
|
|
" partial match)\n"
|
2018-12-31 14:05:23 +01:00
|
|
|
" pubKeyOperator - Print the masternode operator public key\n"
|
2019-01-03 10:17:43 +01:00
|
|
|
" status - Print masternode status: ENABLED / POSE_BANNED\n"
|
2018-12-17 13:20:16 +01:00
|
|
|
" (can be additionally filtered, partial match)\n"
|
2019-01-11 11:05:58 +01:00
|
|
|
" votingaddress - Print the masternode voting Dash address\n"
|
2018-08-29 13:36:35 +02:00
|
|
|
);
|
|
|
|
}
|
2014-12-06 20:41:53 +01:00
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static UniValue masternode_list(const JSONRPCRequest& request)
|
2014-12-09 02:17:57 +01:00
|
|
|
{
|
RPC folder: Cleaned up brackets on if, while, for, BOOST_FOREACH. Some whitespace fixes (#2257)
* Cleaned up brackets on if, while, for, BOOST_FOREACH. Some whitespace fixes
* gov, mn and mining cleanup
* Revert "Cleaned up brackets on if, while, for, BOOST_FOREACH. Some whitespace fixes"
This reverts commit 4a2a1b0645c5195025d0c7e6dad2e01a93efbfd6.
* Revert "gov, mn and mining cleanup"
This reverts commit 7cb91aabc67df0ab60db4ee84e3aaaf6cf6b7881.
* cleanup some dash specific
* "if(" -> "if (" "for(" -> "for (" + corrected some else blocks
2018-09-05 14:04:24 +02:00
|
|
|
if (request.fHelp)
|
2018-08-29 13:36:35 +02:00
|
|
|
masternode_list_help();
|
|
|
|
JSONRPCRequest newRequest = request;
|
|
|
|
newRequest.params.setArray();
|
|
|
|
// forward params but skip "list"
|
|
|
|
for (unsigned int i = 1; i < request.params.size(); i++) {
|
|
|
|
newRequest.params.push_back(request.params[i]);
|
2016-09-16 17:22:57 +02:00
|
|
|
}
|
2018-08-29 13:36:35 +02:00
|
|
|
return masternodelist(newRequest);
|
|
|
|
}
|
2016-09-16 17:22:57 +02:00
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static void masternode_connect_help()
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
|
|
|
throw std::runtime_error(
|
|
|
|
"masternode connect \"address\"\n"
|
|
|
|
"Connect to given masternode\n"
|
|
|
|
"\nArguments:\n"
|
|
|
|
"1. \"address\" (string, required) The address of the masternode to connect\n"
|
|
|
|
);
|
|
|
|
}
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static UniValue masternode_connect(const JSONRPCRequest& request)
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
RPC folder: Cleaned up brackets on if, while, for, BOOST_FOREACH. Some whitespace fixes (#2257)
* Cleaned up brackets on if, while, for, BOOST_FOREACH. Some whitespace fixes
* gov, mn and mining cleanup
* Revert "Cleaned up brackets on if, while, for, BOOST_FOREACH. Some whitespace fixes"
This reverts commit 4a2a1b0645c5195025d0c7e6dad2e01a93efbfd6.
* Revert "gov, mn and mining cleanup"
This reverts commit 7cb91aabc67df0ab60db4ee84e3aaaf6cf6b7881.
* cleanup some dash specific
* "if(" -> "if (" "for(" -> "for (" + corrected some else blocks
2018-09-05 14:04:24 +02:00
|
|
|
if (request.fHelp || request.params.size() < 2)
|
2018-08-29 13:36:35 +02:00
|
|
|
masternode_connect_help();
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2018-08-29 13:36:35 +02:00
|
|
|
std::string strAddress = request.params[1].get_str();
|
2016-09-16 17:22:57 +02:00
|
|
|
|
2018-08-29 13:36:35 +02:00
|
|
|
CService addr;
|
|
|
|
if (!Lookup(strAddress.c_str(), addr, 0, false))
|
|
|
|
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Incorrect masternode address %s", strAddress));
|
2015-07-18 21:17:17 +02:00
|
|
|
|
2018-08-29 13:36:35 +02:00
|
|
|
// TODO: Pass CConnman instance somehow and don't use global variable.
|
|
|
|
g_connman->OpenMasternodeConnection(CAddress(addr, NODE_NETWORK));
|
|
|
|
if (!g_connman->IsConnected(CAddress(addr, NODE_NETWORK), CConnman::AllNodes))
|
|
|
|
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Couldn't connect to masternode %s", strAddress));
|
2015-07-18 21:17:17 +02:00
|
|
|
|
2018-08-29 13:36:35 +02:00
|
|
|
return "successfully connected";
|
|
|
|
}
|
2016-09-16 17:22:57 +02:00
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static void masternode_count_help()
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
|
|
|
throw std::runtime_error(
|
2021-03-26 13:17:25 +01:00
|
|
|
"masternode count\n"
|
|
|
|
"Get information about number of masternodes.\n"
|
2018-08-29 13:36:35 +02:00
|
|
|
);
|
|
|
|
}
|
2015-07-18 21:17:17 +02:00
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static UniValue masternode_count(const JSONRPCRequest& request)
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
2021-03-26 13:17:25 +01:00
|
|
|
if (request.fHelp || request.params.size() > 1)
|
2018-08-29 13:36:35 +02:00
|
|
|
masternode_count_help();
|
2015-08-20 17:36:44 +02:00
|
|
|
|
2018-12-17 16:27:17 +01:00
|
|
|
auto mnList = deterministicMNManager->GetListAtChainTip();
|
|
|
|
int total = mnList.GetAllMNsCount();
|
|
|
|
int enabled = mnList.GetValidMNsCount();
|
2018-02-08 06:43:19 +01:00
|
|
|
|
2021-03-26 13:17:25 +01:00
|
|
|
UniValue obj(UniValue::VOBJ);
|
|
|
|
obj.pushKV("total", total);
|
|
|
|
obj.pushKV("enabled", enabled);
|
|
|
|
return obj;
|
2018-08-29 13:36:35 +02:00
|
|
|
}
|
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static UniValue GetNextMasternodeForPayment(int heightShift)
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
2018-12-17 13:15:13 +01:00
|
|
|
auto mnList = deterministicMNManager->GetListAtChainTip();
|
|
|
|
auto payees = mnList.GetProjectedMNPayees(heightShift);
|
|
|
|
if (payees.empty())
|
|
|
|
return "unknown";
|
2019-03-21 21:47:05 +01:00
|
|
|
auto payee = payees.back();
|
2018-12-17 13:15:13 +01:00
|
|
|
CScript payeeScript = payee->pdmnState->scriptPayout;
|
2018-11-14 15:39:40 +01:00
|
|
|
|
|
|
|
CTxDestination payeeDest;
|
Merge #11117: Prepare for non-Base58 addresses (#3294)
* Merge #11117: Prepare for non-Base58 addresses
864cd2787 Move CBitcoinAddress to base58.cpp (Pieter Wuille)
5c8ff0d44 Introduce wrappers around CBitcoinAddress (Pieter Wuille)
Pull request description:
This patch removes the need for the intermediary Base58 type `CBitcoinAddress`, by providing {`Encode`,`Decode`,`IsValid`}`Destination` functions that directly operate on the conversion between `std::string`s and `CTxDestination`.
As a side, it also fixes a number of indentation issues, and removes probably several unnecessary implicit `CTxDestination`<->`CBitcoinAddress` conversions.
This change is far from complete. In follow-ups I'd like to:
* Split off the specific address and key encoding logic from base58.h, and move it to a address.h or so.
* Replace `CTxDestination` with a non-`boost::variant` version (which can be more efficient as `boost::variant` allocates everything on the heap, and remove the need for `boost::get<...>` and `IsValidDestination` calls everywhere).
* Do the same for `CBitcoinSecret`, `CBitcoinExtKey`, and `CBitcoinExtPubKey`.
However, I've tried to keep this patch to be minimally invasive, but still enough to support non-Base58 addresses. Perhaps a smaller patch is possible to hack Bech32 support into `CBitcoinAddress`, but I would consider that a move in the wrong direction.
Tree-SHA512: c2c77ffb57caeadf2429b1c2562ce60e8c7be8aa9f8e51b591f354b6b441162625b2efe14c023a1ae485cf2ed417263afa35c892891dfaa7844e7fbabccab85e
* CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* more CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* more CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* more CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* fix CBitcoinAddress GetKeyID check
Signed-off-by: Pasta <pasta@dashboost.org>
* fix providertx.cpp
Signed-off-by: Pasta <pasta@dashboost.org>
* hopefully fix governance-classes.cpp
Signed-off-by: Pasta <pasta@dashboost.org>
* partially fix governance-validators.cpp, unable to resolve "address.IsScript()"
Signed-off-by: Pasta <pasta@dashboost.org>
* partially fix governance-classes.cpp, unable to resolve "address.IsScript()"
Signed-off-by: Pasta <pasta@dashboost.org>
* fix governance-classes.h
Signed-off-by: Pasta <pasta@dashboost.org>
* DecodeTransaction -> DecodeDestination, fix governance-validators.cpp
Signed-off-by: Pasta <pasta@dashboost.org>
* More fixes for 3294
* Move GetIndexKey into rpc/misc.cpp near getAddressesFromParams
No need to have it in base58.cpp anymore as this is only used in getAddressesFromParams
Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com>
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Alexander Block <ablock84@gmail.com>
2020-01-22 11:35:04 +01:00
|
|
|
ExtractDestination(payeeScript, payeeDest);
|
2015-07-18 21:17:17 +02:00
|
|
|
|
2018-08-29 13:36:35 +02:00
|
|
|
UniValue obj(UniValue::VOBJ);
|
2016-09-15 08:50:41 +02:00
|
|
|
|
2020-06-18 11:17:23 +02:00
|
|
|
obj.pushKV("height", mnList.GetHeight() + heightShift);
|
|
|
|
obj.pushKV("IP:port", payee->pdmnState->addr.ToString());
|
|
|
|
obj.pushKV("proTxHash", payee->proTxHash.ToString());
|
|
|
|
obj.pushKV("outpoint", payee->collateralOutpoint.ToStringShort());
|
|
|
|
obj.pushKV("payee", IsValidDestination(payeeDest) ? EncodeDestination(payeeDest) : "UNKNOWN");
|
2018-08-29 13:36:35 +02:00
|
|
|
return obj;
|
|
|
|
}
|
2015-07-18 21:17:17 +02:00
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static void masternode_winner_help()
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
2021-03-26 13:17:25 +01:00
|
|
|
if (!IsDeprecatedRPCEnabled("masternode_winner")) {
|
|
|
|
throw std::runtime_error("DEPRECATED: set -deprecatedrpc=masternode_winner to enable it");
|
|
|
|
}
|
|
|
|
|
2018-08-29 13:36:35 +02:00
|
|
|
throw std::runtime_error(
|
|
|
|
"masternode winner\n"
|
|
|
|
"Print info on next masternode winner to vote for\n"
|
|
|
|
);
|
|
|
|
}
|
2018-03-01 14:18:46 +01:00
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static UniValue masternode_winner(const JSONRPCRequest& request)
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
2021-03-26 13:17:25 +01:00
|
|
|
if (request.fHelp || !IsDeprecatedRPCEnabled("masternode_winner"))
|
2018-08-29 13:36:35 +02:00
|
|
|
masternode_winner_help();
|
2015-07-18 03:23:52 +02:00
|
|
|
|
2018-08-29 13:36:35 +02:00
|
|
|
return GetNextMasternodeForPayment(10);
|
|
|
|
}
|
2015-07-18 03:23:52 +02:00
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static void masternode_current_help()
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
2021-03-26 13:17:25 +01:00
|
|
|
if (!IsDeprecatedRPCEnabled("masternode_current")) {
|
|
|
|
throw std::runtime_error("DEPRECATED: set -deprecatedrpc=masternode_current to enable it");
|
|
|
|
}
|
|
|
|
|
2018-08-29 13:36:35 +02:00
|
|
|
throw std::runtime_error(
|
|
|
|
"masternode current\n"
|
|
|
|
"Print info on current masternode winner to be paid the next block (calculated locally)\n"
|
|
|
|
);
|
|
|
|
}
|
2014-12-06 20:41:53 +01:00
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static UniValue masternode_current(const JSONRPCRequest& request)
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
2021-03-26 13:17:25 +01:00
|
|
|
if (request.fHelp || !IsDeprecatedRPCEnabled("masternode_current"))
|
2018-08-29 13:36:35 +02:00
|
|
|
masternode_current_help();
|
2014-12-06 20:41:53 +01:00
|
|
|
|
2018-08-29 13:36:35 +02:00
|
|
|
return GetNextMasternodeForPayment(1);
|
|
|
|
}
|
2014-12-06 20:41:53 +01:00
|
|
|
|
2018-08-29 13:36:35 +02:00
|
|
|
#ifdef ENABLE_WALLET
|
2018-05-04 22:42:39 +02:00
|
|
|
static void masternode_outputs_help()
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
|
|
|
throw std::runtime_error(
|
|
|
|
"masternode outputs\n"
|
|
|
|
"Print masternode compatible outputs\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static UniValue masternode_outputs(const JSONRPCRequest& request)
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
2021-04-01 19:28:43 +02:00
|
|
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
|
|
|
CWallet* const pwallet = wallet.get();
|
2018-12-29 21:15:02 +01:00
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
|
2018-08-29 13:36:35 +02:00
|
|
|
return NullUniValue;
|
|
|
|
|
2021-04-27 16:12:12 +02:00
|
|
|
if (request.fHelp)
|
|
|
|
masternode_outputs_help();
|
|
|
|
|
2020-07-07 08:06:59 +02:00
|
|
|
LOCK2(cs_main, pwallet->cs_wallet);
|
|
|
|
|
2018-08-29 13:36:35 +02:00
|
|
|
// Find possible candidates
|
|
|
|
std::vector<COutput> vPossibleCoins;
|
2019-10-23 09:56:44 +02:00
|
|
|
CCoinControl coin_control;
|
2020-05-18 14:26:18 +02:00
|
|
|
coin_control.nCoinType = CoinType::ONLY_MASTERNODE_COLLATERAL;
|
2019-10-23 09:56:44 +02:00
|
|
|
pwallet->AvailableCoins(vPossibleCoins, true, &coin_control);
|
2018-08-29 13:36:35 +02:00
|
|
|
|
|
|
|
UniValue obj(UniValue::VOBJ);
|
|
|
|
for (const auto& out : vPossibleCoins) {
|
2020-06-18 11:17:23 +02:00
|
|
|
obj.pushKV(out.tx->GetHash().ToString(), strprintf("%d", out.i));
|
2014-12-26 21:00:56 +01:00
|
|
|
}
|
2018-08-29 13:36:35 +02:00
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2017-12-01 19:53:34 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2014-12-26 21:00:56 +01:00
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static void masternode_status_help()
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
|
|
|
throw std::runtime_error(
|
|
|
|
"masternode status\n"
|
|
|
|
"Print masternode status information\n"
|
|
|
|
);
|
|
|
|
}
|
2016-03-02 21:57:24 +01:00
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static UniValue masternode_status(const JSONRPCRequest& request)
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
RPC folder: Cleaned up brackets on if, while, for, BOOST_FOREACH. Some whitespace fixes (#2257)
* Cleaned up brackets on if, while, for, BOOST_FOREACH. Some whitespace fixes
* gov, mn and mining cleanup
* Revert "Cleaned up brackets on if, while, for, BOOST_FOREACH. Some whitespace fixes"
This reverts commit 4a2a1b0645c5195025d0c7e6dad2e01a93efbfd6.
* Revert "gov, mn and mining cleanup"
This reverts commit 7cb91aabc67df0ab60db4ee84e3aaaf6cf6b7881.
* cleanup some dash specific
* "if(" -> "if (" "for(" -> "for (" + corrected some else blocks
2018-09-05 14:04:24 +02:00
|
|
|
if (request.fHelp)
|
2018-08-29 13:36:35 +02:00
|
|
|
masternode_status_help();
|
2015-07-21 00:09:42 +02:00
|
|
|
|
2018-08-29 13:36:35 +02:00
|
|
|
if (!fMasternodeMode)
|
|
|
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "This is not a masternode");
|
2015-07-21 00:09:42 +02:00
|
|
|
|
2018-08-29 13:36:35 +02:00
|
|
|
UniValue mnObj(UniValue::VOBJ);
|
2016-03-06 17:44:21 +01:00
|
|
|
|
2021-07-26 17:52:52 +02:00
|
|
|
CDeterministicMNCPtr dmn;
|
|
|
|
{
|
|
|
|
LOCK(activeMasternodeInfoCs);
|
|
|
|
|
|
|
|
// keep compatibility with legacy status for now (might get deprecated/removed later)
|
|
|
|
mnObj.pushKV("outpoint", activeMasternodeInfo.outpoint.ToStringShort());
|
|
|
|
mnObj.pushKV("service", activeMasternodeInfo.service.ToString());
|
|
|
|
dmn = deterministicMNManager->GetListAtChainTip().GetMN(activeMasternodeInfo.proTxHash);
|
|
|
|
}
|
2019-01-03 10:17:43 +01:00
|
|
|
if (dmn) {
|
2020-06-18 11:17:23 +02:00
|
|
|
mnObj.pushKV("proTxHash", dmn->proTxHash.ToString());
|
|
|
|
mnObj.pushKV("collateralHash", dmn->collateralOutpoint.hash.ToString());
|
|
|
|
mnObj.pushKV("collateralIndex", (int)dmn->collateralOutpoint.n);
|
2019-01-03 10:17:43 +01:00
|
|
|
UniValue stateObj;
|
|
|
|
dmn->pdmnState->ToJson(stateObj);
|
2020-06-18 11:17:23 +02:00
|
|
|
mnObj.pushKV("dmnState", stateObj);
|
2018-02-23 13:30:36 +01:00
|
|
|
}
|
2020-06-18 11:17:23 +02:00
|
|
|
mnObj.pushKV("state", activeMasternodeManager->GetStateString());
|
|
|
|
mnObj.pushKV("status", activeMasternodeManager->GetStatus());
|
2019-01-03 10:17:43 +01:00
|
|
|
|
2018-08-29 13:36:35 +02:00
|
|
|
return mnObj;
|
|
|
|
}
|
2015-07-18 21:17:17 +02:00
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static std::string GetRequiredPaymentsString(int nBlockHeight, const CDeterministicMNCPtr &payee)
|
2020-12-11 23:38:08 +01:00
|
|
|
{
|
|
|
|
std::string strPayments = "Unknown";
|
|
|
|
if (payee) {
|
|
|
|
CTxDestination dest;
|
|
|
|
if (!ExtractDestination(payee->pdmnState->scriptPayout, dest)) {
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
strPayments = EncodeDestination(dest);
|
2020-12-24 00:24:06 +01:00
|
|
|
if (payee->nOperatorReward != 0 && payee->pdmnState->scriptOperatorPayout != CScript()) {
|
|
|
|
if (!ExtractDestination(payee->pdmnState->scriptOperatorPayout, dest)) {
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
strPayments += ", " + EncodeDestination(dest);
|
|
|
|
}
|
2020-12-11 23:38:08 +01:00
|
|
|
}
|
|
|
|
if (CSuperblockManager::IsSuperblockTriggered(nBlockHeight)) {
|
|
|
|
std::vector<CTxOut> voutSuperblock;
|
|
|
|
if (!CSuperblockManager::GetSuperblockPayments(nBlockHeight, voutSuperblock)) {
|
|
|
|
return strPayments + ", error";
|
|
|
|
}
|
|
|
|
std::string strSBPayees = "Unknown";
|
|
|
|
for (const auto& txout : voutSuperblock) {
|
|
|
|
CTxDestination dest;
|
|
|
|
ExtractDestination(txout.scriptPubKey, dest);
|
|
|
|
if (strSBPayees != "Unknown") {
|
|
|
|
strSBPayees += ", " + EncodeDestination(dest);
|
|
|
|
} else {
|
|
|
|
strSBPayees = EncodeDestination(dest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strPayments += ", " + strSBPayees;
|
|
|
|
}
|
|
|
|
return strPayments;
|
|
|
|
}
|
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static void masternode_winners_help()
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
|
|
|
throw std::runtime_error(
|
|
|
|
"masternode winners ( count \"filter\" )\n"
|
|
|
|
"Print list of masternode winners\n"
|
|
|
|
"\nArguments:\n"
|
|
|
|
"1. count (numeric, optional) number of last winners to return\n"
|
|
|
|
"2. filter (string, optional) filter for returned winners\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static UniValue masternode_winners(const JSONRPCRequest& request)
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
2017-08-22 09:24:31 +02:00
|
|
|
if (request.fHelp || request.params.size() > 3)
|
2018-08-29 13:36:35 +02:00
|
|
|
masternode_winners_help();
|
|
|
|
|
2020-12-11 23:38:08 +01:00
|
|
|
const CBlockIndex* pindexTip{nullptr};
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
|
|
|
LOCK(cs_main);
|
2020-12-11 23:38:08 +01:00
|
|
|
pindexTip = chainActive.Tip();
|
|
|
|
if (!pindexTip) return NullUniValue;
|
2015-07-18 21:17:17 +02:00
|
|
|
}
|
|
|
|
|
2020-12-11 23:38:08 +01:00
|
|
|
int nCount = 10;
|
2018-08-29 13:36:35 +02:00
|
|
|
std::string strFilter = "";
|
2018-08-11 00:36:17 +02:00
|
|
|
|
2017-08-22 09:24:31 +02:00
|
|
|
if (!request.params[1].isNull()) {
|
2020-12-11 23:38:08 +01:00
|
|
|
nCount = atoi(request.params[1].get_str());
|
2018-08-29 13:36:35 +02:00
|
|
|
}
|
2018-08-11 00:36:17 +02:00
|
|
|
|
2017-08-22 09:24:31 +02:00
|
|
|
if (!request.params[2].isNull()) {
|
2018-08-29 13:36:35 +02:00
|
|
|
strFilter = request.params[2].get_str();
|
|
|
|
}
|
2018-08-11 00:36:17 +02:00
|
|
|
|
2018-08-29 13:36:35 +02:00
|
|
|
UniValue obj(UniValue::VOBJ);
|
2020-12-11 23:38:08 +01:00
|
|
|
|
|
|
|
int nChainTipHeight = pindexTip->nHeight;
|
|
|
|
int nStartHeight = std::max(nChainTipHeight - nCount, 1);
|
|
|
|
|
|
|
|
for (int h = nStartHeight; h <= nChainTipHeight; h++) {
|
|
|
|
auto payee = deterministicMNManager->GetListForBlock(pindexTip->GetAncestor(h - 1)).GetMNPayee();
|
|
|
|
std::string strPayments = GetRequiredPaymentsString(h, payee);
|
|
|
|
if (strFilter != "" && strPayments.find(strFilter) == std::string::npos) continue;
|
|
|
|
obj.pushKV(strprintf("%d", h), strPayments);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto projection = deterministicMNManager->GetListForBlock(pindexTip).GetProjectedMNPayees(20);
|
|
|
|
for (size_t i = 0; i < projection.size(); i++) {
|
|
|
|
int h = nChainTipHeight + 1 + i;
|
|
|
|
std::string strPayments = GetRequiredPaymentsString(h, projection[i]);
|
|
|
|
if (strFilter != "" && strPayments.find(strFilter) == std::string::npos) continue;
|
|
|
|
obj.pushKV(strprintf("%d", h), strPayments);
|
2018-08-29 13:36:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
2018-05-04 22:42:39 +02:00
|
|
|
static void masternode_payments_help()
|
2020-12-15 03:15:09 +01:00
|
|
|
{
|
|
|
|
throw std::runtime_error(
|
|
|
|
"masternode payments ( \"blockhash\" count )\n"
|
|
|
|
"\nReturns an array of deterministic masternodes and their payments for the specified block\n"
|
|
|
|
"\nArguments:\n"
|
|
|
|
"1. \"blockhash\" (string, optional, default=tip) The hash of the starting block\n"
|
|
|
|
"2. count (numeric, optional, default=1) The number of blocks to return.\n"
|
|
|
|
" Will return <count> previous blocks if <count> is negative.\n"
|
|
|
|
" Both 1 and -1 correspond to the chain tip.\n"
|
|
|
|
"\nResult:\n"
|
|
|
|
" [ (array) Blocks\n"
|
|
|
|
" {\n"
|
|
|
|
" \"height\" : n, (numeric) The height of the block\n"
|
|
|
|
" \"blockhash\" : \"hash\", (string) The hash of the block\n"
|
|
|
|
" \"amount\": n (numeric) Amount received in this block by all masternodes\n"
|
|
|
|
" \"masternodes\": [ (array) Masternodes that received payments in this block\n"
|
|
|
|
" {\n"
|
|
|
|
" \"proTxHash\": \"xxxx\", (string) The hash of the corresponding ProRegTx\n"
|
|
|
|
" \"amount\": n (numeric) Amount received by this masternode\n"
|
|
|
|
" \"payees\": [ (array) Payees who received a share of this payment\n"
|
|
|
|
" {\n"
|
|
|
|
" \"address\" : \"xxx\", (string) Payee address\n"
|
|
|
|
" \"script\" : \"xxx\", (string) Payee scriptPubKey\n"
|
|
|
|
" \"amount\": n (numeric) Amount received by this payee\n"
|
|
|
|
" },...\n"
|
|
|
|
" ]\n"
|
|
|
|
" },...\n"
|
|
|
|
" ]\n"
|
|
|
|
" },...\n"
|
|
|
|
" ]\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static UniValue masternode_payments(const JSONRPCRequest& request)
|
2020-12-15 03:15:09 +01:00
|
|
|
{
|
|
|
|
if (request.fHelp || request.params.size() > 3) {
|
|
|
|
masternode_payments_help();
|
|
|
|
}
|
|
|
|
|
|
|
|
CBlockIndex* pindex{nullptr};
|
|
|
|
|
2021-05-25 12:48:04 +02:00
|
|
|
if (g_txindex) {
|
|
|
|
g_txindex->BlockUntilSyncedToCurrentChain();
|
|
|
|
}
|
|
|
|
|
2020-12-15 03:15:09 +01:00
|
|
|
if (request.params[1].isNull()) {
|
|
|
|
LOCK(cs_main);
|
|
|
|
pindex = chainActive.Tip();
|
|
|
|
} else {
|
|
|
|
LOCK(cs_main);
|
|
|
|
uint256 blockHash = ParseHashV(request.params[1], "blockhash");
|
2020-12-15 23:41:21 +01:00
|
|
|
pindex = LookupBlockIndex(blockHash);
|
|
|
|
if (pindex == nullptr) {
|
2020-12-15 03:15:09 +01:00
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t nCount = request.params.size() > 2 ? ParseInt64V(request.params[2], "count") : 1;
|
|
|
|
|
|
|
|
// A temporary vector which is used to sort results properly (there is no "reverse" in/for UniValue)
|
|
|
|
std::vector<UniValue> vecPayments;
|
|
|
|
|
|
|
|
while (vecPayments.size() < std::abs(nCount) != 0 && pindex != nullptr) {
|
|
|
|
|
|
|
|
CBlock block;
|
|
|
|
if (!ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
|
|
|
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: we have to actually calculate block reward from scratch instead of simply querying coinbase vout
|
|
|
|
// because miners might collect less coins than they potentially could and this would break our calculations.
|
|
|
|
CAmount nBlockFees{0};
|
|
|
|
for (const auto& tx : block.vtx) {
|
|
|
|
if (tx->IsCoinBase()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CAmount nValueIn{0};
|
|
|
|
for (const auto txin : tx->vin) {
|
|
|
|
CTransactionRef txPrev;
|
|
|
|
uint256 blockHashTmp;
|
|
|
|
GetTransaction(txin.prevout.hash, txPrev, Params().GetConsensus(), blockHashTmp);
|
|
|
|
nValueIn += txPrev->vout[txin.prevout.n].nValue;
|
|
|
|
}
|
|
|
|
nBlockFees += nValueIn - tx->GetValueOut();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<CTxOut> voutMasternodePayments, voutDummy;
|
|
|
|
CMutableTransaction dummyTx;
|
|
|
|
CAmount blockReward = nBlockFees + GetBlockSubsidy(pindex->pprev->nBits, pindex->pprev->nHeight, Params().GetConsensus());
|
|
|
|
FillBlockPayments(dummyTx, pindex->nHeight, blockReward, voutMasternodePayments, voutDummy);
|
|
|
|
|
|
|
|
UniValue blockObj(UniValue::VOBJ);
|
|
|
|
CAmount payedPerBlock{0};
|
|
|
|
|
|
|
|
UniValue masternodeArr(UniValue::VARR);
|
|
|
|
UniValue protxObj(UniValue::VOBJ);
|
|
|
|
UniValue payeesArr(UniValue::VARR);
|
|
|
|
CAmount payedPerMasternode{0};
|
|
|
|
|
|
|
|
for (const auto& txout : voutMasternodePayments) {
|
|
|
|
UniValue obj(UniValue::VOBJ);
|
|
|
|
CTxDestination dest;
|
|
|
|
ExtractDestination(txout.scriptPubKey, dest);
|
|
|
|
obj.pushKV("address", EncodeDestination(dest));
|
|
|
|
obj.pushKV("script", HexStr(txout.scriptPubKey));
|
|
|
|
obj.pushKV("amount", txout.nValue);
|
|
|
|
payedPerMasternode += txout.nValue;
|
|
|
|
payeesArr.push_back(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto dmnPayee = deterministicMNManager->GetListForBlock(pindex).GetMNPayee();
|
|
|
|
protxObj.pushKV("proTxHash", dmnPayee == nullptr ? "" : dmnPayee->proTxHash.ToString());
|
|
|
|
protxObj.pushKV("amount", payedPerMasternode);
|
|
|
|
protxObj.pushKV("payees", payeesArr);
|
|
|
|
payedPerBlock += payedPerMasternode;
|
|
|
|
masternodeArr.push_back(protxObj);
|
|
|
|
|
|
|
|
blockObj.pushKV("height", pindex->nHeight);
|
|
|
|
blockObj.pushKV("blockhash", pindex->GetBlockHash().ToString());
|
|
|
|
blockObj.pushKV("amount", payedPerBlock);
|
|
|
|
blockObj.pushKV("masternodes", masternodeArr);
|
|
|
|
vecPayments.push_back(blockObj);
|
|
|
|
|
|
|
|
if (nCount > 0) {
|
|
|
|
LOCK(cs_main);
|
|
|
|
pindex = chainActive.Next(pindex);
|
|
|
|
} else {
|
|
|
|
pindex = pindex->pprev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nCount < 0) {
|
|
|
|
std::reverse(vecPayments.begin(), vecPayments.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
UniValue paymentsArr(UniValue::VARR);
|
|
|
|
for (const auto& payment : vecPayments) {
|
|
|
|
paymentsArr.push_back(payment);
|
|
|
|
}
|
|
|
|
|
|
|
|
return paymentsArr;
|
|
|
|
}
|
2018-08-29 13:36:35 +02:00
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
[[ noreturn ]] static void masternode_help()
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
|
|
|
throw std::runtime_error(
|
2019-05-30 10:01:16 +02:00
|
|
|
"masternode \"command\" ...\n"
|
2018-08-29 13:36:35 +02:00
|
|
|
"Set of commands to execute masternode related actions\n"
|
|
|
|
"\nArguments:\n"
|
|
|
|
"1. \"command\" (string or set of strings, required) The command to execute\n"
|
|
|
|
"\nAvailable commands:\n"
|
2021-03-26 13:17:25 +01:00
|
|
|
" count - Get information about number of masternodes\n"
|
|
|
|
" current - DEPRECATED Print info on current masternode winner to be paid the next block (calculated locally)\n"
|
2018-08-29 13:36:35 +02:00
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
" outputs - Print masternode compatible outputs\n"
|
|
|
|
#endif // ENABLE_WALLET
|
|
|
|
" status - Print masternode status information\n"
|
|
|
|
" list - Print list of all known masternodes (see masternodelist for more info)\n"
|
2020-12-15 03:15:09 +01:00
|
|
|
" payments - Return information about masternode payments in a mined block\n"
|
2021-03-26 13:17:25 +01:00
|
|
|
" winner - DEPRECATED Print info on next masternode winner to vote for\n"
|
2018-08-29 13:36:35 +02:00
|
|
|
" winners - Print list of masternode winners\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static UniValue masternode(const JSONRPCRequest& request)
|
2018-08-29 13:36:35 +02:00
|
|
|
{
|
|
|
|
std::string strCommand;
|
2017-08-22 09:24:31 +02:00
|
|
|
if (!request.params[0].isNull()) {
|
2018-08-29 13:36:35 +02:00
|
|
|
strCommand = request.params[0].get_str();
|
2018-08-11 00:36:17 +02:00
|
|
|
}
|
|
|
|
|
2018-11-09 07:48:26 +01:00
|
|
|
if (request.fHelp && strCommand.empty()) {
|
2018-09-10 12:23:42 +02:00
|
|
|
masternode_help();
|
|
|
|
}
|
2018-08-29 13:36:35 +02:00
|
|
|
|
|
|
|
if (strCommand == "list") {
|
|
|
|
return masternode_list(request);
|
|
|
|
} else if (strCommand == "connect") {
|
|
|
|
return masternode_connect(request);
|
|
|
|
} else if (strCommand == "count") {
|
|
|
|
return masternode_count(request);
|
|
|
|
} else if (strCommand == "current") {
|
|
|
|
return masternode_current(request);
|
|
|
|
} else if (strCommand == "winner") {
|
|
|
|
return masternode_winner(request);
|
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
} else if (strCommand == "outputs") {
|
|
|
|
return masternode_outputs(request);
|
|
|
|
#endif // ENABLE_WALLET
|
|
|
|
} else if (strCommand == "status") {
|
|
|
|
return masternode_status(request);
|
2020-12-15 03:15:09 +01:00
|
|
|
} else if (strCommand == "payments") {
|
|
|
|
return masternode_payments(request);
|
2018-08-29 13:36:35 +02:00
|
|
|
} else if (strCommand == "winners") {
|
|
|
|
return masternode_winners(request);
|
2018-09-10 12:23:42 +02:00
|
|
|
} else {
|
|
|
|
masternode_help();
|
2018-08-29 13:36:35 +02:00
|
|
|
}
|
2014-12-09 02:17:57 +01:00
|
|
|
}
|
|
|
|
|
2018-05-04 22:42:39 +02:00
|
|
|
static UniValue masternodelist(const JSONRPCRequest& request)
|
2015-02-23 21:26:23 +01:00
|
|
|
{
|
2018-03-08 13:22:13 +01:00
|
|
|
std::string strMode = "json";
|
2015-02-23 21:26:23 +01:00
|
|
|
std::string strFilter = "";
|
|
|
|
|
2017-08-22 09:24:31 +02:00
|
|
|
if (!request.params[0].isNull()) strMode = request.params[0].get_str();
|
|
|
|
if (!request.params[1].isNull()) strFilter = request.params[1].get_str();
|
2015-02-23 21:26:23 +01:00
|
|
|
|
2021-09-09 20:37:36 +02:00
|
|
|
std::transform(strMode.begin(), strMode.end(), strMode.begin(), ToLower);
|
2018-12-31 14:05:23 +01:00
|
|
|
|
2016-10-19 15:01:33 +02:00
|
|
|
if (request.fHelp || (
|
2018-12-17 13:20:16 +01:00
|
|
|
strMode != "addr" && strMode != "full" && strMode != "info" && strMode != "json" &&
|
2019-01-11 11:05:58 +01:00
|
|
|
strMode != "owneraddress" && strMode != "votingaddress" &&
|
2018-12-17 13:20:16 +01:00
|
|
|
strMode != "lastpaidtime" && strMode != "lastpaidblock" &&
|
2018-12-31 14:05:23 +01:00
|
|
|
strMode != "payee" && strMode != "pubkeyoperator" &&
|
2018-12-17 16:02:12 +01:00
|
|
|
strMode != "status"))
|
2015-02-23 21:26:23 +01:00
|
|
|
{
|
2018-08-29 13:36:35 +02:00
|
|
|
masternode_list_help();
|
2015-02-23 21:26:23 +01:00
|
|
|
}
|
|
|
|
|
2016-02-02 16:28:56 +01:00
|
|
|
UniValue obj(UniValue::VOBJ);
|
2018-12-17 16:36:58 +01:00
|
|
|
|
|
|
|
auto mnList = deterministicMNManager->GetListAtChainTip();
|
|
|
|
auto dmnToStatus = [&](const CDeterministicMNCPtr& dmn) {
|
|
|
|
if (mnList.IsMNValid(dmn)) {
|
|
|
|
return "ENABLED";
|
|
|
|
}
|
|
|
|
if (mnList.IsMNPoSeBanned(dmn)) {
|
|
|
|
return "POSE_BANNED";
|
2018-12-17 16:02:12 +01:00
|
|
|
}
|
2018-12-17 16:36:58 +01:00
|
|
|
return "UNKNOWN";
|
|
|
|
};
|
|
|
|
auto dmnToLastPaidTime = [&](const CDeterministicMNCPtr& dmn) {
|
|
|
|
if (dmn->pdmnState->nLastPaidHeight == 0) {
|
|
|
|
return (int)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOCK(cs_main);
|
|
|
|
const CBlockIndex* pindex = chainActive[dmn->pdmnState->nLastPaidHeight];
|
|
|
|
return (int)pindex->nTime;
|
|
|
|
};
|
2018-11-14 15:39:40 +01:00
|
|
|
|
2018-12-17 16:36:58 +01:00
|
|
|
mnList.ForEachMN(false, [&](const CDeterministicMNCPtr& dmn) {
|
|
|
|
std::string strOutpoint = dmn->collateralOutpoint.ToStringShort();
|
2019-03-06 08:01:03 +01:00
|
|
|
Coin coin;
|
|
|
|
std::string collateralAddressStr = "UNKNOWN";
|
|
|
|
if (GetUTXOCoin(dmn->collateralOutpoint, coin)) {
|
|
|
|
CTxDestination collateralDest;
|
|
|
|
if (ExtractDestination(coin.out.scriptPubKey, collateralDest)) {
|
Merge #11117: Prepare for non-Base58 addresses (#3294)
* Merge #11117: Prepare for non-Base58 addresses
864cd2787 Move CBitcoinAddress to base58.cpp (Pieter Wuille)
5c8ff0d44 Introduce wrappers around CBitcoinAddress (Pieter Wuille)
Pull request description:
This patch removes the need for the intermediary Base58 type `CBitcoinAddress`, by providing {`Encode`,`Decode`,`IsValid`}`Destination` functions that directly operate on the conversion between `std::string`s and `CTxDestination`.
As a side, it also fixes a number of indentation issues, and removes probably several unnecessary implicit `CTxDestination`<->`CBitcoinAddress` conversions.
This change is far from complete. In follow-ups I'd like to:
* Split off the specific address and key encoding logic from base58.h, and move it to a address.h or so.
* Replace `CTxDestination` with a non-`boost::variant` version (which can be more efficient as `boost::variant` allocates everything on the heap, and remove the need for `boost::get<...>` and `IsValidDestination` calls everywhere).
* Do the same for `CBitcoinSecret`, `CBitcoinExtKey`, and `CBitcoinExtPubKey`.
However, I've tried to keep this patch to be minimally invasive, but still enough to support non-Base58 addresses. Perhaps a smaller patch is possible to hack Bech32 support into `CBitcoinAddress`, but I would consider that a move in the wrong direction.
Tree-SHA512: c2c77ffb57caeadf2429b1c2562ce60e8c7be8aa9f8e51b591f354b6b441162625b2efe14c023a1ae485cf2ed417263afa35c892891dfaa7844e7fbabccab85e
* CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* more CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* more CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* more CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* fix CBitcoinAddress GetKeyID check
Signed-off-by: Pasta <pasta@dashboost.org>
* fix providertx.cpp
Signed-off-by: Pasta <pasta@dashboost.org>
* hopefully fix governance-classes.cpp
Signed-off-by: Pasta <pasta@dashboost.org>
* partially fix governance-validators.cpp, unable to resolve "address.IsScript()"
Signed-off-by: Pasta <pasta@dashboost.org>
* partially fix governance-classes.cpp, unable to resolve "address.IsScript()"
Signed-off-by: Pasta <pasta@dashboost.org>
* fix governance-classes.h
Signed-off-by: Pasta <pasta@dashboost.org>
* DecodeTransaction -> DecodeDestination, fix governance-validators.cpp
Signed-off-by: Pasta <pasta@dashboost.org>
* More fixes for 3294
* Move GetIndexKey into rpc/misc.cpp near getAddressesFromParams
No need to have it in base58.cpp anymore as this is only used in getAddressesFromParams
Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com>
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Alexander Block <ablock84@gmail.com>
2020-01-22 11:35:04 +01:00
|
|
|
collateralAddressStr = EncodeDestination(collateralDest);
|
2019-03-06 08:01:03 +01:00
|
|
|
}
|
|
|
|
}
|
2018-12-17 16:36:58 +01:00
|
|
|
|
|
|
|
CScript payeeScript = dmn->pdmnState->scriptPayout;
|
2018-12-17 16:02:12 +01:00
|
|
|
CTxDestination payeeDest;
|
2019-03-06 08:01:03 +01:00
|
|
|
std::string payeeStr = "UNKNOWN";
|
2018-12-17 16:02:12 +01:00
|
|
|
if (ExtractDestination(payeeScript, payeeDest)) {
|
Merge #11117: Prepare for non-Base58 addresses (#3294)
* Merge #11117: Prepare for non-Base58 addresses
864cd2787 Move CBitcoinAddress to base58.cpp (Pieter Wuille)
5c8ff0d44 Introduce wrappers around CBitcoinAddress (Pieter Wuille)
Pull request description:
This patch removes the need for the intermediary Base58 type `CBitcoinAddress`, by providing {`Encode`,`Decode`,`IsValid`}`Destination` functions that directly operate on the conversion between `std::string`s and `CTxDestination`.
As a side, it also fixes a number of indentation issues, and removes probably several unnecessary implicit `CTxDestination`<->`CBitcoinAddress` conversions.
This change is far from complete. In follow-ups I'd like to:
* Split off the specific address and key encoding logic from base58.h, and move it to a address.h or so.
* Replace `CTxDestination` with a non-`boost::variant` version (which can be more efficient as `boost::variant` allocates everything on the heap, and remove the need for `boost::get<...>` and `IsValidDestination` calls everywhere).
* Do the same for `CBitcoinSecret`, `CBitcoinExtKey`, and `CBitcoinExtPubKey`.
However, I've tried to keep this patch to be minimally invasive, but still enough to support non-Base58 addresses. Perhaps a smaller patch is possible to hack Bech32 support into `CBitcoinAddress`, but I would consider that a move in the wrong direction.
Tree-SHA512: c2c77ffb57caeadf2429b1c2562ce60e8c7be8aa9f8e51b591f354b6b441162625b2efe14c023a1ae485cf2ed417263afa35c892891dfaa7844e7fbabccab85e
* CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* more CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* more CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* more CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* fix CBitcoinAddress GetKeyID check
Signed-off-by: Pasta <pasta@dashboost.org>
* fix providertx.cpp
Signed-off-by: Pasta <pasta@dashboost.org>
* hopefully fix governance-classes.cpp
Signed-off-by: Pasta <pasta@dashboost.org>
* partially fix governance-validators.cpp, unable to resolve "address.IsScript()"
Signed-off-by: Pasta <pasta@dashboost.org>
* partially fix governance-classes.cpp, unable to resolve "address.IsScript()"
Signed-off-by: Pasta <pasta@dashboost.org>
* fix governance-classes.h
Signed-off-by: Pasta <pasta@dashboost.org>
* DecodeTransaction -> DecodeDestination, fix governance-validators.cpp
Signed-off-by: Pasta <pasta@dashboost.org>
* More fixes for 3294
* Move GetIndexKey into rpc/misc.cpp near getAddressesFromParams
No need to have it in base58.cpp anymore as this is only used in getAddressesFromParams
Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com>
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Alexander Block <ablock84@gmail.com>
2020-01-22 11:35:04 +01:00
|
|
|
payeeStr = EncodeDestination(payeeDest);
|
2018-12-17 16:02:12 +01:00
|
|
|
}
|
2018-11-14 15:39:40 +01:00
|
|
|
|
2018-12-17 16:02:12 +01:00
|
|
|
if (strMode == "addr") {
|
2018-12-31 14:05:23 +01:00
|
|
|
std::string strAddress = dmn->pdmnState->addr.ToString(false);
|
2018-12-17 16:02:12 +01:00
|
|
|
if (strFilter !="" && strAddress.find(strFilter) == std::string::npos &&
|
2018-12-17 16:36:58 +01:00
|
|
|
strOutpoint.find(strFilter) == std::string::npos) return;
|
2020-06-18 11:17:23 +02:00
|
|
|
obj.pushKV(strOutpoint, strAddress);
|
2018-12-17 16:02:12 +01:00
|
|
|
} else if (strMode == "full") {
|
|
|
|
std::ostringstream streamFull;
|
|
|
|
streamFull << std::setw(18) <<
|
2018-12-17 16:36:58 +01:00
|
|
|
dmnToStatus(dmn) << " " <<
|
2018-12-31 14:05:23 +01:00
|
|
|
payeeStr << " " << std::setw(10) <<
|
2018-12-17 16:36:58 +01:00
|
|
|
dmnToLastPaidTime(dmn) << " " << std::setw(6) <<
|
|
|
|
dmn->pdmnState->nLastPaidHeight << " " <<
|
|
|
|
dmn->pdmnState->addr.ToString();
|
2018-12-17 16:02:12 +01:00
|
|
|
std::string strFull = streamFull.str();
|
|
|
|
if (strFilter !="" && strFull.find(strFilter) == std::string::npos &&
|
2018-12-17 16:36:58 +01:00
|
|
|
strOutpoint.find(strFilter) == std::string::npos) return;
|
2020-06-18 11:17:23 +02:00
|
|
|
obj.pushKV(strOutpoint, strFull);
|
2018-12-17 16:02:12 +01:00
|
|
|
} else if (strMode == "info") {
|
|
|
|
std::ostringstream streamInfo;
|
|
|
|
streamInfo << std::setw(18) <<
|
2018-12-17 16:36:58 +01:00
|
|
|
dmnToStatus(dmn) << " " <<
|
2018-12-17 16:02:12 +01:00
|
|
|
payeeStr << " " <<
|
2019-01-08 11:36:35 +01:00
|
|
|
dmn->pdmnState->addr.ToString();
|
2018-12-17 16:02:12 +01:00
|
|
|
std::string strInfo = streamInfo.str();
|
|
|
|
if (strFilter !="" && strInfo.find(strFilter) == std::string::npos &&
|
2018-12-17 16:36:58 +01:00
|
|
|
strOutpoint.find(strFilter) == std::string::npos) return;
|
2020-06-18 11:17:23 +02:00
|
|
|
obj.pushKV(strOutpoint, strInfo);
|
2018-12-17 16:02:12 +01:00
|
|
|
} else if (strMode == "json") {
|
|
|
|
std::ostringstream streamInfo;
|
2019-04-30 14:54:49 +02:00
|
|
|
streamInfo << dmn->proTxHash.ToString() << " " <<
|
|
|
|
dmn->pdmnState->addr.ToString() << " " <<
|
2019-01-08 11:36:35 +01:00
|
|
|
payeeStr << " " <<
|
2018-12-17 16:36:58 +01:00
|
|
|
dmnToStatus(dmn) << " " <<
|
|
|
|
dmnToLastPaidTime(dmn) << " " <<
|
2019-01-08 11:36:35 +01:00
|
|
|
dmn->pdmnState->nLastPaidHeight << " " <<
|
Merge #11117: Prepare for non-Base58 addresses (#3294)
* Merge #11117: Prepare for non-Base58 addresses
864cd2787 Move CBitcoinAddress to base58.cpp (Pieter Wuille)
5c8ff0d44 Introduce wrappers around CBitcoinAddress (Pieter Wuille)
Pull request description:
This patch removes the need for the intermediary Base58 type `CBitcoinAddress`, by providing {`Encode`,`Decode`,`IsValid`}`Destination` functions that directly operate on the conversion between `std::string`s and `CTxDestination`.
As a side, it also fixes a number of indentation issues, and removes probably several unnecessary implicit `CTxDestination`<->`CBitcoinAddress` conversions.
This change is far from complete. In follow-ups I'd like to:
* Split off the specific address and key encoding logic from base58.h, and move it to a address.h or so.
* Replace `CTxDestination` with a non-`boost::variant` version (which can be more efficient as `boost::variant` allocates everything on the heap, and remove the need for `boost::get<...>` and `IsValidDestination` calls everywhere).
* Do the same for `CBitcoinSecret`, `CBitcoinExtKey`, and `CBitcoinExtPubKey`.
However, I've tried to keep this patch to be minimally invasive, but still enough to support non-Base58 addresses. Perhaps a smaller patch is possible to hack Bech32 support into `CBitcoinAddress`, but I would consider that a move in the wrong direction.
Tree-SHA512: c2c77ffb57caeadf2429b1c2562ce60e8c7be8aa9f8e51b591f354b6b441162625b2efe14c023a1ae485cf2ed417263afa35c892891dfaa7844e7fbabccab85e
* CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* more CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* more CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* more CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* fix CBitcoinAddress GetKeyID check
Signed-off-by: Pasta <pasta@dashboost.org>
* fix providertx.cpp
Signed-off-by: Pasta <pasta@dashboost.org>
* hopefully fix governance-classes.cpp
Signed-off-by: Pasta <pasta@dashboost.org>
* partially fix governance-validators.cpp, unable to resolve "address.IsScript()"
Signed-off-by: Pasta <pasta@dashboost.org>
* partially fix governance-classes.cpp, unable to resolve "address.IsScript()"
Signed-off-by: Pasta <pasta@dashboost.org>
* fix governance-classes.h
Signed-off-by: Pasta <pasta@dashboost.org>
* DecodeTransaction -> DecodeDestination, fix governance-validators.cpp
Signed-off-by: Pasta <pasta@dashboost.org>
* More fixes for 3294
* Move GetIndexKey into rpc/misc.cpp near getAddressesFromParams
No need to have it in base58.cpp anymore as this is only used in getAddressesFromParams
Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com>
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Alexander Block <ablock84@gmail.com>
2020-01-22 11:35:04 +01:00
|
|
|
EncodeDestination(dmn->pdmnState->keyIDOwner) << " " <<
|
|
|
|
EncodeDestination(dmn->pdmnState->keyIDVoting) << " " <<
|
2019-03-06 08:01:03 +01:00
|
|
|
collateralAddressStr << " " <<
|
2019-06-13 11:01:26 +02:00
|
|
|
dmn->pdmnState->pubKeyOperator.Get().ToString();
|
2018-12-17 16:02:12 +01:00
|
|
|
std::string strInfo = streamInfo.str();
|
|
|
|
if (strFilter !="" && strInfo.find(strFilter) == std::string::npos &&
|
2018-12-17 16:36:58 +01:00
|
|
|
strOutpoint.find(strFilter) == std::string::npos) return;
|
2018-12-17 16:02:12 +01:00
|
|
|
UniValue objMN(UniValue::VOBJ);
|
2020-06-18 11:17:23 +02:00
|
|
|
objMN.pushKV("proTxHash", dmn->proTxHash.ToString());
|
|
|
|
objMN.pushKV("address", dmn->pdmnState->addr.ToString());
|
|
|
|
objMN.pushKV("payee", payeeStr);
|
|
|
|
objMN.pushKV("status", dmnToStatus(dmn));
|
|
|
|
objMN.pushKV("lastpaidtime", dmnToLastPaidTime(dmn));
|
|
|
|
objMN.pushKV("lastpaidblock", dmn->pdmnState->nLastPaidHeight);
|
|
|
|
objMN.pushKV("owneraddress", EncodeDestination(dmn->pdmnState->keyIDOwner));
|
|
|
|
objMN.pushKV("votingaddress", EncodeDestination(dmn->pdmnState->keyIDVoting));
|
|
|
|
objMN.pushKV("collateraladdress", collateralAddressStr);
|
|
|
|
objMN.pushKV("pubkeyoperator", dmn->pdmnState->pubKeyOperator.Get().ToString());
|
|
|
|
obj.pushKV(strOutpoint, objMN);
|
2018-12-17 16:02:12 +01:00
|
|
|
} else if (strMode == "lastpaidblock") {
|
2018-12-17 16:36:58 +01:00
|
|
|
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) return;
|
2020-06-18 11:17:23 +02:00
|
|
|
obj.pushKV(strOutpoint, dmn->pdmnState->nLastPaidHeight);
|
2018-12-17 16:02:12 +01:00
|
|
|
} else if (strMode == "lastpaidtime") {
|
2018-12-17 16:36:58 +01:00
|
|
|
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) return;
|
2020-06-18 11:17:23 +02:00
|
|
|
obj.pushKV(strOutpoint, dmnToLastPaidTime(dmn));
|
2018-12-17 16:02:12 +01:00
|
|
|
} else if (strMode == "payee") {
|
|
|
|
if (strFilter !="" && payeeStr.find(strFilter) == std::string::npos &&
|
2018-12-17 16:36:58 +01:00
|
|
|
strOutpoint.find(strFilter) == std::string::npos) return;
|
2020-06-18 11:17:23 +02:00
|
|
|
obj.pushKV(strOutpoint, payeeStr);
|
2019-01-11 11:05:58 +01:00
|
|
|
} else if (strMode == "owneraddress") {
|
2018-12-17 16:36:58 +01:00
|
|
|
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) return;
|
2020-06-18 11:17:23 +02:00
|
|
|
obj.pushKV(strOutpoint, EncodeDestination(dmn->pdmnState->keyIDOwner));
|
2018-12-31 14:05:23 +01:00
|
|
|
} else if (strMode == "pubkeyoperator") {
|
2018-12-17 16:36:58 +01:00
|
|
|
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) return;
|
2020-06-18 11:17:23 +02:00
|
|
|
obj.pushKV(strOutpoint, dmn->pdmnState->pubKeyOperator.Get().ToString());
|
2018-12-17 16:02:12 +01:00
|
|
|
} else if (strMode == "status") {
|
2018-12-17 16:36:58 +01:00
|
|
|
std::string strStatus = dmnToStatus(dmn);
|
2018-12-17 16:02:12 +01:00
|
|
|
if (strFilter !="" && strStatus.find(strFilter) == std::string::npos &&
|
2018-12-17 16:36:58 +01:00
|
|
|
strOutpoint.find(strFilter) == std::string::npos) return;
|
2020-06-18 11:17:23 +02:00
|
|
|
obj.pushKV(strOutpoint, strStatus);
|
2019-01-11 11:05:58 +01:00
|
|
|
} else if (strMode == "votingaddress") {
|
|
|
|
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) return;
|
2020-06-18 11:17:23 +02:00
|
|
|
obj.pushKV(strOutpoint, EncodeDestination(dmn->pdmnState->keyIDVoting));
|
2015-02-24 00:48:11 +01:00
|
|
|
}
|
2018-12-17 16:36:58 +01:00
|
|
|
});
|
2018-12-17 16:02:12 +01:00
|
|
|
|
2015-02-24 00:48:11 +01:00
|
|
|
return obj;
|
2016-03-16 16:30:22 +01:00
|
|
|
}
|
|
|
|
|
2016-03-31 10:55:06 +02:00
|
|
|
static const CRPCCommand commands[] =
|
2017-09-05 18:43:07 +02:00
|
|
|
{ // category name actor (function) argNames
|
|
|
|
// --------------------- ------------------------ ----------------------- ----------
|
|
|
|
{ "dash", "masternode", &masternode, {} },
|
|
|
|
{ "dash", "masternodelist", &masternodelist, {} },
|
2016-03-31 10:55:06 +02:00
|
|
|
};
|
|
|
|
|
2016-08-31 16:04:22 +02:00
|
|
|
void RegisterMasternodeRPCCommands(CRPCTable &t)
|
2016-03-31 10:55:06 +02:00
|
|
|
{
|
|
|
|
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
|
2016-08-31 16:04:22 +02:00
|
|
|
t.appendCommand(commands[vcidx].name, &commands[vcidx]);
|
2018-05-13 22:57:12 +02:00
|
|
|
}
|