2014-12-09 02:17:57 +01:00
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
# include "main.h"
# include "db.h"
# include "init.h"
# include "activemasternode.h"
2015-02-23 21:01:21 +01:00
# include "masternodeman.h"
2015-04-16 21:58:09 +02:00
# include "masternode-payments.h"
2015-04-22 16:33:44 +02:00
# include "masternode-budget.h"
2014-12-06 20:41:53 +01:00
# include "masternodeconfig.h"
2014-12-09 02:17:57 +01:00
# include "rpcserver.h"
2015-04-03 00:51:08 +02:00
# include "utilmoneystr.h"
2014-12-09 02:17:57 +01:00
# include <fstream>
using namespace json_spirit ;
2015-04-03 00:51:08 +02:00
void SendMoney ( const CTxDestination & address , CAmount nValue , CWalletTx & wtxNew , AvailableCoinsType coin_type = ALL_COINS )
{
// Check amount
if ( nValue < = 0 )
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Invalid amount " ) ;
if ( nValue > pwalletMain - > GetBalance ( ) )
throw JSONRPCError ( RPC_WALLET_INSUFFICIENT_FUNDS , " Insufficient funds " ) ;
string strError ;
if ( pwalletMain - > IsLocked ( ) )
{
strError = " Error: Wallet locked, unable to create transaction! " ;
LogPrintf ( " SendMoney() : %s " , strError ) ;
throw JSONRPCError ( RPC_WALLET_ERROR , strError ) ;
}
// Parse Dash address
CScript scriptPubKey = GetScriptForDestination ( address ) ;
// Create and send the transaction
CReserveKey reservekey ( pwalletMain ) ;
CAmount nFeeRequired ;
if ( ! pwalletMain - > CreateTransaction ( scriptPubKey , nValue , wtxNew , reservekey , nFeeRequired , strError , NULL , coin_type ) )
{
if ( nValue + nFeeRequired > pwalletMain - > GetBalance ( ) )
strError = strprintf ( " Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds! " , FormatMoney ( nFeeRequired ) ) ;
LogPrintf ( " SendMoney() : %s \n " , strError ) ;
throw JSONRPCError ( RPC_WALLET_ERROR , strError ) ;
}
if ( ! pwalletMain - > CommitTransaction ( wtxNew , reservekey ) )
throw JSONRPCError ( RPC_WALLET_ERROR , " Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here. " ) ;
}
2014-12-09 02:17:57 +01:00
Value darksend ( const Array & params , bool fHelp )
{
if ( fHelp | | params . size ( ) = = 0 )
throw runtime_error (
2015-03-19 15:15:08 +01:00
" darksend <dashaddress> <amount> \n "
" dashaddress, reset, or auto (AutoDenominate) "
2015-08-03 21:53:00 +02:00
" <amount> is a real and will be rounded to the next 0.1 "
2014-12-09 02:17:57 +01:00
+ HelpRequiringPassphrase ( ) ) ;
if ( pwalletMain - > IsLocked ( ) )
throw JSONRPCError ( RPC_WALLET_UNLOCK_NEEDED , " Error: Please enter the wallet passphrase with walletpassphrase first. " ) ;
if ( params [ 0 ] . get_str ( ) = = " auto " ) {
2014-12-30 01:09:34 +01:00
if ( fMasterNode )
return " DarkSend is not supported from masternodes " ;
2015-08-03 21:53:00 +02:00
return " DoAutomaticDenominating " + ( darkSendPool . DoAutomaticDenominating ( ) ? " successful " : ( " failed: " + darkSendPool . GetStatus ( ) ) ) ;
2014-12-09 02:17:57 +01:00
}
if ( params [ 0 ] . get_str ( ) = = " reset " ) {
2015-07-26 00:43:40 +02:00
darkSendPool . Reset ( ) ;
2014-12-09 02:17:57 +01:00
return " successfully reset darksend " ;
}
if ( params . size ( ) ! = 2 )
throw runtime_error (
2015-03-19 15:15:08 +01:00
" darksend <dashaddress> <amount> \n "
" dashaddress, denominate, or auto (AutoDenominate) "
2015-08-03 21:53:00 +02:00
" <amount> is a real and will be rounded to the next 0.1 "
2014-12-09 02:17:57 +01:00
+ HelpRequiringPassphrase ( ) ) ;
CBitcoinAddress address ( params [ 0 ] . get_str ( ) ) ;
if ( ! address . IsValid ( ) )
2015-03-29 04:25:32 +02:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Invalid Dash address " ) ;
2014-12-09 02:17:57 +01:00
// Amount
2015-04-03 00:51:08 +02:00
CAmount nAmount = AmountFromValue ( params [ 1 ] ) ;
2014-12-09 02:17:57 +01:00
// Wallet comments
CWalletTx wtx ;
2015-04-03 00:51:08 +02:00
// string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx, ONLY_DENOMINATED);
SendMoney ( address . Get ( ) , nAmount , wtx , ONLY_DENOMINATED ) ;
// if (strError != "")
// throw JSONRPCError(RPC_WALLET_ERROR, strError);
2014-12-09 02:17:57 +01:00
return wtx . GetHash ( ) . GetHex ( ) ;
}
Value getpoolinfo ( const Array & params , bool fHelp )
{
if ( fHelp | | params . size ( ) ! = 0 )
throw runtime_error (
" getpoolinfo \n "
" Returns an object containing anonymous pool-related information. " ) ;
Object obj ;
2015-02-23 21:01:21 +01:00
obj . push_back ( Pair ( " current_masternode " , mnodeman . GetCurrentMasterNode ( ) - > addr . ToString ( ) ) ) ;
2014-12-09 02:17:57 +01:00
obj . push_back ( Pair ( " state " , darkSendPool . GetState ( ) ) ) ;
obj . push_back ( Pair ( " entries " , darkSendPool . GetEntriesCount ( ) ) ) ;
obj . push_back ( Pair ( " entries_accepted " , darkSendPool . GetCountEntriesAccepted ( ) ) ) ;
return obj ;
}
2014-12-06 20:41:53 +01:00
2014-12-09 02:17:57 +01:00
Value masternode ( const Array & params , bool fHelp )
{
string strCommand ;
if ( params . size ( ) > = 1 )
strCommand = params [ 0 ] . get_str ( ) ;
if ( fHelp | |
2015-04-22 16:33:44 +02:00
( strCommand ! = " start " & & strCommand ! = " start-alias " & & strCommand ! = " start-many " & & strCommand ! = " stop " & & strCommand ! = " stop-alias " & &
strCommand ! = " stop-many " & & strCommand ! = " list " & & strCommand ! = " list-conf " & & strCommand ! = " count " & & strCommand ! = " enforce " & &
2015-06-24 01:44:31 +02:00
strCommand ! = " debug " & & strCommand ! = " current " & & strCommand ! = " winners " & & strCommand ! = " genkey " & & strCommand ! = " connect " & &
2015-07-24 17:21:02 +02:00
strCommand ! = " outputs " & & strCommand ! = " status " & & strCommand ! = " calcscore " ) )
2014-12-09 02:17:57 +01:00
throw runtime_error (
2015-02-26 02:35:33 +01:00
" masternode \" command \" ... ( \" passphrase \" ) \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 "
" 2. \" passphrase \" (string, optional) The wallet passphrase \n "
" \n Available commands: \n "
2015-07-19 01:20:48 +02:00
" count - Print number of all known masternodes (optional: 'ds', 'enabled', 'all') \n "
2015-02-26 02:35:33 +01:00
" current - Print info on current masternode winner \n "
" debug - Print masternode status \n "
" genkey - Generate new masternodeprivkey \n "
" enforce - Enforce masternode payments \n "
" outputs - Print masternode compatible outputs \n "
2015-03-19 15:15:08 +01:00
" start - Start masternode configured in dash.conf \n "
2015-02-26 02:35:33 +01:00
" start-alias - Start single masternode by assigned alias configured in masternode.conf \n "
" start-many - Start all masternodes configured in masternode.conf \n "
2015-07-18 21:17:17 +02:00
" status - Print masternode status information \n "
2015-02-26 02:35:33 +01:00
" list - Print list of all known masternodes (see masternodelist for more info) \n "
" list-conf - Print masternode.conf in JSON format \n "
" winners - Print list of masternode winners \n "
) ;
2014-12-09 02:17:57 +01:00
if ( strCommand = = " list " )
{
2015-02-23 21:26:23 +01:00
Array newParams ( params . size ( ) - 1 ) ;
std : : copy ( params . begin ( ) + 1 , params . end ( ) , newParams . begin ( ) ) ;
return masternodelist ( newParams , fHelp ) ;
}
2014-12-09 02:17:57 +01:00
2015-04-22 16:33:44 +02:00
if ( strCommand = = " budget " )
{
return " Show budgets " ;
}
2015-07-18 21:17:17 +02:00
if ( strCommand = = " connect " )
{
std : : string strAddress = " " ;
if ( params . size ( ) = = 2 ) {
strAddress = params [ 1 ] . get_str ( ) ;
} else {
throw runtime_error (
" Masternode address required \n " ) ;
}
CService addr = CService ( strAddress ) ;
if ( ConnectNode ( ( CAddress ) addr , NULL , true ) ) {
return " successfully connected " ;
} else {
return " error connecting " ;
}
}
2015-02-23 21:26:23 +01:00
if ( strCommand = = " count " )
{
if ( params . size ( ) > 2 ) {
2014-12-09 02:17:57 +01:00
throw runtime_error (
2015-02-23 21:26:23 +01:00
" too many parameters \n " ) ;
2014-12-09 02:17:57 +01:00
}
2015-02-26 02:35:33 +01:00
if ( params . size ( ) = = 2 )
{
2015-07-19 01:20:48 +02:00
if ( params [ 1 ] = = " ds " ) return mnodeman . CountEnabled ( MIN_POOL_PEER_PROTO_VERSION ) ;
2015-02-26 02:35:33 +01:00
if ( params [ 1 ] = = " enabled " ) return mnodeman . CountEnabled ( ) ;
2015-07-25 10:18:22 +02:00
if ( params [ 1 ] = = " all " ) return strprintf ( " Total: %d (DS Compatible: %d / Enabled: %d) " ,
mnodeman . size ( ) ,
2015-07-19 01:20:48 +02:00
mnodeman . CountEnabled ( MIN_POOL_PEER_PROTO_VERSION ) ,
2015-07-25 10:18:22 +02:00
mnodeman . CountEnabled ( ) ) ;
2015-02-26 02:35:33 +01:00
}
2015-02-23 21:26:23 +01:00
return mnodeman . size ( ) ;
2014-12-09 02:17:57 +01:00
}
2015-07-18 21:17:17 +02:00
if ( strCommand = = " current " )
{
CMasternode * winner = mnodeman . GetCurrentMasterNode ( 1 ) ;
if ( winner ) {
Object obj ;
CScript pubkey ;
pubkey = GetScriptForDestination ( winner - > pubkey . GetID ( ) ) ;
CTxDestination address1 ;
ExtractDestination ( pubkey , address1 ) ;
CBitcoinAddress address2 ( address1 ) ;
obj . push_back ( Pair ( " IP:port " , winner - > addr . ToString ( ) ) ) ;
obj . push_back ( Pair ( " protocol " , ( int64_t ) winner - > protocolVersion ) ) ;
obj . push_back ( Pair ( " vin " , winner - > vin . prevout . hash . ToString ( ) ) ) ;
obj . push_back ( Pair ( " pubkey " , address2 . ToString ( ) ) ) ;
obj . push_back ( Pair ( " lastseen " , ( winner - > lastPing = = CMasternodePing ( ) ) ? winner - > sigTime :
( int64_t ) winner - > lastPing . sigTime ) ) ;
obj . push_back ( Pair ( " activeseconds " , ( winner - > lastPing = = CMasternodePing ( ) ) ? 0 :
( int64_t ) ( winner - > lastPing . sigTime - winner - > sigTime ) ) ) ;
return obj ;
}
return " unknown " ;
}
if ( strCommand = = " debug " )
{
2015-07-23 04:11:39 +02:00
if ( activeMasternode . status ! = ACTIVE_MASTERNODE_INITIAL | | ! masternodeSync . IsSynced ( ) )
return activeMasternode . GetStatus ( ) ;
2015-07-18 21:17:17 +02:00
CTxIn vin = CTxIn ( ) ;
CPubKey pubkey = CScript ( ) ;
CKey key ;
bool found = activeMasternode . GetMasterNodeVin ( vin , pubkey , key ) ;
if ( ! found ) {
return " Missing masternode input, please look at the documentation for instructions on masternode creation " ;
} else {
2015-07-23 04:11:39 +02:00
return activeMasternode . GetStatus ( ) ;
2015-07-18 21:17:17 +02:00
}
}
if ( strCommand = = " enforce " )
{
return ( uint64_t ) enforceMasternodePaymentsTime ;
}
2014-12-09 02:17:57 +01:00
if ( strCommand = = " start " )
{
if ( ! fMasterNode ) return " you must set masternode=1 in the configuration " ;
if ( pwalletMain - > IsLocked ( ) ) {
SecureString strWalletPass ;
strWalletPass . reserve ( 100 ) ;
if ( params . size ( ) = = 2 ) {
strWalletPass = params [ 1 ] . get_str ( ) . c_str ( ) ;
} else {
throw runtime_error (
" Your wallet is locked, passphrase is required \n " ) ;
}
if ( ! pwalletMain - > Unlock ( strWalletPass ) ) {
return " incorrect passphrase " ;
}
}
2015-07-17 12:26:24 +02:00
if ( activeMasternode . status ! = ACTIVE_MASTERNODE_STARTED ) {
activeMasternode . status = ACTIVE_MASTERNODE_INITIAL ; // TODO: consider better way
2015-01-21 22:57:02 +01:00
activeMasternode . ManageStatus ( ) ;
pwalletMain - > Lock ( ) ;
}
2014-12-26 21:00:56 +01:00
2015-07-14 07:25:07 +02:00
return activeMasternode . GetStatus ( ) ;
2014-12-09 02:17:57 +01:00
}
2014-12-06 20:41:53 +01:00
if ( strCommand = = " start-alias " )
2014-12-09 02:17:57 +01:00
{
2015-07-18 03:23:52 +02:00
if ( params . size ( ) < 2 ) {
throw runtime_error (
" command needs at least 2 parameters \n " ) ;
2014-12-09 02:17:57 +01:00
}
2015-07-18 19:31:28 +02:00
std : : string alias = params [ 1 ] . get_str ( ) ;
2015-07-18 03:23:52 +02:00
if ( pwalletMain - > IsLocked ( ) ) {
SecureString strWalletPass ;
strWalletPass . reserve ( 100 ) ;
if ( params . size ( ) = = 3 ) {
strWalletPass = params [ 2 ] . get_str ( ) . c_str ( ) ;
} else {
throw runtime_error (
" Your wallet is locked, passphrase is required \n " ) ;
}
if ( ! pwalletMain - > Unlock ( strWalletPass ) ) {
return " incorrect passphrase " ;
}
}
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
bool found = false ;
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
Object statusObj ;
statusObj . push_back ( Pair ( " alias " , alias ) ) ;
2015-03-21 20:49:21 +01:00
2015-07-18 03:23:52 +02:00
BOOST_FOREACH ( CMasternodeConfig : : CMasternodeEntry mne , masternodeConfig . getEntries ( ) ) {
if ( mne . getAlias ( ) = = alias ) {
found = true ;
std : : string errorMessage ;
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
bool result = activeMasternode . Register ( mne . getIp ( ) , mne . getPrivKey ( ) , mne . getTxHash ( ) , mne . getOutputIndex ( ) , errorMessage ) ;
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
statusObj . push_back ( Pair ( " result " , result ? " successful " : " failed " ) ) ;
if ( ! result ) {
statusObj . push_back ( Pair ( " errorMessage " , errorMessage ) ) ;
}
break ;
}
}
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
if ( ! found ) {
statusObj . push_back ( Pair ( " result " , " failed " ) ) ;
statusObj . push_back ( Pair ( " errorMessage " , " could not find alias in config. Verify with list-conf. " ) ) ;
}
pwalletMain - > Lock ( ) ;
return statusObj ;
2014-12-09 02:17:57 +01:00
}
2014-12-26 21:00:56 +01:00
2014-12-06 20:41:53 +01:00
if ( strCommand = = " start-many " )
2014-12-26 21:00:56 +01:00
{
2015-07-18 03:23:52 +02:00
if ( pwalletMain - > IsLocked ( ) ) {
SecureString strWalletPass ;
strWalletPass . reserve ( 100 ) ;
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
if ( params . size ( ) = = 2 ) {
strWalletPass = params [ 1 ] . get_str ( ) . c_str ( ) ;
} else {
throw runtime_error (
" Your wallet is locked, passphrase is required \n " ) ;
}
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
if ( ! pwalletMain - > Unlock ( strWalletPass ) ) {
return " incorrect passphrase " ;
}
}
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
std : : vector < CMasternodeConfig : : CMasternodeEntry > mnEntries ;
mnEntries = masternodeConfig . getEntries ( ) ;
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
int successful = 0 ;
2015-07-18 19:31:28 +02:00
int failed = 0 ;
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
Object resultsObj ;
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
BOOST_FOREACH ( CMasternodeConfig : : CMasternodeEntry mne , masternodeConfig . getEntries ( ) ) {
std : : string errorMessage ;
2015-03-21 20:49:21 +01:00
2015-07-18 03:23:52 +02:00
bool result = activeMasternode . Register ( mne . getIp ( ) , mne . getPrivKey ( ) , mne . getTxHash ( ) , mne . getOutputIndex ( ) , errorMessage ) ;
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
Object statusObj ;
statusObj . push_back ( Pair ( " alias " , mne . getAlias ( ) ) ) ;
2015-02-17 11:27:47 +01:00
statusObj . push_back ( Pair ( " result " , result ? " successful " : " failed " ) ) ;
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
if ( result ) {
successful + + ;
} else {
2015-07-18 19:31:28 +02:00
failed + + ;
2015-07-18 03:23:52 +02:00
statusObj . push_back ( Pair ( " errorMessage " , errorMessage ) ) ;
}
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
resultsObj . push_back ( Pair ( " status " , statusObj ) ) ;
}
pwalletMain - > Lock ( ) ;
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
Object returnObj ;
2015-07-18 19:31:28 +02:00
returnObj . push_back ( Pair ( " overall " , strprintf ( " Successfully started %d masternodes, failed to start %d, total %d " , successful , failed , successful + failed ) ) ) ;
2015-07-18 03:23:52 +02:00
returnObj . push_back ( Pair ( " detail " , resultsObj ) ) ;
2014-12-06 20:41:53 +01:00
2015-07-18 03:23:52 +02:00
return returnObj ;
2014-12-06 20:41:53 +01:00
}
2014-12-09 02:17:57 +01:00
if ( strCommand = = " create " )
{
return " Not implemented yet, please look at the documentation for instructions on masternode creation " ;
}
if ( strCommand = = " genkey " )
{
CKey secret ;
secret . MakeNewKey ( false ) ;
return CBitcoinSecret ( secret ) . ToString ( ) ;
}
2014-12-06 20:41:53 +01:00
if ( strCommand = = " list-conf " )
{
2015-07-18 03:23:52 +02:00
std : : vector < CMasternodeConfig : : CMasternodeEntry > mnEntries ;
mnEntries = masternodeConfig . getEntries ( ) ;
2014-12-06 20:41:53 +01:00
Object resultObj ;
BOOST_FOREACH ( CMasternodeConfig : : CMasternodeEntry mne , masternodeConfig . getEntries ( ) ) {
2015-03-16 20:44:16 +01:00
Object mnObj ;
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 ( ) ) ) ;
resultObj . push_back ( Pair ( " masternode " , mnObj ) ) ;
}
2014-12-06 20:41:53 +01:00
2015-03-16 20:44:16 +01:00
return resultObj ;
2014-12-06 20:41:53 +01:00
}
2014-12-26 21:00:56 +01:00
if ( strCommand = = " outputs " ) {
// Find possible candidates
vector < COutput > possibleCoins = activeMasternode . SelectCoinsMasternode ( ) ;
Object obj ;
BOOST_FOREACH ( COutput & out , possibleCoins ) {
2015-07-18 19:31:28 +02:00
obj . push_back ( Pair ( out . tx - > GetHash ( ) . ToString ( ) , strprintf ( " %d " , out . i ) ) ) ;
2014-12-26 21:00:56 +01:00
}
return obj ;
}
2015-06-24 18:41:03 +02:00
if ( strCommand = = " status " )
{
std : : vector < CMasternodeConfig : : CMasternodeEntry > mnEntries ;
mnEntries = masternodeConfig . getEntries ( ) ;
CScript pubkey ;
pubkey = GetScriptForDestination ( activeMasternode . pubKeyMasternode . GetID ( ) ) ;
CTxDestination address1 ;
ExtractDestination ( pubkey , address1 ) ;
CBitcoinAddress address2 ( address1 ) ;
Object mnObj ;
2015-07-18 19:31:28 +02:00
mnObj . push_back ( Pair ( " vin " , activeMasternode . vin . ToString ( ) ) ) ;
mnObj . push_back ( Pair ( " service " , activeMasternode . service . ToString ( ) ) ) ;
2015-06-24 18:41:03 +02:00
mnObj . push_back ( Pair ( " status " , activeMasternode . status ) ) ;
2015-07-18 19:31:28 +02:00
mnObj . push_back ( Pair ( " pubKeyMasternode " , address2 . ToString ( ) ) ) ;
mnObj . push_back ( Pair ( " notCapableReason " , activeMasternode . notCapableReason ) ) ;
2015-06-24 18:41:03 +02:00
return mnObj ;
}
2015-07-18 21:17:17 +02:00
if ( strCommand = = " winners " )
{
2015-07-21 00:09:42 +02:00
int nLast = 10 ;
if ( params . size ( ) > = 2 ) {
2015-07-22 00:14:54 +02:00
nLast = atoi ( params [ 1 ] . get_str ( ) ) ;
2015-07-21 00:09:42 +02:00
}
2015-07-18 21:17:17 +02:00
Object obj ;
2015-07-21 00:09:42 +02:00
for ( int nHeight = chainActive . Tip ( ) - > nHeight - nLast ; nHeight < chainActive . Tip ( ) - > nHeight + 20 ; nHeight + + )
2015-07-18 21:17:17 +02:00
{
obj . push_back ( Pair ( strprintf ( " %d " , nHeight ) , GetRequiredPaymentsString ( nHeight ) ) ) ;
}
return obj ;
}
2015-07-24 17:21:02 +02:00
/*
Shows which masternode wins by score each block
*/
if ( strCommand = = " calcscore " )
{
2015-07-26 14:15:43 +02:00
2015-07-24 17:21:02 +02:00
int nLast = 10 ;
if ( params . size ( ) > = 2 ) {
nLast = atoi ( params [ 1 ] . get_str ( ) ) ;
}
Object obj ;
std : : vector < CMasternode > vMasternodes = mnodeman . GetFullMasternodeVector ( ) ;
for ( int nHeight = chainActive . Tip ( ) - > nHeight - nLast ; nHeight < chainActive . Tip ( ) - > nHeight + 20 ; nHeight + + ) {
uint256 nHigh = 0 ;
CMasternode * pBestMasternode = NULL ;
BOOST_FOREACH ( CMasternode & mn , vMasternodes ) {
uint256 n = mn . CalculateScore ( 1 , nHeight - 100 ) ;
if ( n > nHigh ) {
nHigh = n ;
pBestMasternode = & mn ;
}
}
if ( pBestMasternode )
obj . push_back ( Pair ( strprintf ( " %d " , nHeight ) , pBestMasternode - > vin . prevout . ToStringShort ( ) . c_str ( ) ) ) ;
}
return obj ;
}
2014-12-09 02:17:57 +01:00
return Value : : null ;
}
2015-02-23 21:26:23 +01:00
Value masternodelist ( const Array & params , bool fHelp )
{
2015-03-31 03:14:44 +02:00
std : : string strMode = " status " ;
2015-02-23 21:26:23 +01:00
std : : string strFilter = " " ;
if ( params . size ( ) > = 1 ) strMode = params [ 0 ] . get_str ( ) ;
if ( params . size ( ) = = 2 ) strFilter = params [ 1 ] . get_str ( ) ;
if ( fHelp | |
2015-05-04 17:04:09 +02:00
( strMode ! = " status " & & strMode ! = " vin " & & strMode ! = " pubkey " & & strMode ! = " lastseen " & & strMode ! = " activeseconds " & & strMode ! = " rank " & & strMode ! = " addr "
2015-07-26 16:01:49 +02:00
& & strMode ! = " protocol " & & strMode ! = " full " & & strMode ! = " lastpaid " ) )
2015-02-23 21:26:23 +01:00
{
throw runtime_error (
" masternodelist ( \" mode \" \" filter \" ) \n "
" Get a list of masternodes in different modes \n "
" \n Arguments: \n "
2015-03-31 03:14:44 +02:00
" 1. \" mode \" (string, optional/required to use filter, defaults = status) The mode to run list in \n "
2015-04-05 23:59:25 +02:00
" 2. \" filter \" (string, optional) Filter results. Partial match by IP by default in all modes, \n "
" additional matches in some modes are also available \n "
2015-02-26 02:35:33 +01:00
" \n Available modes: \n "
2015-02-23 21:26:23 +01:00
" activeseconds - Print number of seconds masternode recognized by the network as enabled \n "
2015-07-14 07:25:07 +02:00
" (since latest issued \" masternode start/start-many/start-alias \" ) \n "
2015-07-18 19:31:28 +02:00
" addr - Print ip address associated with a masternode (can be additionally filtered, partial match) \n "
2015-06-23 22:44:20 +02:00
" full - Print info in format 'status protocol pubkey IP lastseen activeseconds lastpaid' \n "
2015-04-05 23:59:25 +02:00
" (can be additionally filtered, partial match) \n "
2015-02-23 21:26:23 +01:00
" lastseen - Print timestamp of when a masternode was last seen on the network \n "
2015-07-18 19:31:28 +02:00
" lastpaid - The last time a node was paid on the network \n "
2015-03-01 18:39:18 +01:00
" protocol - Print protocol of a masternode (can be additionally filtered, exact match)) \n "
2015-04-05 23:59:25 +02:00
" pubkey - Print public key associated with a masternode (can be additionally filtered, \n "
" partial match) \n "
2015-02-23 21:26:23 +01:00
" rank - Print rank of a masternode based on current block \n "
2015-04-05 23:59:25 +02:00
" status - Print masternode status: ENABLED / EXPIRED / VIN_SPENT / REMOVE / POS_ERROR \n "
" (can be additionally filtered, partial match) \n "
2015-02-23 21:26:23 +01:00
) ;
}
2015-02-24 00:48:11 +01:00
Object obj ;
2015-03-14 19:34:51 +01:00
if ( strMode = = " rank " ) {
std : : vector < pair < int , CMasternode > > vMasternodeRanks = mnodeman . GetMasternodeRanks ( chainActive . Tip ( ) - > nHeight ) ;
BOOST_FOREACH ( PAIRTYPE ( int , CMasternode ) & s , vMasternodeRanks ) {
2015-04-16 16:08:06 +02:00
std : : string strVin = s . second . vin . prevout . ToStringShort ( ) ;
if ( strFilter ! = " " & & strVin . find ( strFilter ) = = string : : npos ) continue ;
obj . push_back ( Pair ( strVin , s . first ) ) ;
2015-03-14 19:34:51 +01:00
}
} else {
std : : vector < CMasternode > vMasternodes = mnodeman . GetFullMasternodeVector ( ) ;
BOOST_FOREACH ( CMasternode & mn , vMasternodes ) {
2015-04-16 16:08:06 +02:00
std : : string strVin = mn . vin . prevout . ToStringShort ( ) ;
2015-03-31 03:14:44 +02:00
if ( strMode = = " activeseconds " ) {
2015-04-16 16:08:06 +02:00
if ( strFilter ! = " " & & strVin . find ( strFilter ) = = string : : npos ) continue ;
2015-07-14 07:25:07 +02:00
obj . push_back ( Pair ( strVin , ( int64_t ) ( mn . lastPing . sigTime - mn . sigTime ) ) ) ;
2015-07-18 19:31:28 +02:00
} else if ( strMode = = " addr " ) {
if ( strFilter ! = " " & & mn . vin . prevout . hash . ToString ( ) . find ( strFilter ) = = string : : npos & &
strVin . find ( strFilter ) = = string : : npos ) continue ;
obj . push_back ( Pair ( strVin , mn . addr . ToString ( ) ) ) ;
2015-03-14 19:34:51 +01:00
} else if ( strMode = = " full " ) {
CScript pubkey ;
2015-04-03 00:51:08 +02:00
pubkey = GetScriptForDestination ( mn . pubkey . GetID ( ) ) ;
2015-03-14 19:34:51 +01:00
CTxDestination address1 ;
ExtractDestination ( pubkey , address1 ) ;
CBitcoinAddress address2 ( address1 ) ;
2015-02-24 00:48:11 +01:00
2015-03-14 19:34:51 +01:00
std : : ostringstream addrStream ;
2015-04-16 16:08:06 +02:00
addrStream < < setw ( 21 ) < < strVin ;
2015-03-14 19:34:51 +01:00
std : : ostringstream stringStream ;
2015-07-18 19:31:28 +02:00
stringStream < < setw ( 9 ) < <
2015-03-31 03:14:44 +02:00
mn . Status ( ) < < " " < <
2015-03-14 19:34:51 +01:00
mn . protocolVersion < < " " < <
2015-07-18 19:31:28 +02:00
address2 . ToString ( ) < < " " < < setw ( 21 ) < <
2015-04-16 16:08:06 +02:00
mn . addr . ToString ( ) < < " " < <
2015-07-23 04:11:39 +02:00
( int64_t ) mn . lastPing . sigTime < < " " < < setw ( 8 ) < <
( int64_t ) ( mn . lastPing . sigTime - mn . sigTime ) < < " " < <
( int64_t ) mn . GetLastPaid ( ) ;
2015-03-14 19:34:51 +01:00
std : : string output = stringStream . str ( ) ;
2015-04-16 16:08:06 +02:00
stringStream < < " " < < strVin ;
2015-03-14 19:34:51 +01:00
if ( strFilter ! = " " & & stringStream . str ( ) . find ( strFilter ) = = string : : npos & &
2015-04-16 16:08:06 +02:00
strVin . find ( strFilter ) = = string : : npos ) continue ;
2015-03-14 19:34:51 +01:00
obj . push_back ( Pair ( addrStream . str ( ) , output ) ) ;
} else if ( strMode = = " lastseen " ) {
2015-04-16 16:08:06 +02:00
if ( strFilter ! = " " & & strVin . find ( strFilter ) = = string : : npos ) continue ;
2015-07-14 07:25:07 +02:00
obj . push_back ( Pair ( strVin , ( int64_t ) mn . lastPing . sigTime ) ) ;
2015-07-18 19:31:28 +02:00
} else if ( strMode = = " lastpaid " ) {
if ( strFilter ! = " " & & mn . vin . prevout . hash . ToString ( ) . find ( strFilter ) = = string : : npos & &
strVin . find ( strFilter ) = = string : : npos ) continue ;
obj . push_back ( Pair ( strVin , ( int64_t ) mn . GetLastPaid ( ) ) ) ;
2015-03-14 19:34:51 +01:00
} else if ( strMode = = " protocol " ) {
2015-07-18 19:31:28 +02:00
if ( strFilter ! = " " & & strFilter ! = strprintf ( " %d " , mn . protocolVersion ) & &
2015-04-16 16:08:06 +02:00
strVin . find ( strFilter ) = = string : : npos ) continue ;
obj . push_back ( Pair ( strVin , ( int64_t ) mn . protocolVersion ) ) ;
2015-03-14 19:34:51 +01:00
} else if ( strMode = = " pubkey " ) {
CScript pubkey ;
2015-04-03 00:51:08 +02:00
pubkey = GetScriptForDestination ( mn . pubkey . GetID ( ) ) ;
2015-03-14 19:34:51 +01:00
CTxDestination address1 ;
ExtractDestination ( pubkey , address1 ) ;
CBitcoinAddress address2 ( address1 ) ;
2015-03-01 18:39:18 +01:00
2015-03-14 19:34:51 +01:00
if ( strFilter ! = " " & & address2 . ToString ( ) . find ( strFilter ) = = string : : npos & &
2015-04-16 16:08:06 +02:00
strVin . find ( strFilter ) = = string : : npos ) continue ;
2015-07-18 19:31:28 +02:00
obj . push_back ( Pair ( strVin , address2 . ToString ( ) ) ) ;
2015-03-31 03:14:44 +02:00
} else if ( strMode = = " status " ) {
std : : string strStatus = mn . Status ( ) ;
2015-04-16 16:08:06 +02:00
if ( strFilter ! = " " & & strVin . find ( strFilter ) = = string : : npos & & strStatus . find ( strFilter ) = = string : : npos ) continue ;
2015-07-18 19:31:28 +02:00
obj . push_back ( Pair ( strVin , strStatus ) ) ;
2015-03-14 19:34:51 +01:00
}
2015-02-24 00:48:11 +01:00
}
}
return obj ;
2015-02-23 21:26:23 +01:00
}