2016-12-20 14:26:45 +01:00
// Copyright (c) 2014-2017 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.
# include "activemasternode.h"
2017-12-01 19:53:34 +01:00
# include "base58.h"
2018-03-09 13:41:51 +01:00
# include "clientversion.h"
2016-12-20 14:27:59 +01:00
# include "init.h"
2017-09-03 15:29:10 +02:00
# include "netbase.h"
2017-08-09 02:19:06 +02:00
# include "validation.h"
2016-01-24 20:05:31 +01:00
# include "masternode-payments.h"
# include "masternode-sync.h"
2014-12-06 20:41:53 +01:00
# include "masternodeconfig.h"
2016-01-24 20:05:31 +01:00
# include "masternodeman.h"
2017-12-01 19:53:34 +01:00
# ifdef ENABLE_WALLET
2017-05-05 13:26:27 +02:00
# include "privatesend-client.h"
2017-12-01 19:53:34 +01:00
# endif // ENABLE_WALLET
2017-05-05 13:26:27 +02:00
# include "privatesend-server.h"
2017-07-03 15:13:34 +02:00
# include "rpc/server.h"
2016-12-20 14:27:59 +01:00
# include "util.h"
2015-04-03 00:51:08 +02:00
# include "utilmoneystr.h"
2018-08-31 11:47:14 +02:00
# include "txmempool.h"
# include "evo/specialtx.h"
# include "evo/deterministicmns.h"
2014-12-09 02:17:57 +01:00
2018-02-15 19:14:28 +01:00
# include "evo/deterministicmns.h"
2014-12-09 02:17:57 +01:00
# include <fstream>
2016-02-02 16:28:56 +01:00
# include <iomanip>
# include <univalue.h>
2014-12-09 02:17:57 +01:00
2016-10-19 15:01:33 +02:00
UniValue masternodelist ( const JSONRPCRequest & request ) ;
2017-12-20 08:39:44 +01:00
2018-03-01 14:18:46 +01:00
bool EnsureWalletIsAvailable ( bool avoidException ) ;
2017-12-01 19:53:34 +01:00
# ifdef ENABLE_WALLET
2016-09-12 19:38:52 +02:00
void EnsureWalletIsUnlocked ( ) ;
2016-10-19 15:01:33 +02:00
UniValue privatesend ( const JSONRPCRequest & request )
2014-12-09 02:17:57 +01:00
{
2018-03-01 14:18:46 +01:00
if ( ! EnsureWalletIsAvailable ( request . fHelp ) )
return NullUniValue ;
2016-10-19 15:01:33 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 1 )
2016-09-16 17:22:57 +02:00
throw std : : runtime_error (
2016-05-25 07:25:16 +02:00
" privatesend \" command \" \n "
2016-02-01 18:22:00 +01:00
" \n Arguments: \n "
" 1. \" command \" (string or set of strings, required) The command to execute \n "
" \n Available commands: \n "
" start - Start mixing \n "
" stop - Stop mixing \n "
" reset - Reset mixing \n "
2017-02-10 01:51:47 +01:00
) ;
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 ( fMasternodeMode )
2018-03-01 14:18:46 +01:00
throw JSONRPCError ( RPC_INTERNAL_ERROR , " Client-side mixing is not supported on masternodes " ) ;
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 . params [ 0 ] . get_str ( ) = = " start " ) {
2017-02-10 01:51:47 +01:00
{
LOCK ( pwalletMain - > cs_wallet ) ;
2018-06-11 12:13:03 +02:00
if ( pwalletMain - > IsLocked ( true ) )
throw JSONRPCError ( RPC_WALLET_UNLOCK_NEEDED , " Error: Please unlock wallet for mixing with walletpassphrase first. " ) ;
2017-02-10 01:51:47 +01:00
}
2014-12-09 02:17:57 +01:00
2017-05-05 13:26:27 +02:00
privateSendClient . fEnablePrivateSend = true ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
bool result = privateSendClient . DoAutomaticDenominating ( * g_connman ) ;
2018-09-04 12:54:59 +02:00
return " Mixing " + ( result ? " started successfully " : ( " start failed: " + privateSendClient . GetStatuses ( ) + " , will retry " ) ) ;
2016-02-01 18:22:00 +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 . params [ 0 ] . get_str ( ) = = " stop " ) {
2017-05-05 13:26:27 +02:00
privateSendClient . fEnablePrivateSend = false ;
2016-02-01 18:22:00 +01:00
return " Mixing was stopped " ;
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 . params [ 0 ] . get_str ( ) = = " reset " ) {
2017-05-05 13:26:27 +02:00
privateSendClient . ResetPool ( ) ;
2016-02-01 18:22:00 +01:00
return " Mixing was reset " ;
2014-12-09 02:17:57 +01:00
}
2016-05-25 07:25:16 +02:00
return " Unknown command, please see \" help privatesend \" " ;
2014-12-09 02:17:57 +01:00
}
2017-12-01 19:53:34 +01:00
# endif // ENABLE_WALLET
2014-12-09 02:17:57 +01:00
2016-10-19 15:01:33 +02:00
UniValue getpoolinfo ( const JSONRPCRequest & request )
2014-12-09 02:17:57 +01:00
{
2016-10-19 15:01:33 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 0 )
2016-09-16 17:22:57 +02:00
throw std : : runtime_error (
2014-12-09 02:17:57 +01:00
" getpoolinfo \n "
2016-11-21 21:40:56 +01:00
" Returns an object containing mixing pool related information. \n " ) ;
2014-12-09 02:17:57 +01:00
2017-12-01 19:53:34 +01:00
# ifdef ENABLE_WALLET
2018-09-04 12:54:59 +02:00
CPrivateSendBaseManager * pprivateSendBaseManager = fMasternodeMode ? ( CPrivateSendBaseManager * ) & privateSendServer : ( CPrivateSendBaseManager * ) & privateSendClient ;
2017-05-05 13:26:27 +02:00
2016-02-02 16:28:56 +01:00
UniValue obj ( UniValue : : VOBJ ) ;
2018-09-04 12:54:59 +02:00
// TODO:
// obj.push_back(Pair("state", pprivateSendBase->GetStateString()));
obj . push_back ( Pair ( " queue " , pprivateSendBaseManager - > GetQueueSize ( ) ) ) ;
// obj.push_back(Pair("entries", pprivateSendBase->GetEntriesCount()));
obj . push_back ( Pair ( " status " , privateSendClient . GetStatuses ( ) ) ) ;
std : : vector < masternode_info_t > vecMnInfo ;
if ( privateSendClient . GetMixingMasternodesInfo ( vecMnInfo ) ) {
UniValue pools ( UniValue : : VARR ) ;
for ( const auto & mnInfo : vecMnInfo ) {
UniValue pool ( UniValue : : VOBJ ) ;
pool . push_back ( Pair ( " outpoint " , mnInfo . outpoint . ToStringShort ( ) ) ) ;
pool . push_back ( Pair ( " addr " , mnInfo . addr . ToString ( ) ) ) ;
pools . push_back ( pool ) ;
}
obj . push_back ( Pair ( " pools " , pools ) ) ;
2016-11-21 21:40:56 +01:00
}
if ( pwalletMain ) {
obj . push_back ( Pair ( " keys_left " , pwalletMain - > nKeysLeftSinceAutoBackup ) ) ;
obj . push_back ( Pair ( " warnings " , pwalletMain - > nKeysLeftSinceAutoBackup < PRIVATESEND_KEYS_THRESHOLD_WARNING
? " WARNING: keypool is almost depleted! " : " " ) ) ;
}
2017-12-01 19:53:34 +01:00
# else // ENABLE_WALLET
UniValue obj ( UniValue : : VOBJ ) ;
obj . push_back ( Pair ( " state " , privateSendServer . GetStateString ( ) ) ) ;
obj . push_back ( Pair ( " queue " , privateSendServer . GetQueueSize ( ) ) ) ;
obj . push_back ( Pair ( " entries " , privateSendServer . GetEntriesCount ( ) ) ) ;
# endif // ENABLE_WALLET
2016-11-21 21:40:56 +01:00
2014-12-09 02:17:57 +01:00
return obj ;
}
2018-08-29 13:36:35 +02:00
void masternode_list_help ( )
{
throw std : : runtime_error (
" masternode list ( \" mode \" \" filter \" ) \n "
" Get a list of masternodes in different modes. This call is identical to masternodelist call. \n "
" \n Arguments: \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 "
" \n Available modes: \n "
" activeseconds - Print number of seconds masternode recognized by the network as enabled \n "
" (since latest issued \" masternode start/start-many/start-alias \" ) \n "
" addr - Print ip address associated with a masternode (can be additionally filtered, partial match) \n "
" daemon - Print daemon version of a masternode (can be additionally filtered, exact match) \n "
" full - Print info in format 'status protocol payee lastseen activeseconds lastpaidtime lastpaidblock IP' \n "
" (can be additionally filtered, partial match) \n "
" info - Print info in format 'status protocol payee lastseen activeseconds sentinelversion sentinelstate IP' \n "
" (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 "
" lastseen - Print timestamp of when a masternode was last seen on the network \n "
" payee - Print Dash address associated with a masternode (can be additionally filtered, \n "
" partial match) \n "
" protocol - Print protocol of a masternode (can be additionally filtered, exact match) \n "
" keyid - Print the masternode (not collateral) key id \n "
" rank - Print rank of a masternode based on current block \n "
" sentinel - Print sentinel version of a masternode (can be additionally filtered, exact match) \n "
" status - Print masternode status: PRE_ENABLED / ENABLED / EXPIRED / SENTINEL_PING_EXPIRED / NEW_START_REQUIRED / \n "
" UPDATE_REQUIRED / POSE_BAN / OUTPOINT_SPENT (can be additionally filtered, partial match) \n "
) ;
}
2014-12-06 20:41:53 +01:00
2018-08-29 13:36:35 +02:00
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-08-29 13:36:35 +02:00
void masternode_connect_help ( )
{
throw std : : runtime_error (
" masternode connect \" address \" \n "
" Connect to given masternode \n "
" \n Arguments: \n "
" 1. \" address \" (string, required) The address of the masternode to connect \n "
) ;
}
2014-12-09 02:17:57 +01:00
2018-08-29 13:36:35 +02:00
UniValue masternode_connect ( const JSONRPCRequest & request )
{
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-08-29 13:36:35 +02:00
void masternode_count_help ( )
{
throw std : : runtime_error (
" masternode count ( \" mode \" ) \n "
" Get information about number of masternodes. Mode \n "
" usage is depricated, call without mode params returns \n "
" all values in JSON format. \n "
" \n Arguments: \n "
" 1. \" mode \" (string, optional, DEPRICATED) Option to get number of masternodes in different states \n "
" \n Available modes: \n "
" total - total number of masternodes "
" ps - number of PrivateSend compatible masternodes "
" enabled - number of enabled masternodes "
" qualify - number of qualified masternodes "
" all - all above in one string "
) ;
}
2015-07-18 21:17:17 +02:00
2018-08-29 13:36:35 +02:00
UniValue masternode_count ( const JSONRPCRequest & request )
{
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_count_help ( ) ;
2015-08-20 17:36:44 +02:00
2018-08-29 13:36:35 +02:00
int nCount ;
2018-02-15 19:14:28 +01:00
int total ;
if ( deterministicMNManager - > IsDeterministicMNsSporkActive ( ) ) {
nCount = total = mnodeman . CountEnabled ( ) ;
} else {
masternode_info_t mnInfo ;
mnodeman . GetNextMasternodeInQueueForPayment ( true , nCount , mnInfo ) ;
total = mnodeman . size ( ) ;
}
2018-02-08 06:43:19 +01:00
2018-08-29 13:36:35 +02:00
int ps = mnodeman . CountEnabled ( MIN_PRIVATESEND_PEER_PROTO_VERSION ) ;
int enabled = mnodeman . CountEnabled ( ) ;
2018-02-08 06:43:19 +01:00
2018-08-29 13:36:35 +02:00
if ( request . params . size ( ) = = 1 ) {
UniValue obj ( UniValue : : VOBJ ) ;
2018-02-08 06:43:19 +01:00
2018-08-29 13:36:35 +02:00
obj . push_back ( Pair ( " total " , total ) ) ;
obj . push_back ( Pair ( " ps_compatible " , ps ) ) ;
obj . push_back ( Pair ( " enabled " , enabled ) ) ;
obj . push_back ( Pair ( " qualify " , nCount ) ) ;
2018-02-08 06:43:19 +01:00
2018-08-29 13:36:35 +02:00
return obj ;
}
2015-08-20 17:36:44 +02:00
2018-08-29 13:36:35 +02:00
std : : string strMode = request . params [ 1 ] . get_str ( ) ;
2016-09-16 17:22:57 +02:00
2018-08-29 13:36:35 +02:00
if ( strMode = = " total " )
return total ;
2018-02-08 06:43:19 +01:00
2018-08-29 13:36:35 +02:00
if ( strMode = = " ps " )
return ps ;
2016-09-16 17:22:57 +02:00
2018-08-29 13:36:35 +02:00
if ( strMode = = " enabled " )
return enabled ;
2016-09-16 17:22:57 +02:00
2018-08-29 13:36:35 +02:00
if ( strMode = = " qualify " )
return nCount ;
2016-09-16 17:22:57 +02:00
2018-08-29 13:36:35 +02:00
if ( strMode = = " all " )
return strprintf ( " Total: %d (PS Compatible: %d / Enabled: %d / Qualify: %d) " ,
total , ps , enabled , nCount ) ;
2014-12-09 02:17:57 +01:00
2018-08-29 13:36:35 +02:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Unknown mode value " ) ;
}
UniValue GetNextMasternodeForPayment ( int heightShift )
{
int nCount ;
int nHeight ;
masternode_info_t mnInfo ;
CBlockIndex * pindex = NULL ;
2015-07-18 21:17:17 +02:00
{
2018-08-29 13:36:35 +02:00
LOCK ( cs_main ) ;
pindex = chainActive . Tip ( ) ;
}
2018-02-15 19:14:28 +01:00
2018-08-29 13:36:35 +02:00
nHeight = pindex - > nHeight + heightShift ;
mnodeman . UpdateLastPaid ( pindex ) ;
2017-10-17 18:40:25 +02:00
2018-02-15 19:14:28 +01:00
if ( deterministicMNManager - > IsDeterministicMNsSporkActive ( ) ) {
auto payee = deterministicMNManager - > GetListAtChainTip ( ) . GetMNPayee ( ) ;
if ( ! payee | | ! mnodeman . GetMasternodeInfo ( payee - > proTxHash , mnInfo ) )
return " unknown " ;
} else {
if ( ! mnodeman . GetNextMasternodeInQueueForPayment ( nHeight , true , nCount , mnInfo ) )
return " unknown " ;
}
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
2018-08-29 13:36:35 +02:00
obj . push_back ( Pair ( " height " , nHeight ) ) ;
obj . push_back ( Pair ( " IP:port " , mnInfo . addr . ToString ( ) ) ) ;
obj . push_back ( Pair ( " protocol " , mnInfo . nProtocolVersion ) ) ;
obj . push_back ( Pair ( " outpoint " , mnInfo . outpoint . ToStringShort ( ) ) ) ;
obj . push_back ( Pair ( " payee " , CBitcoinAddress ( mnInfo . keyIDCollateralAddress ) . ToString ( ) ) ) ;
obj . push_back ( Pair ( " lastseen " , mnInfo . nTimeLastPing ) ) ;
obj . push_back ( Pair ( " activeseconds " , mnInfo . nTimeLastPing - mnInfo . sigTime ) ) ;
return obj ;
}
2015-07-18 21:17:17 +02:00
2018-08-29 13:36:35 +02:00
void masternode_winner_help ( )
{
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-08-29 13:36:35 +02:00
UniValue masternode_winner ( const JSONRPCRequest & request )
{
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_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-08-29 13:36:35 +02:00
void masternode_current_help ( )
{
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-08-29 13:36:35 +02:00
UniValue masternode_current ( const JSONRPCRequest & request )
{
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_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
void masternode_start_alias_help ( )
{
throw std : : runtime_error (
" masternode start-alias \" alias \" \n "
" Start single remote masternode by assigned alias \n "
" \n Arguments: \n "
" 1. \" alias \" (string, required) The alias of the remote masternode configured in masternode.conf \n "
) ;
}
2015-07-18 03:23:52 +02:00
2018-08-29 13:36:35 +02:00
UniValue masternode_start_alias ( const JSONRPCRequest & request )
{
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_start_alias_help ( ) ;
2018-02-23 13:30:02 +01:00
if ( deterministicMNManager - > IsDeterministicMNsSporkActive ( ) )
throw JSONRPCError ( RPC_MISC_ERROR , " start-alias is not supported when deterministic masternode list is active (DIP3) " ) ;
2014-12-09 02:17:57 +01:00
2018-08-29 13:36:35 +02:00
if ( ! EnsureWalletIsAvailable ( request . fHelp ) )
return NullUniValue ;
2014-12-26 21:00:56 +01:00
{
2018-08-29 13:36:35 +02:00
LOCK ( pwalletMain - > cs_wallet ) ;
EnsureWalletIsUnlocked ( ) ;
}
2014-12-06 20:41:53 +01:00
2018-08-29 13:36:35 +02:00
std : : string strAlias = request . params [ 1 ] . get_str ( ) ;
2015-08-31 06:20:38 +02:00
2018-08-29 13:36:35 +02:00
bool fFound = false ;
2014-12-06 20:41:53 +01:00
2018-08-29 13:36:35 +02:00
UniValue statusObj ( UniValue : : VOBJ ) ;
statusObj . push_back ( Pair ( " alias " , strAlias ) ) ;
2014-12-06 20:41:53 +01:00
2018-08-29 13:36:35 +02:00
for ( const auto & mne : masternodeConfig . getEntries ( ) ) {
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 ( mne . getAlias ( ) = = strAlias ) {
2018-08-29 13:36:35 +02:00
fFound = true ;
2016-09-16 17:22:57 +02:00
std : : string strError ;
2016-03-16 16:30:22 +01:00
CMasternodeBroadcast mnb ;
2015-08-26 22:15:37 +02:00
2016-09-16 17:22:57 +02:00
bool fResult = CMasternodeBroadcast : : Create ( mne . getIp ( ) , mne . getPrivKey ( ) , mne . getTxHash ( ) , mne . getOutputIndex ( ) , strError , mnb ) ;
2014-12-06 20:41:53 +01:00
2018-02-21 17:32:51 +01:00
int nDoS ;
if ( fResult & & ! mnodeman . CheckMnbAndUpdateMasternodeList ( NULL , mnb , nDoS , * g_connman ) ) {
strError = " Failed to verify MNB " ;
fResult = false ;
}
2016-09-16 17:22:57 +02:00
statusObj . push_back ( Pair ( " result " , fResult ? " successful " : " failed " ) ) ;
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 ( ! fResult ) {
2016-09-16 17:22:57 +02:00
statusObj . push_back ( Pair ( " errorMessage " , strError ) ) ;
2015-07-18 03:23:52 +02:00
}
2018-08-29 13:36:35 +02:00
mnodeman . NotifyMasternodeUpdates ( * g_connman ) ;
break ;
}
}
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 ( ! fFound ) {
2018-08-29 13:36:35 +02:00
statusObj . push_back ( Pair ( " result " , " failed " ) ) ;
statusObj . push_back ( Pair ( " errorMessage " , " Could not find alias in config. Verify with list-conf. " ) ) ;
}
return statusObj ;
}
void masternode_start_all_help ( )
{
throw std : : runtime_error (
" masternode start-all \n "
" Start remote masternodes configured in masternode.conf \n "
) ;
}
UniValue StartMasternodeList ( const std : : vector < CMasternodeConfig : : CMasternodeEntry > & entries )
{
int nSuccessful = 0 ;
int nFailed = 0 ;
UniValue resultsObj ( UniValue : : VOBJ ) ;
for ( const auto & mne : entries ) {
std : : string strError ;
CMasternodeBroadcast mnb ;
bool fResult = CMasternodeBroadcast : : Create ( mne . getIp ( ) , mne . getPrivKey ( ) , mne . getTxHash ( ) , mne . getOutputIndex ( ) , strError , mnb ) ;
2014-12-06 20:41:53 +01:00
2018-08-29 13:36:35 +02:00
int nDoS ;
if ( fResult & & ! mnodeman . CheckMnbAndUpdateMasternodeList ( NULL , mnb , nDoS , * g_connman ) ) {
strError = " Failed to verify MNB " ;
fResult = false ;
2015-07-18 03:23:52 +02:00
}
2014-12-06 20:41:53 +01:00
2018-08-29 13:36:35 +02:00
UniValue statusObj ( UniValue : : VOBJ ) ;
statusObj . push_back ( Pair ( " alias " , mne . getAlias ( ) ) ) ;
statusObj . push_back ( Pair ( " result " , fResult ? " successful " : " failed " ) ) ;
if ( fResult ) {
nSuccessful + + ;
} else {
nFailed + + ;
statusObj . push_back ( Pair ( " errorMessage " , strError ) ) ;
}
2014-12-06 20:41:53 +01:00
2018-08-29 13:36:35 +02:00
resultsObj . push_back ( Pair ( " status " , statusObj ) ) ;
2014-12-06 20:41:53 +01:00
}
2018-08-29 13:36:35 +02:00
mnodeman . NotifyMasternodeUpdates ( * g_connman ) ;
UniValue returnObj ( UniValue : : VOBJ ) ;
returnObj . push_back ( Pair ( " overall " , strprintf ( " Successfully started %d masternodes, failed to start %d, total %d " , nSuccessful , nFailed , nSuccessful + nFailed ) ) ) ;
returnObj . push_back ( Pair ( " detail " , resultsObj ) ) ;
return returnObj ;
}
UniValue masternode_start_all ( const JSONRPCRequest & request )
{
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_start_all_help ( ) ;
2018-02-23 13:30:02 +01:00
if ( deterministicMNManager - > IsDeterministicMNsSporkActive ( ) )
throw JSONRPCError ( RPC_MISC_ERROR , strprintf ( " start-all is not supported when deterministic masternode list is active (DIP3) " )) ;
2018-08-29 13:36:35 +02:00
if ( ! EnsureWalletIsAvailable ( request . fHelp ) )
return NullUniValue ;
2014-12-09 02:17:57 +01:00
{
2018-08-29 13:36:35 +02:00
LOCK ( pwalletMain - > cs_wallet ) ;
EnsureWalletIsUnlocked ( ) ;
}
return StartMasternodeList ( masternodeConfig . getEntries ( ) ) ;
}
void masternode_start_missing_help ( )
{
throw std : : runtime_error (
" masternode start-missing \n "
" Start not started remote masternodes configured in masternode.conf \n "
) ;
}
UniValue masternode_start_missing ( const JSONRPCRequest & request )
{
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_start_missing_help ( ) ;
if ( ! EnsureWalletIsAvailable ( request . fHelp ) )
return NullUniValue ;
{
LOCK ( pwalletMain - > cs_wallet ) ;
EnsureWalletIsUnlocked ( ) ;
}
2018-08-21 16:08:11 +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 ( ! masternodeSync . IsMasternodeListSynced ( ) ) {
2018-08-29 13:36:35 +02:00
throw JSONRPCError ( RPC_CLIENT_IN_INITIAL_DOWNLOAD , " You can't use this command until masternode list is synced " ) ;
}
2014-12-09 02:17:57 +01:00
2018-08-29 13:36:35 +02:00
std : : vector < CMasternodeConfig : : CMasternodeEntry > entries ;
for ( const auto & mne : masternodeConfig . getEntries ( ) ) {
COutPoint outpoint = COutPoint ( uint256S ( mne . getTxHash ( ) ) , ( uint32_t ) atoi ( mne . getOutputIndex ( ) ) ) ;
CMasternode mn ;
bool fFound = mnodeman . Get ( outpoint , mn ) ;
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 ( fFound )
2018-08-29 13:36:35 +02:00
entries . push_back ( mne ) ;
2014-12-09 02:17:57 +01:00
}
2018-08-29 13:36:35 +02:00
return StartMasternodeList ( entries ) ;
}
void masternode_start_disabled_help ( )
{
throw std : : runtime_error (
" masternode start-disabled \n "
" Start not started and disabled remote masternodes configured in masternode.conf \n "
) ;
}
UniValue masternode_start_disabled ( const JSONRPCRequest & request )
{
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_start_disabled_help ( ) ;
if ( ! EnsureWalletIsAvailable ( request . fHelp ) )
return NullUniValue ;
2014-12-09 02:17:57 +01:00
2014-12-06 20:41:53 +01:00
{
2018-08-29 13:36:35 +02:00
LOCK ( pwalletMain - > cs_wallet ) ;
EnsureWalletIsUnlocked ( ) ;
}
2014-12-06 20:41:53 +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 ( ! masternodeSync . IsMasternodeListSynced ( ) ) {
2018-08-29 13:36:35 +02:00
throw JSONRPCError ( RPC_CLIENT_IN_INITIAL_DOWNLOAD , " You can't use this command until masternode list is synced " ) ;
2014-12-06 20:41:53 +01:00
}
2018-08-29 13:36:35 +02:00
std : : vector < CMasternodeConfig : : CMasternodeEntry > entries ;
for ( const auto & mne : masternodeConfig . getEntries ( ) ) {
COutPoint outpoint = COutPoint ( uint256S ( mne . getTxHash ( ) ) , ( uint32_t ) atoi ( mne . getOutputIndex ( ) ) ) ;
CMasternode mn ;
bool fFound = mnodeman . Get ( outpoint , mn ) ;
2018-03-01 14:18:46 +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 ( fFound & & mn . IsEnabled ( ) ) continue ;
2014-12-26 21:00:56 +01:00
2018-08-29 13:36:35 +02:00
entries . push_back ( mne ) ;
}
return StartMasternodeList ( entries ) ;
}
2014-12-26 21:00:56 +01:00
2018-08-29 13:36:35 +02:00
void masternode_outputs_help ( )
{
throw std : : runtime_error (
" masternode outputs \n "
" Print masternode compatible outputs \n "
) ;
}
UniValue masternode_outputs ( const JSONRPCRequest & request )
{
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_outputs_help ( ) ;
if ( ! EnsureWalletIsAvailable ( request . fHelp ) )
return NullUniValue ;
// Find possible candidates
std : : vector < COutput > vPossibleCoins ;
pwalletMain - > AvailableCoins ( vPossibleCoins , true , NULL , false , ONLY_1000 ) ;
UniValue obj ( UniValue : : VOBJ ) ;
for ( const auto & out : vPossibleCoins ) {
obj . push_back ( Pair ( 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-08-29 13:36:35 +02:00
void masternode_genkey_help ( )
{
throw std : : runtime_error (
" masternode genkey (compressed) \n "
" Generate new masternodeprivkey \n "
" \n Arguments: \n "
" 1. compressed (boolean, optional, default=false) generate compressed privkey \n "
) ;
}
2015-06-24 18:41:03 +02:00
2018-08-29 13:36:35 +02:00
UniValue masternode_genkey ( const JSONRPCRequest & request )
{
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_genkey_help ( ) ;
2015-08-28 22:18:55 +02:00
2018-08-29 13:36:35 +02:00
bool fCompressed = false ;
if ( request . params . size ( ) > 1 ) {
fCompressed = ParseBoolV ( request . params [ 1 ] , " compressed " ) ;
}
CKey secret ;
secret . MakeNewKey ( fCompressed ) ;
return CBitcoinSecret ( secret ) . ToString ( ) ;
}
void masternode_list_conf_help ( )
{
throw std : : runtime_error (
" masternode list-conf \n "
" Print masternode.conf in JSON format \n "
) ;
}
UniValue masternode_list_conf ( const JSONRPCRequest & request )
{
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_conf_help ( ) ;
2016-09-18 23:13:23 +02:00
2018-08-29 13:36:35 +02:00
UniValue resultObj ( UniValue : : VOBJ ) ;
for ( const auto & mne : masternodeConfig . getEntries ( ) ) {
COutPoint outpoint = COutPoint ( uint256S ( mne . getTxHash ( ) ) , ( uint32_t ) atoi ( mne . getOutputIndex ( ) ) ) ;
2016-09-18 23:13:23 +02:00
CMasternode mn ;
2018-08-29 13:36:35 +02:00
bool fFound = mnodeman . Get ( outpoint , mn ) ;
2016-09-18 23:13:23 +02:00
2018-08-29 13:36:35 +02:00
std : : string strStatus = fFound ? mn . GetStatus ( ) : " MISSING " ;
UniValue mnObj ( UniValue : : VOBJ ) ;
mnObj . push_back ( Pair ( " alias " , mne . getAlias ( ) ) ) ;
mnObj . push_back ( Pair ( " address " , mne . getIp ( ) ) ) ;
mnObj . push_back ( Pair ( " privateKey " , mne . getPrivKey ( ) ) ) ;
mnObj . push_back ( Pair ( " txHash " , mne . getTxHash ( ) ) ) ;
mnObj . push_back ( Pair ( " outputIndex " , mne . getOutputIndex ( ) ) ) ;
mnObj . push_back ( Pair ( " status " , strStatus ) ) ;
resultObj . push_back ( Pair ( " masternode " , mnObj ) ) ;
2015-06-24 18:41:03 +02:00
}
2018-08-29 13:36:35 +02:00
return resultObj ;
}
2016-03-02 21:57:24 +01:00
2018-08-29 13:36:35 +02:00
void masternode_status_help ( )
{
throw std : : runtime_error (
" masternode status \n "
" Print masternode status information \n "
) ;
}
2016-03-02 21:57:24 +01:00
2018-08-29 13:36:35 +02:00
UniValue masternode_status ( const JSONRPCRequest & request )
{
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
2018-02-23 13:30:36 +01:00
// keep compatibility with legacy status for now (might get deprecated/removed later)
2018-08-29 13:36:35 +02:00
mnObj . push_back ( Pair ( " outpoint " , activeMasternodeInfo . outpoint . ToStringShort ( ) ) ) ;
mnObj . push_back ( Pair ( " service " , activeMasternodeInfo . service . ToString ( ) ) ) ;
2016-03-06 17:44:21 +01:00
2018-02-23 13:30:36 +01:00
if ( deterministicMNManager - > IsDeterministicMNsSporkActive ( ) ) {
auto dmn = activeMasternodeManager - > GetDMN ( ) ;
if ( dmn ) {
mnObj . push_back ( Pair ( " proTxHash " , dmn - > proTxHash . ToString ( ) ) ) ;
2018-10-25 16:29:50 +02:00
mnObj . push_back ( Pair ( " collateralHash " , dmn - > collateralOutpoint . hash . ToString ( ) ) ) ;
mnObj . push_back ( Pair ( " collateralIndex " , ( int ) dmn - > collateralOutpoint . n ) ) ;
2018-02-23 13:30:36 +01:00
UniValue stateObj ;
dmn - > pdmnState - > ToJson ( stateObj ) ;
mnObj . push_back ( Pair ( " dmnState " , stateObj ) ) ;
}
mnObj . push_back ( Pair ( " state " , activeMasternodeManager - > GetStateString ( ) ) ) ;
mnObj . push_back ( Pair ( " status " , activeMasternodeManager - > GetStatus ( ) ) ) ;
} else {
CMasternode mn ;
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 ( mnodeman . Get ( activeMasternodeInfo . outpoint , mn ) ) {
2018-02-23 13:30:36 +01:00
mnObj . push_back ( Pair ( " payee " , CBitcoinAddress ( mn . keyIDCollateralAddress ) . ToString ( ) ) ) ;
}
2015-07-18 21:17:17 +02:00
2018-02-23 13:30:36 +01:00
mnObj . push_back ( Pair ( " status " , legacyActiveMasternodeManager . GetStatus ( ) ) ) ;
}
2018-08-29 13:36:35 +02:00
return mnObj ;
}
2015-07-18 21:17:17 +02:00
2018-08-29 13:36:35 +02:00
void masternode_winners_help ( )
{
throw std : : runtime_error (
" masternode winners ( count \" filter \" ) \n "
" Print list of masternode winners \n "
" \n Arguments: \n "
" 1. count (numeric, optional) number of last winners to return \n "
" 2. filter (string, optional) filter for returned winners \n "
) ;
}
UniValue masternode_winners ( const JSONRPCRequest & request )
{
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_winners_help ( ) ;
int nHeight ;
{
LOCK ( cs_main ) ;
CBlockIndex * pindex = chainActive . Tip ( ) ;
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 ( ! pindex ) return NullUniValue ;
2018-08-29 13:36:35 +02:00
nHeight = pindex - > nHeight ;
2015-07-18 21:17:17 +02:00
}
2018-08-29 13:36:35 +02:00
int nLast = 10 ;
std : : string strFilter = " " ;
2018-08-11 00:36:17 +02:00
2018-08-29 13:36:35 +02:00
if ( request . params . size ( ) > = 2 ) {
nLast = atoi ( request . params [ 1 ] . get_str ( ) ) ;
}
2018-08-11 00:36:17 +02:00
2018-08-29 13:36:35 +02:00
if ( request . params . size ( ) = = 3 ) {
strFilter = request . params [ 2 ] . get_str ( ) ;
}
2018-08-11 00:36:17 +02:00
2018-08-29 13:36:35 +02:00
if ( request . params . size ( ) > 3 )
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Correct usage is 'masternode winners ( \" count \" \" filter \" ) ' " ) ;
2018-08-11 00:36:17 +02:00
2018-08-29 13:36:35 +02:00
UniValue obj ( UniValue : : VOBJ ) ;
2018-04-04 17:20:54 +02:00
auto mapPayments = GetRequiredPaymentsStrings ( nHeight - nLast , nHeight + 20 ) ;
for ( const auto & p : mapPayments ) {
obj . push_back ( Pair ( strprintf ( " %d " , p . first ) , p . second ) ) ;
2018-08-29 13:36:35 +02:00
}
return obj ;
}
void masternode_check_help ( )
{
throw std : : runtime_error (
" masternode check \n "
" Force check all masternodes and remove invalid ones \n "
) ;
}
UniValue masternode_check ( const JSONRPCRequest & request )
{
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_check_help ( ) ;
int countBeforeCheck = mnodeman . CountMasternodes ( ) ;
int countEnabledBeforeCheck = mnodeman . CountEnabled ( ) ;
mnodeman . CheckAndRemove ( * g_connman ) ;
int countAfterCheck = mnodeman . CountMasternodes ( ) ;
int countEnabledAfterCheck = mnodeman . CountEnabled ( ) ;
int removedCount = std : : max ( 0 , countBeforeCheck - countAfterCheck ) ;
int removedEnabledCount = std : : max ( 0 , countEnabledBeforeCheck - countEnabledAfterCheck ) ;
UniValue obj ( UniValue : : VOBJ ) ;
obj . push_back ( Pair ( " removedTotalCount " , removedCount ) ) ;
obj . push_back ( Pair ( " removedEnabledCount " , removedEnabledCount ) ) ;
obj . push_back ( Pair ( " totalCount " , countAfterCheck ) ) ;
obj . push_back ( Pair ( " enabledCount " , countEnabledAfterCheck ) ) ;
return obj ;
}
2018-11-05 10:28:38 +01:00
[[ noreturn ]] void masternode_help ( )
2018-08-29 13:36:35 +02:00
{
throw std : : runtime_error (
" masternode \" command \" ... \n "
" Set of commands to execute masternode related actions \n "
" \n Arguments: \n "
" 1. \" command \" (string or set of strings, required) The command to execute \n "
" \n Available commands: \n "
" check - Force check all masternodes and remove invalid ones \n "
" count - Get information about number of masternodes (DEPRECATED options: 'total', 'ps', 'enabled', 'qualify', 'all') \n "
" current - Print info on current masternode winner to be paid the next block (calculated locally) \n "
" genkey - Generate new masternodeprivkey, optional param: 'compressed' (boolean, optional, default=false) generate compressed privkey \n "
# ifdef ENABLE_WALLET
" outputs - Print masternode compatible outputs \n "
" start-alias - Start single remote masternode by assigned alias configured in masternode.conf \n "
" start-<mode> - Start remote masternodes configured in masternode.conf (<mode>: 'all', 'missing', 'disabled') \n "
# endif // ENABLE_WALLET
" status - Print masternode status information \n "
" list - Print list of all known masternodes (see masternodelist for more info) \n "
" list-conf - Print masternode.conf in JSON format \n "
" winner - Print info on next masternode winner to vote for \n "
" winners - Print list of masternode winners \n "
) ;
}
UniValue masternode ( const JSONRPCRequest & request )
{
std : : string strCommand ;
if ( request . params . size ( ) > = 1 ) {
strCommand = request . params [ 0 ] . get_str ( ) ;
2018-08-11 00:36:17 +02:00
}
2018-08-29 13:36:35 +02:00
# ifdef ENABLE_WALLET
if ( strCommand = = " start-many " )
throw JSONRPCError ( RPC_INVALID_PARAMETER , " DEPRECATED, please use start-all instead " ) ;
# endif // ENABLE_WALLET
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 = = " start-alias " ) {
return masternode_start_alias ( request ) ;
} else if ( strCommand = = " start-all " ) {
return masternode_start_all ( request ) ;
} else if ( strCommand = = " start-missing " ) {
return masternode_start_missing ( request ) ;
} else if ( strCommand = = " start-disabled " ) {
return masternode_start_disabled ( request ) ;
# endif // ENABLE_WALLET
} else if ( strCommand = = " genkey " ) {
return masternode_genkey ( request ) ;
} else if ( strCommand = = " list-conf " ) {
return masternode_list_conf ( request ) ;
# ifdef ENABLE_WALLET
} else if ( strCommand = = " outputs " ) {
return masternode_outputs ( request ) ;
# endif // ENABLE_WALLET
} else if ( strCommand = = " status " ) {
return masternode_status ( request ) ;
} else if ( strCommand = = " winners " ) {
return masternode_winners ( request ) ;
} else if ( strCommand = = " check " ) {
return masternode_check ( 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
}
2016-10-19 15:01:33 +02:00
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 = " " ;
2016-10-19 15:01:33 +02:00
if ( request . params . size ( ) > = 1 ) strMode = request . params [ 0 ] . get_str ( ) ;
if ( request . params . size ( ) = = 2 ) strFilter = request . params [ 1 ] . get_str ( ) ;
2015-02-23 21:26:23 +01:00
2016-10-19 15:01:33 +02:00
if ( request . fHelp | | (
2018-03-08 13:22:13 +01:00
strMode ! = " activeseconds " & & strMode ! = " addr " & & strMode ! = " daemon " & & strMode ! = " full " & & strMode ! = " info " & & strMode ! = " json " & &
2016-09-11 22:22:37 +02:00
strMode ! = " lastseen " & & strMode ! = " lastpaidtime " & & strMode ! = " lastpaidblock " & &
2017-07-22 22:33:42 +02:00
strMode ! = " protocol " & & strMode ! = " payee " & & strMode ! = " pubkey " & &
2018-03-08 13:22:13 +01:00
strMode ! = " rank " & & strMode ! = " sentinel " & & 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
}
2018-03-08 13:22:13 +01:00
if ( strMode = = " full " | | strMode = = " json " | | strMode = = " lastpaidtime " | | strMode = = " lastpaidblock " ) {
2017-08-25 14:57:05 +02:00
CBlockIndex * pindex = NULL ;
{
LOCK ( cs_main ) ;
pindex = chainActive . Tip ( ) ;
}
mnodeman . UpdateLastPaid ( pindex ) ;
2016-09-11 22:22:37 +02:00
}
2016-02-02 16:28:56 +01:00
UniValue obj ( UniValue : : VOBJ ) ;
2015-03-14 19:34:51 +01:00
if ( strMode = = " rank " ) {
2017-09-14 15:58:29 +02:00
CMasternodeMan : : rank_pair_vec_t vMasternodeRanks ;
mnodeman . GetMasternodeRanks ( vMasternodeRanks ) ;
2018-02-06 12:09:33 +01:00
for ( const auto & rankpair : vMasternodeRanks ) {
2018-02-15 08:29:44 +01:00
std : : string strOutpoint = rankpair . second . outpoint . ToStringShort ( ) ;
2016-09-16 17:22:57 +02:00
if ( strFilter ! = " " & & strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
2018-02-06 12:09:33 +01:00
obj . push_back ( Pair ( strOutpoint , rankpair . first ) ) ;
2015-03-14 19:34:51 +01:00
}
} else {
2017-09-11 16:13:48 +02:00
std : : map < COutPoint , CMasternode > mapMasternodes = mnodeman . GetFullMasternodeMap ( ) ;
2018-02-06 12:09:33 +01:00
for ( const auto & mnpair : mapMasternodes ) {
2017-09-11 16:13:48 +02:00
CMasternode mn = mnpair . second ;
std : : string strOutpoint = mnpair . first . ToStringShort ( ) ;
2015-03-31 03:14:44 +02:00
if ( strMode = = " activeseconds " ) {
2016-09-16 17:22:57 +02:00
if ( strFilter ! = " " & & strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
obj . push_back ( Pair ( strOutpoint , ( int64_t ) ( mn . lastPing . sigTime - mn . sigTime ) ) ) ;
2015-07-18 19:31:28 +02:00
} else if ( strMode = = " addr " ) {
2016-09-16 17:22:57 +02:00
std : : string strAddress = mn . addr . ToString ( ) ;
if ( strFilter ! = " " & & strAddress . find ( strFilter ) = = std : : string : : npos & &
strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
obj . push_back ( Pair ( strOutpoint , strAddress ) ) ;
2018-03-08 13:22:13 +01:00
} else if ( strMode = = " daemon " ) {
2018-07-25 17:09:48 +02:00
std : : string strDaemon = mn . lastPing . GetDaemonString ( ) ;
2018-03-08 13:22:13 +01:00
if ( strFilter ! = " " & & strDaemon . find ( strFilter ) = = std : : string : : npos & &
strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
obj . push_back ( Pair ( strOutpoint , strDaemon ) ) ;
} else if ( strMode = = " sentinel " ) {
2018-07-25 17:09:48 +02:00
std : : string strSentinel = mn . lastPing . GetSentinelString ( ) ;
2018-03-08 13:22:13 +01:00
if ( strFilter ! = " " & & strSentinel . find ( strFilter ) = = std : : string : : npos & &
strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
obj . push_back ( Pair ( strOutpoint , strSentinel ) ) ;
2015-03-14 19:34:51 +01:00
} else if ( strMode = = " full " ) {
2016-09-16 17:22:57 +02:00
std : : ostringstream streamFull ;
2017-01-25 12:37:45 +01:00
streamFull < < std : : setw ( 18 ) < <
2016-09-16 00:00:06 +02:00
mn . GetStatus ( ) < < " " < <
mn . nProtocolVersion < < " " < <
2018-08-11 21:55:56 +02:00
CBitcoinAddress ( mn . keyIDCollateralAddress ) . ToString ( ) < < " " < <
2016-09-16 17:22:57 +02:00
( int64_t ) mn . lastPing . sigTime < < " " < < std : : setw ( 8 ) < <
( int64_t ) ( mn . lastPing . sigTime - mn . sigTime ) < < " " < < std : : setw ( 10 ) < <
mn . GetLastPaidTime ( ) < < " " < < std : : setw ( 6 ) < <
mn . GetLastPaidBlock ( ) < < " " < <
mn . addr . ToString ( ) ;
std : : string strFull = streamFull . str ( ) ;
if ( strFilter ! = " " & & strFull . find ( strFilter ) = = std : : string : : npos & &
strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
obj . push_back ( Pair ( strOutpoint , strFull ) ) ;
2017-07-10 16:41:42 +02:00
} else if ( strMode = = " info " ) {
std : : ostringstream streamInfo ;
streamInfo < < std : : setw ( 18 ) < <
mn . GetStatus ( ) < < " " < <
mn . nProtocolVersion < < " " < <
2018-08-11 21:55:56 +02:00
CBitcoinAddress ( mn . keyIDCollateralAddress ) . ToString ( ) < < " " < <
2017-07-10 16:41:42 +02:00
( int64_t ) mn . lastPing . sigTime < < " " < < std : : setw ( 8 ) < <
( int64_t ) ( mn . lastPing . sigTime - mn . sigTime ) < < " " < <
2018-07-25 17:09:48 +02:00
mn . lastPing . GetSentinelString ( ) < < " " < <
2017-07-10 16:41:42 +02:00
( mn . lastPing . fSentinelIsCurrent ? " current " : " expired " ) < < " " < <
mn . addr . ToString ( ) ;
std : : string strInfo = streamInfo . str ( ) ;
if ( strFilter ! = " " & & strInfo . find ( strFilter ) = = std : : string : : npos & &
strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
obj . push_back ( Pair ( strOutpoint , strInfo ) ) ;
2018-03-08 13:22:13 +01:00
} else if ( strMode = = " json " ) {
std : : ostringstream streamInfo ;
streamInfo < < mn . addr . ToString ( ) < < " " < <
CBitcoinAddress ( mn . pubKeyCollateralAddress . GetID ( ) ) . ToString ( ) < < " " < <
mn . GetStatus ( ) < < " " < <
mn . nProtocolVersion < < " " < <
mn . lastPing . nDaemonVersion < < " " < <
2018-07-25 17:09:48 +02:00
mn . lastPing . GetSentinelString ( ) < < " " < <
2018-03-08 13:22:13 +01:00
( mn . lastPing . fSentinelIsCurrent ? " current " : " expired " ) < < " " < <
( int64_t ) mn . lastPing . sigTime < < " " < <
( int64_t ) ( mn . lastPing . sigTime - mn . sigTime ) < < " " < <
mn . GetLastPaidTime ( ) < < " " < <
mn . GetLastPaidBlock ( ) ;
std : : string strInfo = streamInfo . str ( ) ;
if ( strFilter ! = " " & & strInfo . find ( strFilter ) = = std : : string : : npos & &
strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
UniValue objMN ( UniValue : : VOBJ ) ;
objMN . push_back ( Pair ( " address " , mn . addr . ToString ( ) ) ) ;
objMN . push_back ( Pair ( " payee " , CBitcoinAddress ( mn . pubKeyCollateralAddress . GetID ( ) ) . ToString ( ) ) ) ;
objMN . push_back ( Pair ( " status " , mn . GetStatus ( ) ) ) ;
objMN . push_back ( Pair ( " protocol " , mn . nProtocolVersion ) ) ;
2018-07-25 17:09:48 +02:00
objMN . push_back ( Pair ( " daemonversion " , mn . lastPing . GetDaemonString ( ) ) ) ;
objMN . push_back ( Pair ( " sentinelversion " , mn . lastPing . GetSentinelString ( ) ) ) ;
2018-03-08 13:22:13 +01:00
objMN . push_back ( Pair ( " sentinelstate " , ( mn . lastPing . fSentinelIsCurrent ? " current " : " expired " ) ) ) ;
objMN . push_back ( Pair ( " lastseen " , ( int64_t ) mn . lastPing . sigTime ) ) ;
objMN . push_back ( Pair ( " activeseconds " , ( int64_t ) ( mn . lastPing . sigTime - mn . sigTime ) ) ) ;
objMN . push_back ( Pair ( " lastpaidtime " , mn . GetLastPaidTime ( ) ) ) ;
objMN . push_back ( Pair ( " lastpaidblock " , mn . GetLastPaidBlock ( ) ) ) ;
obj . push_back ( Pair ( strOutpoint , objMN ) ) ;
2016-09-11 22:22:37 +02:00
} else if ( strMode = = " lastpaidblock " ) {
2016-09-16 17:22:57 +02:00
if ( strFilter ! = " " & & strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
obj . push_back ( Pair ( strOutpoint , mn . GetLastPaidBlock ( ) ) ) ;
2016-09-11 22:22:37 +02:00
} else if ( strMode = = " lastpaidtime " ) {
2016-09-16 17:22:57 +02:00
if ( strFilter ! = " " & & strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
obj . push_back ( Pair ( strOutpoint , mn . GetLastPaidTime ( ) ) ) ;
} else if ( strMode = = " lastseen " ) {
if ( strFilter ! = " " & & strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
obj . push_back ( Pair ( strOutpoint , ( int64_t ) mn . lastPing . sigTime ) ) ;
} else if ( strMode = = " payee " ) {
2018-08-11 21:55:56 +02:00
CBitcoinAddress address ( mn . keyIDCollateralAddress ) ;
2016-09-16 17:22:57 +02:00
std : : string strPayee = address . ToString ( ) ;
if ( strFilter ! = " " & & strPayee . find ( strFilter ) = = std : : string : : npos & &
strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
obj . push_back ( Pair ( strOutpoint , strPayee ) ) ;
} else if ( strMode = = " protocol " ) {
if ( strFilter ! = " " & & strFilter ! = strprintf ( " %d " , mn . nProtocolVersion ) & &
strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
2018-04-20 12:53:23 +02:00
obj . push_back ( Pair ( strOutpoint , mn . nProtocolVersion ) ) ;
2018-08-31 15:31:59 +02:00
} else if ( strMode = = " keyIDOwner " ) {
2017-07-22 22:33:42 +02:00
if ( strFilter ! = " " & & strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
2018-08-31 15:31:59 +02:00
obj . push_back ( Pair ( strOutpoint , HexStr ( mn . keyIDOwner ) ) ) ;
} else if ( strMode = = " keyIDOperator " ) {
if ( strFilter ! = " " & & strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
2018-10-21 21:45:16 +02:00
obj . push_back ( Pair ( strOutpoint , HexStr ( mn . legacyKeyIDOperator ) ) ) ;
2018-08-31 15:31:59 +02:00
} else if ( strMode = = " keyIDVoting " ) {
if ( strFilter ! = " " & & strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
obj . push_back ( Pair ( strOutpoint , HexStr ( mn . keyIDVoting ) ) ) ;
2016-09-16 17:22:57 +02:00
} else if ( strMode = = " status " ) {
2016-09-16 00:00:06 +02:00
std : : string strStatus = mn . GetStatus ( ) ;
2016-09-16 17:22:57 +02:00
if ( strFilter ! = " " & & strStatus . find ( strFilter ) = = std : : string : : npos & &
strOutpoint . find ( strFilter ) = = std : : string : : npos ) continue ;
obj . push_back ( Pair ( strOutpoint , strStatus ) ) ;
2015-03-14 19:34:51 +01:00
}
2015-02-24 00:48:11 +01:00
}
}
return obj ;
2016-03-16 16:30:22 +01:00
}
2016-03-17 18:39:17 +01:00
bool DecodeHexVecMnb ( std : : vector < CMasternodeBroadcast > & vecMnb , std : : string strHexMnb ) {
2016-03-16 16:30:22 +01:00
if ( ! IsHex ( strHexMnb ) )
return false ;
2016-09-16 17:22:57 +02:00
std : : vector < unsigned char > mnbData ( ParseHex ( strHexMnb ) ) ;
2016-03-16 16:30:22 +01:00
CDataStream ssData ( mnbData , SER_NETWORK , PROTOCOL_VERSION ) ;
try {
2016-03-17 18:39:17 +01:00
ssData > > vecMnb ;
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
} catch ( const std : : exception & ) {
2016-03-16 16:30:22 +01:00
return false ;
}
return true ;
}
2016-10-19 15:01:33 +02:00
UniValue masternodebroadcast ( const JSONRPCRequest & request )
2016-03-16 16:30:22 +01:00
{
2016-09-16 17:22:57 +02:00
std : : string strCommand ;
2016-10-19 15:01:33 +02:00
if ( request . params . size ( ) > = 1 )
strCommand = request . params [ 0 ] . get_str ( ) ;
2016-03-16 16:30:22 +01:00
2016-10-19 15:01:33 +02:00
if ( request . fHelp | |
2017-12-01 19:53:34 +01:00
(
# ifdef ENABLE_WALLET
strCommand ! = " create-alias " & & strCommand ! = " create-all " & &
# endif // ENABLE_WALLET
strCommand ! = " decode " & & strCommand ! = " relay " ) )
2016-09-16 17:22:57 +02:00
throw std : : runtime_error (
2017-02-10 01:51:47 +01:00
" masternodebroadcast \" command \" ... \n "
2016-03-16 16:30:22 +01:00
" Set of commands to create and relay masternode broadcast messages \n "
" \n Arguments: \n "
" 1. \" command \" (string or set of strings, required) The command to execute \n "
" \n Available commands: \n "
2017-12-01 19:53:34 +01:00
# ifdef ENABLE_WALLET
2016-03-16 16:30:22 +01:00
" create-alias - Create single remote masternode broadcast message by assigned alias configured in masternode.conf \n "
" create-all - Create remote masternode broadcast messages for all masternodes configured in masternode.conf \n "
2017-12-01 19:53:34 +01:00
# endif // ENABLE_WALLET
2016-03-16 16:30:22 +01:00
" decode - Decode masternode broadcast message \n "
" relay - Relay masternode broadcast message to the network \n "
2017-02-10 01:51:47 +01:00
) ;
2016-03-16 16:30:22 +01:00
2017-12-01 19:53:34 +01:00
# ifdef ENABLE_WALLET
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 ( strCommand = = " create-alias " ) {
2018-03-01 14:18:46 +01:00
if ( ! EnsureWalletIsAvailable ( request . fHelp ) )
return NullUniValue ;
2016-03-16 16:30:22 +01:00
// wait for reindex and/or import to finish
if ( fImporting | | fReindex )
throw JSONRPCError ( RPC_INTERNAL_ERROR , " Wait for reindex and/or import to finish " ) ;
2016-10-19 15:01:33 +02:00
if ( request . params . size ( ) < 2 )
2016-09-16 17:22:57 +02:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Please specify an alias " ) ;
2016-03-16 16:30:22 +01:00
2016-10-24 01:14:54 +02:00
{
LOCK ( pwalletMain - > cs_wallet ) ;
EnsureWalletIsUnlocked ( ) ;
}
2016-03-16 16:30:22 +01:00
2016-09-16 17:22:57 +02:00
bool fFound = false ;
2016-10-19 15:01:33 +02:00
std : : string strAlias = request . params [ 1 ] . get_str ( ) ;
2016-03-16 16:30:22 +01:00
UniValue statusObj ( UniValue : : VOBJ ) ;
2016-03-17 18:39:17 +01:00
std : : vector < CMasternodeBroadcast > vecMnb ;
2016-09-16 17:22:57 +02:00
statusObj . push_back ( Pair ( " alias " , strAlias ) ) ;
2016-03-16 16:30:22 +01:00
2018-02-06 12:09:33 +01:00
for ( const auto & mne : masternodeConfig . getEntries ( ) ) {
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 ( mne . getAlias ( ) = = strAlias ) {
2016-09-16 17:22:57 +02:00
fFound = true ;
std : : string strError ;
2016-03-16 16:30:22 +01:00
CMasternodeBroadcast mnb ;
2016-09-16 17:22:57 +02:00
bool fResult = CMasternodeBroadcast : : Create ( mne . getIp ( ) , mne . getPrivKey ( ) , mne . getTxHash ( ) , mne . getOutputIndex ( ) , strError , mnb , true ) ;
2016-03-16 16:30:22 +01:00
2016-09-16 17:22:57 +02:00
statusObj . push_back ( Pair ( " result " , fResult ? " successful " : " failed " ) ) ;
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 ( fResult ) {
2016-03-17 18:39:17 +01:00
vecMnb . push_back ( mnb ) ;
CDataStream ssVecMnb ( SER_NETWORK , PROTOCOL_VERSION ) ;
ssVecMnb < < vecMnb ;
2018-03-01 14:18:46 +01:00
statusObj . push_back ( Pair ( " hex " , HexStr ( ssVecMnb ) ) ) ;
2016-03-16 16:30:22 +01:00
} else {
2016-09-16 17:22:57 +02:00
statusObj . push_back ( Pair ( " errorMessage " , strError ) ) ;
2016-03-16 16:30:22 +01:00
}
break ;
}
}
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 ( ! fFound ) {
2016-03-17 18:39:17 +01:00
statusObj . push_back ( Pair ( " result " , " not found " ) ) ;
2016-03-16 16:30:22 +01:00
statusObj . push_back ( Pair ( " errorMessage " , " Could not find alias in config. Verify with list-conf. " ) ) ;
}
return statusObj ;
}
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 ( strCommand = = " create-all " ) {
2018-03-01 14:18:46 +01:00
if ( ! EnsureWalletIsAvailable ( request . fHelp ) )
return NullUniValue ;
2016-03-16 16:30:22 +01:00
// wait for reindex and/or import to finish
if ( fImporting | | fReindex )
throw JSONRPCError ( RPC_INTERNAL_ERROR , " Wait for reindex and/or import to finish " ) ;
2016-10-24 01:14:54 +02:00
{
LOCK ( pwalletMain - > cs_wallet ) ;
EnsureWalletIsUnlocked ( ) ;
}
2016-03-16 16:30:22 +01:00
2016-09-16 17:22:57 +02:00
int nSuccessful = 0 ;
int nFailed = 0 ;
2016-03-16 16:30:22 +01:00
UniValue resultsObj ( UniValue : : VOBJ ) ;
2016-03-17 18:39:17 +01:00
std : : vector < CMasternodeBroadcast > vecMnb ;
2016-03-16 16:30:22 +01:00
2018-02-06 12:09:33 +01:00
for ( const auto & mne : masternodeConfig . getEntries ( ) ) {
2016-09-16 17:22:57 +02:00
std : : string strError ;
2016-03-16 16:30:22 +01:00
CMasternodeBroadcast mnb ;
2016-09-16 17:22:57 +02:00
bool fResult = CMasternodeBroadcast : : Create ( mne . getIp ( ) , mne . getPrivKey ( ) , mne . getTxHash ( ) , mne . getOutputIndex ( ) , strError , mnb , true ) ;
2016-03-16 16:30:22 +01:00
UniValue statusObj ( UniValue : : VOBJ ) ;
statusObj . push_back ( Pair ( " alias " , mne . getAlias ( ) ) ) ;
2016-09-16 17:22:57 +02:00
statusObj . push_back ( Pair ( " result " , fResult ? " successful " : " failed " ) ) ;
2016-03-16 16:30:22 +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 ( fResult ) {
2016-09-16 17:22:57 +02:00
nSuccessful + + ;
2016-03-17 18:39:17 +01:00
vecMnb . push_back ( mnb ) ;
2016-03-16 16:30:22 +01:00
} else {
2016-09-16 17:22:57 +02:00
nFailed + + ;
statusObj . push_back ( Pair ( " errorMessage " , strError ) ) ;
2016-03-16 16:30:22 +01:00
}
resultsObj . push_back ( Pair ( " status " , statusObj ) ) ;
}
2016-03-17 18:39:17 +01:00
CDataStream ssVecMnb ( SER_NETWORK , PROTOCOL_VERSION ) ;
ssVecMnb < < vecMnb ;
2016-03-16 16:30:22 +01:00
UniValue returnObj ( UniValue : : VOBJ ) ;
2016-09-16 17:22:57 +02:00
returnObj . push_back ( Pair ( " overall " , strprintf ( " Successfully created broadcast messages for %d masternodes, failed to create %d, total %d " , nSuccessful , nFailed , nSuccessful + nFailed ) ) ) ;
2016-03-16 16:30:22 +01:00
returnObj . push_back ( Pair ( " detail " , resultsObj ) ) ;
2016-03-17 18:39:17 +01:00
returnObj . push_back ( Pair ( " hex " , HexStr ( ssVecMnb . begin ( ) , ssVecMnb . end ( ) ) ) ) ;
2016-03-16 16:30:22 +01:00
return returnObj ;
}
2017-12-01 19:53:34 +01:00
# endif // ENABLE_WALLET
2016-03-16 16:30:22 +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 ( strCommand = = " decode " ) {
2016-10-19 15:01:33 +02:00
if ( request . params . size ( ) ! = 2 )
2016-03-16 16:30:22 +01:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Correct usage is 'masternodebroadcast decode \" hexstring \" ' " ) ;
2016-03-17 18:39:17 +01:00
std : : vector < CMasternodeBroadcast > vecMnb ;
2016-03-16 16:30:22 +01:00
2016-10-19 15:01:33 +02:00
if ( ! DecodeHexVecMnb ( vecMnb , request . params [ 1 ] . get_str ( ) ) )
2016-03-16 16:30:22 +01:00
throw JSONRPCError ( RPC_DESERIALIZATION_ERROR , " Masternode broadcast message decode failed " ) ;
2016-09-16 17:22:57 +02:00
int nSuccessful = 0 ;
int nFailed = 0 ;
int nDos = 0 ;
UniValue returnObj ( UniValue : : VOBJ ) ;
2018-02-06 12:09:33 +01:00
for ( const auto & mnb : vecMnb ) {
2016-03-17 18:39:17 +01:00
UniValue resultObj ( UniValue : : VOBJ ) ;
2016-03-16 16:30:22 +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 ( mnb . CheckSignature ( nDos ) ) {
2016-09-16 17:22:57 +02:00
nSuccessful + + ;
2018-02-15 08:29:44 +01:00
resultObj . push_back ( Pair ( " outpoint " , mnb . outpoint . ToStringShort ( ) ) ) ;
2016-03-17 18:39:17 +01:00
resultObj . push_back ( Pair ( " addr " , mnb . addr . ToString ( ) ) ) ;
2018-08-11 21:55:56 +02:00
resultObj . push_back ( Pair ( " keyIDCollateralAddress " , CBitcoinAddress ( mnb . keyIDCollateralAddress ) . ToString ( ) ) ) ;
2018-10-21 21:45:16 +02:00
resultObj . push_back ( Pair ( " keyIDMasternode " , CBitcoinAddress ( mnb . legacyKeyIDOperator ) . ToString ( ) ) ) ;
2016-03-17 18:39:17 +01:00
resultObj . push_back ( Pair ( " vchSig " , EncodeBase64 ( & mnb . vchSig [ 0 ] , mnb . vchSig . size ( ) ) ) ) ;
resultObj . push_back ( Pair ( " sigTime " , mnb . sigTime ) ) ;
2016-09-16 00:00:06 +02:00
resultObj . push_back ( Pair ( " protocolVersion " , mnb . nProtocolVersion ) ) ;
2016-03-17 18:39:17 +01:00
resultObj . push_back ( Pair ( " nLastDsq " , mnb . nLastDsq ) ) ;
UniValue lastPingObj ( UniValue : : VOBJ ) ;
2018-02-15 08:29:44 +01:00
lastPingObj . push_back ( Pair ( " outpoint " , mnb . lastPing . masternodeOutpoint . ToStringShort ( ) ) ) ;
2016-03-17 18:39:17 +01:00
lastPingObj . push_back ( Pair ( " blockHash " , mnb . lastPing . blockHash . ToString ( ) ) ) ;
lastPingObj . push_back ( Pair ( " sigTime " , mnb . lastPing . sigTime ) ) ;
lastPingObj . push_back ( Pair ( " vchSig " , EncodeBase64 ( & mnb . lastPing . vchSig [ 0 ] , mnb . lastPing . vchSig . size ( ) ) ) ) ;
resultObj . push_back ( Pair ( " lastPing " , lastPingObj ) ) ;
} else {
2016-09-16 17:22:57 +02:00
nFailed + + ;
2016-03-17 18:39:17 +01:00
resultObj . push_back ( Pair ( " errorMessage " , " Masternode broadcast signature verification failed " ) ) ;
}
2016-03-16 16:30:22 +01:00
2016-03-17 18:39:17 +01:00
returnObj . push_back ( Pair ( mnb . GetHash ( ) . ToString ( ) , resultObj ) ) ;
}
2016-03-16 16:30:22 +01:00
2016-09-16 17:22:57 +02:00
returnObj . push_back ( Pair ( " overall " , strprintf ( " Successfully decoded broadcast messages for %d masternodes, failed to decode %d, total %d " , nSuccessful , nFailed , nSuccessful + nFailed ) ) ) ;
2016-03-16 16:30:22 +01:00
2016-03-17 18:39:17 +01:00
return returnObj ;
2016-03-16 16:30:22 +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 ( strCommand = = " relay " ) {
2016-10-19 15:01:33 +02:00
if ( request . params . size ( ) < 2 | | request . params . size ( ) > 3 )
2018-02-21 17:32:51 +01:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " masternodebroadcast relay \" hexstring \" \n "
2016-03-18 00:37:48 +01:00
" \n Arguments: \n "
2018-02-21 17:32:51 +01:00
" 1. \" hex \" (string, required) Broadcast messages hex string \n " ) ;
2016-03-16 16:30:22 +01:00
2016-03-17 18:39:17 +01:00
std : : vector < CMasternodeBroadcast > vecMnb ;
2016-03-16 16:30:22 +01:00
2016-10-19 15:01:33 +02:00
if ( ! DecodeHexVecMnb ( vecMnb , request . params [ 1 ] . get_str ( ) ) )
2016-03-16 16:30:22 +01:00
throw JSONRPCError ( RPC_DESERIALIZATION_ERROR , " Masternode broadcast message decode failed " ) ;
2016-09-16 17:22:57 +02:00
int nSuccessful = 0 ;
int nFailed = 0 ;
UniValue returnObj ( UniValue : : VOBJ ) ;
2016-03-17 18:39:17 +01:00
// verify all signatures first, bailout if any of them broken
2018-02-06 12:09:33 +01:00
for ( const auto & mnb : vecMnb ) {
2016-03-17 18:39:17 +01:00
UniValue resultObj ( UniValue : : VOBJ ) ;
2016-03-16 16:30:22 +01:00
2018-02-15 08:29:44 +01:00
resultObj . push_back ( Pair ( " outpoint " , mnb . outpoint . ToStringShort ( ) ) ) ;
2016-03-17 18:39:17 +01:00
resultObj . push_back ( Pair ( " addr " , mnb . addr . ToString ( ) ) ) ;
2016-03-16 16:30:22 +01:00
2016-03-18 00:37:48 +01:00
int nDos = 0 ;
bool fResult ;
2016-09-16 00:00:06 +02:00
if ( mnb . CheckSignature ( nDos ) ) {
2018-02-21 17:32:51 +01:00
fResult = mnodeman . CheckMnbAndUpdateMasternodeList ( NULL , mnb , nDos , * g_connman ) ;
2017-09-19 16:51:38 +02:00
mnodeman . NotifyMasternodeUpdates ( * g_connman ) ;
2016-03-18 00:37:48 +01:00
} else fResult = false ;
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 ( fResult ) {
2016-09-16 17:22:57 +02:00
nSuccessful + + ;
2016-03-17 18:39:17 +01:00
resultObj . push_back ( Pair ( mnb . GetHash ( ) . ToString ( ) , " successful " ) ) ;
} else {
2016-09-16 17:22:57 +02:00
nFailed + + ;
2016-03-17 18:39:17 +01:00
resultObj . push_back ( Pair ( " errorMessage " , " Masternode broadcast signature verification failed " ) ) ;
}
returnObj . push_back ( Pair ( mnb . GetHash ( ) . ToString ( ) , resultObj ) ) ;
}
2016-09-16 17:22:57 +02:00
returnObj . push_back ( Pair ( " overall " , strprintf ( " Successfully relayed broadcast messages for %d masternodes, failed to relay %d, total %d " , nSuccessful , nFailed , nSuccessful + nFailed ) ) ) ;
2016-03-17 18:39:17 +01:00
return returnObj ;
2016-03-16 16:30:22 +01:00
}
return NullUniValue ;
2015-02-23 21:26:23 +01:00
}
2017-07-04 19:31:57 +02:00
2016-10-19 15:01:33 +02:00
UniValue sentinelping ( const JSONRPCRequest & request )
2017-07-04 19:31:57 +02:00
{
2016-10-19 15:01:33 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 1 ) {
2017-07-04 19:31:57 +02:00
throw std : : runtime_error (
" sentinelping version \n "
" \n Sentinel ping. \n "
" \n Arguments: \n "
" 1. version (string, required) Sentinel version in the form \" x.x.x \" \n "
" \n Result: \n "
" state (boolean) Ping result \n "
" \n Examples: \n "
+ HelpExampleCli ( " sentinelping " , " 1.0.2 " )
+ HelpExampleRpc ( " sentinelping " , " 1.0.2 " )
) ;
}
2018-08-11 21:55:56 +02:00
legacyActiveMasternodeManager . UpdateSentinelPing ( StringVersionToInt ( request . params [ 0 ] . get_str ( ) ) ) ;
2017-07-04 19:31:57 +02:00
return true ;
}
2016-03-31 10:55:06 +02:00
static const CRPCCommand commands [ ] =
2017-01-10 13:52:49 +01:00
{ // category name actor (function) okSafe argNames
// --------------------- ------------------------ ----------------------- ------ ----------
{ " dash " , " masternode " , & masternode , true , { } } ,
{ " dash " , " masternodelist " , & masternodelist , true , { } } ,
{ " dash " , " masternodebroadcast " , & masternodebroadcast , true , { } } ,
{ " dash " , " getpoolinfo " , & getpoolinfo , true , { } } ,
{ " dash " , " sentinelping " , & sentinelping , true , { } } ,
2017-12-20 08:39:44 +01:00
# ifdef ENABLE_WALLET
2017-01-10 13:52:49 +01:00
{ " dash " , " privatesend " , & privatesend , false , { } } ,
2017-12-20 08:39:44 +01:00
# endif // ENABLE_WALLET
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
}