2013-12-13 16:01:22 +01:00
// Copyright (c) 2010 Satoshi Nakamoto
2018-07-27 00:36:45 +02:00
// Copyright (c) 2009-2018 The Bitcoin Core developers
2014-11-20 03:19:29 +01:00
// Distributed under the MIT software license, see the accompanying
2013-12-13 16:01:22 +01:00
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2017-11-10 01:57:53 +01:00
# include <chain.h>
# include <clientversion.h>
# include <core_io.h>
# include <crypto/ripemd160.h>
2017-09-20 03:12:25 +02:00
# include <key_io.h>
2017-11-10 01:57:53 +01:00
# include <validation.h>
# include <httpserver.h>
# include <net.h>
# include <netbase.h>
2018-04-25 10:43:31 +02:00
# include <outputtype.h>
2017-11-10 01:57:53 +01:00
# include <rpc/blockchain.h>
# include <rpc/server.h>
2017-09-29 06:21:28 +02:00
# include <rpc/util.h>
2017-11-10 01:57:53 +01:00
# include <timedata.h>
# include <util.h>
# include <utilstrencodings.h>
# include <warnings.h>
2013-12-13 16:01:22 +01:00
# include <stdint.h>
2017-03-20 10:09:01 +01:00
# ifdef HAVE_MALLOC_INFO
# include <malloc.h>
# endif
2013-12-13 16:01:22 +01:00
2015-09-04 16:11:34 +02:00
# include <univalue.h>
2015-05-18 14:02:18 +02:00
2018-05-02 17:14:48 +02:00
static UniValue validateaddress ( const JSONRPCRequest & request )
2013-12-13 16:18:00 +01:00
{
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 1 )
2017-01-04 05:22:19 +01:00
throw std : : runtime_error (
2016-11-21 14:39:58 +01:00
" validateaddress \" address \" \n "
2013-12-13 16:18:00 +01:00
" \n Return information about the given bitcoin address. \n "
2017-06-13 03:53:46 +02:00
" DEPRECATION WARNING: Parts of this command have been deprecated and moved to getaddressinfo. Clients must \n "
" transition to using getaddressinfo to access this information before upgrading to v0.18. The following deprecated \n "
" fields have moved to getaddressinfo and will only be shown here with -deprecatedrpc=validateaddress: ismine, iswatchonly, \n "
" script, hex, pubkeys, sigsrequired, pubkey, addresses, embedded, iscompressed, account, timestamp, hdkeypath, kdmasterkeyid. \n "
2013-12-13 16:18:00 +01:00
" \n Arguments: \n "
2017-06-13 03:53:46 +02:00
" 1. \" address \" (string, required) The bitcoin address to validate \n "
2013-12-13 16:18:00 +01:00
" \n Result: \n "
" { \n "
2015-08-10 20:10:56 +02:00
" \" isvalid \" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned. \n "
2017-12-01 01:48:45 +01:00
" \" address \" : \" address \" , (string) The bitcoin address validated \n "
2018-10-02 21:49:18 +02:00
" \" scriptPubKey \" : \" hex \" , (string) The hex-encoded scriptPubKey generated by the address \n "
2017-06-13 03:53:46 +02:00
" \" isscript \" : true|false, (boolean) If the key is a script \n "
" \" iswitness \" : true|false, (boolean) If the address is a witness address \n "
" \" witness_version \" : version (numeric, optional) The version number of the witness program \n "
" \" witness_program \" : \" hex \" (string, optional) The hex value of the witness program \n "
2013-12-13 16:18:00 +01:00
" } \n "
" \n Examples: \n "
+ HelpExampleCli ( " validateaddress " , " \" 1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc \" " )
+ HelpExampleRpc ( " validateaddress " , " \" 1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc \" " )
) ;
2017-08-23 03:02:33 +02:00
CTxDestination dest = DecodeDestination ( request . params [ 0 ] . get_str ( ) ) ;
bool isValid = IsValidDestination ( dest ) ;
2013-12-13 16:18:00 +01:00
2015-05-10 14:48:35 +02:00
UniValue ret ( UniValue : : VOBJ ) ;
2017-09-22 20:04:07 +02:00
ret . pushKV ( " isvalid " , isValid ) ;
2013-12-13 16:18:00 +01:00
if ( isValid )
{
2018-02-20 15:02:34 +01:00
std : : string currentAddress = EncodeDestination ( dest ) ;
ret . pushKV ( " address " , currentAddress ) ;
2014-09-23 11:18:47 +02:00
2018-02-20 15:02:34 +01:00
CScript scriptPubKey = GetScriptForDestination ( dest ) ;
ret . pushKV ( " scriptPubKey " , HexStr ( scriptPubKey . begin ( ) , scriptPubKey . end ( ) ) ) ;
2017-06-13 03:53:46 +02:00
2018-02-20 15:02:34 +01:00
UniValue detail = DescribeAddress ( dest ) ;
ret . pushKVs ( detail ) ;
2013-12-13 16:18:00 +01:00
}
return ret ;
}
2018-05-02 17:14:48 +02:00
static UniValue createmultisig ( const JSONRPCRequest & request )
2013-12-13 16:21:38 +01:00
{
2018-04-25 10:43:31 +02:00
if ( request . fHelp | | request . params . size ( ) < 2 | | request . params . size ( ) > 3 )
2013-12-13 16:21:38 +01:00
{
2018-04-25 10:43:31 +02:00
std : : string msg = " createmultisig nrequired [ \" key \" ,...] ( \" address_type \" ) \n "
2013-12-13 16:21:38 +01:00
" \n Creates a multi-signature address with n signature of m keys required. \n "
" It returns a json object with the address and redeemScript. \n "
" \n Arguments: \n "
2018-02-21 17:08:20 +01:00
" 1. nrequired (numeric, required) The number of required signatures out of the n keys. \n "
2017-09-29 06:21:28 +02:00
" 2. \" keys \" (string, required) A json array of hex-encoded public keys \n "
2013-12-13 16:21:38 +01:00
" [ \n "
2017-09-29 06:21:28 +02:00
" \" key \" (string) The hex-encoded public key \n "
2013-12-13 16:21:38 +01:00
" ,... \n "
" ] \n "
2018-04-25 10:43:31 +02:00
" 3. \" address_type \" (string, optional) The address type to use. Options are \" legacy \" , \" p2sh-segwit \" , and \" bech32 \" . Default is legacy. \n "
2013-12-13 16:21:38 +01:00
" \n Result: \n "
" { \n "
" \" address \" : \" multisigaddress \" , (string) The value of the new multisig address. \n "
" \" redeemScript \" : \" script \" (string) The string value of the hex-encoded redemption script. \n "
" } \n "
" \n Examples: \n "
2017-09-29 06:21:28 +02:00
" \n Create a multisig address from 2 public keys \n "
+ HelpExampleCli ( " createmultisig " , " 2 \" [ \\ \" 03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd \\ \" , \\ \" 03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626 \\ \" ] \" " ) +
2018-10-02 21:49:18 +02:00
" \n As a JSON-RPC call \n "
2017-09-29 06:21:28 +02:00
+ HelpExampleRpc ( " createmultisig " , " 2, \" [ \\ \" 03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd \\ \" , \\ \" 03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626 \\ \" ] \" " )
2013-12-13 16:21:38 +01:00
;
2017-01-04 05:22:19 +01:00
throw std : : runtime_error ( msg ) ;
2013-12-13 16:21:38 +01:00
}
2017-09-29 06:21:28 +02:00
int required = request . params [ 0 ] . get_int ( ) ;
// Get the public keys
const UniValue & keys = request . params [ 1 ] . get_array ( ) ;
std : : vector < CPubKey > pubkeys ;
for ( unsigned int i = 0 ; i < keys . size ( ) ; + + i ) {
if ( IsHex ( keys [ i ] . get_str ( ) ) & & ( keys [ i ] . get_str ( ) . length ( ) = = 66 | | keys [ i ] . get_str ( ) . length ( ) = = 130 ) ) {
pubkeys . push_back ( HexToPubKey ( keys [ i ] . get_str ( ) ) ) ;
} else {
2018-08-06 17:49:05 +02:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , strprintf ( " Invalid public key: %s \n . " , keys [ i ] . get_str ( ) ) ) ;
2017-09-29 06:21:28 +02:00
}
}
2018-04-25 10:43:31 +02:00
// Get the output type
OutputType output_type = OutputType : : LEGACY ;
if ( ! request . params [ 2 ] . isNull ( ) ) {
if ( ! ParseOutputType ( request . params [ 2 ] . get_str ( ) , output_type ) ) {
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , strprintf ( " Unknown address type '%s' " , request . params [ 2 ] . get_str ( ) ) ) ;
}
}
2013-12-13 16:21:38 +01:00
// Construct using pay-to-script-hash:
2018-04-25 10:43:31 +02:00
const CScript inner = CreateMultisigRedeemscript ( required , pubkeys ) ;
CBasicKeyStore keystore ;
const CTxDestination dest = AddAndGetDestinationForScript ( keystore , inner , output_type ) ;
2013-12-13 16:21:38 +01:00
2015-06-02 12:28:54 +02:00
UniValue result ( UniValue : : VOBJ ) ;
2018-04-25 10:43:31 +02:00
result . pushKV ( " address " , EncodeDestination ( dest ) ) ;
2017-09-22 20:04:07 +02:00
result . pushKV ( " redeemScript " , HexStr ( inner . begin ( ) , inner . end ( ) ) ) ;
2013-12-13 16:21:38 +01:00
return result ;
}
2018-05-02 17:14:48 +02:00
static UniValue verifymessage ( const JSONRPCRequest & request )
2013-12-13 16:23:39 +01:00
{
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 3 )
2017-01-04 05:22:19 +01:00
throw std : : runtime_error (
2016-11-21 14:39:58 +01:00
" verifymessage \" address \" \" signature \" \" message \" \n "
2013-12-13 16:23:39 +01:00
" \n Verify a signed message \n "
" \n Arguments: \n "
2016-12-09 18:06:42 +01:00
" 1. \" address \" (string, required) The bitcoin address to use for the signature. \n "
2013-12-13 16:23:39 +01:00
" 2. \" signature \" (string, required) The signature provided by the signer in base 64 encoding (see signmessage). \n "
" 3. \" message \" (string, required) The message that was signed. \n "
" \n Result: \n "
" true|false (boolean) If the signature is verified or not. \n "
" \n Examples: \n "
" \n Unlock the wallet for 30 seconds \n "
+ HelpExampleCli ( " walletpassphrase " , " \" mypassphrase \" 30 " ) +
" \n Create the signature \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleCli ( " signmessage " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \" \" my message \" " ) +
2013-12-13 16:23:39 +01:00
" \n Verify the signature \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleCli ( " verifymessage " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \" \" signature \" \" my message \" " ) +
2018-10-02 21:49:18 +02:00
" \n As a JSON-RPC call \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleRpc ( " verifymessage " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \" , \" signature \" , \" my message \" " )
2013-12-13 16:23:39 +01:00
) ;
2014-10-19 10:46:17 +02:00
LOCK ( cs_main ) ;
2017-01-04 05:22:19 +01:00
std : : string strAddress = request . params [ 0 ] . get_str ( ) ;
std : : string strSign = request . params [ 1 ] . get_str ( ) ;
std : : string strMessage = request . params [ 2 ] . get_str ( ) ;
2013-12-13 16:23:39 +01:00
2017-08-23 03:02:33 +02:00
CTxDestination destination = DecodeDestination ( strAddress ) ;
if ( ! IsValidDestination ( destination ) ) {
2013-12-13 16:23:39 +01:00
throw JSONRPCError ( RPC_TYPE_ERROR , " Invalid address " ) ;
2017-08-23 03:02:33 +02:00
}
2013-12-13 16:23:39 +01:00
2017-08-23 03:02:33 +02:00
const CKeyID * keyID = boost : : get < CKeyID > ( & destination ) ;
if ( ! keyID ) {
2013-12-13 16:23:39 +01:00
throw JSONRPCError ( RPC_TYPE_ERROR , " Address does not refer to key " ) ;
2017-08-23 03:02:33 +02:00
}
2013-12-13 16:23:39 +01:00
bool fInvalid = false ;
2017-01-04 05:22:19 +01:00
std : : vector < unsigned char > vchSig = DecodeBase64 ( strSign . c_str ( ) , & fInvalid ) ;
2013-12-13 16:23:39 +01:00
if ( fInvalid )
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Malformed base64 encoding " ) ;
CHashWriter ss ( SER_GETHASH , 0 ) ;
ss < < strMessageMagic ;
ss < < strMessage ;
CPubKey pubkey ;
if ( ! pubkey . RecoverCompact ( ss . GetHash ( ) , vchSig ) )
return false ;
2017-08-23 03:02:33 +02:00
return ( pubkey . GetID ( ) = = * keyID ) ;
2013-12-13 16:23:39 +01:00
}
2014-11-13 00:59:41 +01:00
2018-05-02 17:14:48 +02:00
static UniValue signmessagewithprivkey ( const JSONRPCRequest & request )
2016-04-26 19:17:00 +02:00
{
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 2 )
2017-01-04 05:22:19 +01:00
throw std : : runtime_error (
2016-04-26 19:17:00 +02:00
" signmessagewithprivkey \" privkey \" \" message \" \n "
" \n Sign a message with the private key of an address \n "
" \n Arguments: \n "
" 1. \" privkey \" (string, required) The private key to sign the message with. \n "
" 2. \" message \" (string, required) The message to create a signature of. \n "
" \n Result: \n "
" \" signature \" (string) The signature of the message encoded in base 64 \n "
" \n Examples: \n "
" \n Create the signature \n "
+ HelpExampleCli ( " signmessagewithprivkey " , " \" privkey \" \" my message \" " ) +
" \n Verify the signature \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleCli ( " verifymessage " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \" \" signature \" \" my message \" " ) +
2018-10-02 21:49:18 +02:00
" \n As a JSON-RPC call \n "
2016-04-26 19:17:00 +02:00
+ HelpExampleRpc ( " signmessagewithprivkey " , " \" privkey \" , \" my message \" " )
) ;
2017-01-04 05:22:19 +01:00
std : : string strPrivkey = request . params [ 0 ] . get_str ( ) ;
std : : string strMessage = request . params [ 1 ] . get_str ( ) ;
2016-04-26 19:17:00 +02:00
2017-09-20 01:49:52 +02:00
CKey key = DecodeSecret ( strPrivkey ) ;
if ( ! key . IsValid ( ) ) {
2016-04-26 19:17:00 +02:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Invalid private key " ) ;
2017-09-20 01:49:52 +02:00
}
2016-04-26 19:17:00 +02:00
CHashWriter ss ( SER_GETHASH , 0 ) ;
ss < < strMessageMagic ;
ss < < strMessage ;
2017-01-04 05:22:19 +01:00
std : : vector < unsigned char > vchSig ;
2016-04-26 19:17:00 +02:00
if ( ! key . SignCompact ( ss . GetHash ( ) , vchSig ) )
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Sign failed " ) ;
2017-07-11 11:37:53 +02:00
return EncodeBase64 ( vchSig . data ( ) , vchSig . size ( ) ) ;
2016-04-26 19:17:00 +02:00
}
2018-05-02 17:14:48 +02:00
static UniValue setmocktime ( const JSONRPCRequest & request )
2014-11-13 00:59:41 +01:00
{
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 1 )
2017-01-04 05:22:19 +01:00
throw std : : runtime_error (
2014-11-13 00:59:41 +01:00
" setmocktime timestamp \n "
" \n Set the local time to given timestamp (-regtest only) \n "
" \n Arguments: \n "
" 1. timestamp (integer, required) Unix seconds-since-epoch timestamp \n "
" Pass 0 to go back to using the system time. "
) ;
if ( ! Params ( ) . MineBlocksOnDemand ( ) )
2017-01-04 05:22:19 +01:00
throw std : : runtime_error ( " setmocktime for regression testing (-regtest mode) only " ) ;
2014-11-13 00:59:41 +01:00
2017-01-19 19:01:18 +01:00
// For now, don't change mocktime if we're in the middle of validation, as
// this could have an effect on mempool time-based eviction, as well as
// IsCurrentForFeeEstimation() and IsInitialBlockDownload().
// TODO: figure out the right way to synchronize around mocktime, and
2017-02-06 15:16:18 +01:00
// ensure all call sites of GetTime() are accessing this safely.
2016-04-17 01:13:12 +02:00
LOCK ( cs_main ) ;
2014-10-19 10:46:17 +02:00
2017-06-06 21:15:28 +02:00
RPCTypeCheck ( request . params , { UniValue : : VNUM } ) ;
2016-09-22 09:46:41 +02:00
SetMockTime ( request . params [ 0 ] . get_int64 ( ) ) ;
2014-11-13 00:59:41 +01:00
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2014-11-13 00:59:41 +01:00
}
2016-03-29 19:43:02 +02:00
2016-09-18 10:22:30 +02:00
static UniValue RPCLockedMemoryInfo ( )
{
LockedPool : : Stats stats = LockedPoolManager : : Instance ( ) . stats ( ) ;
UniValue obj ( UniValue : : VOBJ ) ;
2017-09-22 20:04:07 +02:00
obj . pushKV ( " used " , uint64_t ( stats . used ) ) ;
obj . pushKV ( " free " , uint64_t ( stats . free ) ) ;
obj . pushKV ( " total " , uint64_t ( stats . total ) ) ;
obj . pushKV ( " locked " , uint64_t ( stats . locked ) ) ;
obj . pushKV ( " chunks_used " , uint64_t ( stats . chunks_used ) ) ;
obj . pushKV ( " chunks_free " , uint64_t ( stats . chunks_free ) ) ;
2016-09-18 10:22:30 +02:00
return obj ;
}
2017-03-20 10:09:01 +01:00
# ifdef HAVE_MALLOC_INFO
static std : : string RPCMallocInfo ( )
{
char * ptr = nullptr ;
size_t size = 0 ;
FILE * f = open_memstream ( & ptr , & size ) ;
if ( f ) {
malloc_info ( 0 , f ) ;
fclose ( f ) ;
if ( ptr ) {
std : : string rv ( ptr , size ) ;
free ( ptr ) ;
return rv ;
}
}
return " " ;
}
# endif
2018-05-02 17:14:48 +02:00
static UniValue getmemoryinfo ( const JSONRPCRequest & request )
2016-09-18 10:22:30 +02:00
{
/* Please, avoid using the word "pool" here in the RPC interface or help,
* as users will undoubtedly confuse it with the other " memory pool "
*/
2017-03-20 10:09:01 +01:00
if ( request . fHelp | | request . params . size ( ) > 1 )
2017-01-04 05:22:19 +01:00
throw std : : runtime_error (
2017-03-20 10:09:01 +01:00
" getmemoryinfo ( \" mode \" ) \n "
2016-09-18 10:22:30 +02:00
" Returns an object containing information about memory usage. \n "
2017-03-20 10:09:01 +01:00
" Arguments: \n "
" 1. \" mode \" determines what kind of information is returned. This argument is optional, the default mode is \" stats \" . \n "
" - \" stats \" returns general statistics about memory usage in the daemon. \n "
" - \" mallocinfo \" returns an XML string describing low-level heap state (only available if compiled with glibc 2.10+). \n "
" \n Result (mode \" stats \" ): \n "
2016-09-18 10:22:30 +02:00
" { \n "
" \" locked \" : { (json object) Information about locked memory manager \n "
" \" used \" : xxxxx, (numeric) Number of bytes used \n "
" \" free \" : xxxxx, (numeric) Number of bytes available in current arenas \n "
" \" total \" : xxxxxxx, (numeric) Total number of bytes managed \n "
" \" locked \" : xxxxxx, (numeric) Amount of bytes that succeeded locking. If this number is smaller than total, locking pages failed at some point and key data could be swapped to disk. \n "
" \" chunks_used \" : xxxxx, (numeric) Number allocated chunks \n "
" \" chunks_free \" : xxxxx, (numeric) Number unused chunks \n "
" } \n "
" } \n "
2017-03-20 10:09:01 +01:00
" \n Result (mode \" mallocinfo \" ): \n "
" \" <malloc version= \" 1 \" >... \" \n "
2016-09-18 10:22:30 +02:00
" \n Examples: \n "
+ HelpExampleCli ( " getmemoryinfo " , " " )
+ HelpExampleRpc ( " getmemoryinfo " , " " )
) ;
2017-03-20 10:09:01 +01:00
2017-08-15 01:38:18 +02:00
std : : string mode = request . params [ 0 ] . isNull ( ) ? " stats " : request . params [ 0 ] . get_str ( ) ;
2017-03-20 10:09:01 +01:00
if ( mode = = " stats " ) {
UniValue obj ( UniValue : : VOBJ ) ;
2017-09-22 20:04:07 +02:00
obj . pushKV ( " locked " , RPCLockedMemoryInfo ( ) ) ;
2017-03-20 10:09:01 +01:00
return obj ;
} else if ( mode = = " mallocinfo " ) {
# ifdef HAVE_MALLOC_INFO
return RPCMallocInfo ( ) ;
# else
throw JSONRPCError ( RPC_INVALID_PARAMETER , " mallocinfo is only available when compiled with glibc 2.10+ " ) ;
# endif
} else {
throw JSONRPCError ( RPC_INVALID_PARAMETER , " unknown mode " + mode ) ;
}
2016-09-18 10:22:30 +02:00
}
2018-05-02 17:14:48 +02:00
static void EnableOrDisableLogCategories ( UniValue cats , bool enable ) {
2017-04-03 19:39:11 +02:00
cats = cats . get_array ( ) ;
for ( unsigned int i = 0 ; i < cats . size ( ) ; + + i ) {
std : : string cat = cats [ i ] . get_str ( ) ;
2018-04-11 23:06:35 +02:00
bool success ;
2018-04-11 22:02:01 +02:00
if ( enable ) {
2018-04-11 23:06:35 +02:00
success = g_logger - > EnableCategory ( cat ) ;
2018-04-11 22:02:01 +02:00
} else {
2018-04-11 23:06:35 +02:00
success = g_logger - > DisableCategory ( cat ) ;
}
if ( ! success ) {
throw JSONRPCError ( RPC_INVALID_PARAMETER , " unknown logging category " + cat ) ;
2017-08-29 13:32:16 +02:00
}
2017-04-03 19:39:11 +02:00
}
}
UniValue logging ( const JSONRPCRequest & request )
{
if ( request . fHelp | | request . params . size ( ) > 2 ) {
throw std : : runtime_error (
2017-08-29 13:32:16 +02:00
" logging ( <include> <exclude> ) \n "
2017-04-03 19:39:11 +02:00
" Gets and sets the logging configuration. \n "
2017-08-29 13:32:16 +02:00
" When called without an argument, returns the list of categories with status that are currently being debug logged or not. \n "
" When called with arguments, adds or removes categories from debug logging and return the lists above. \n "
" The arguments are evaluated in order \" include \" , \" exclude \" . \n "
" If an item is both included and excluded, it will thus end up being excluded. \n "
2017-04-03 19:39:11 +02:00
" The valid logging categories are: " + ListLogCategories ( ) + " \n "
2017-08-29 13:32:16 +02:00
" In addition, the following are available as category names with special meanings: \n "
" - \" all \" , \" 1 \" : represent all logging categories. \n "
" - \" none \" , \" 0 \" : even if other logging categories are specified, ignore all of them. \n "
" \n Arguments: \n "
" 1. \" include \" (array of strings, optional) A json array of categories to add debug logging \n "
" [ \n "
" \" category \" (string) the valid logging category \n "
" ,... \n "
" ] \n "
" 2. \" exclude \" (array of strings, optional) A json array of categories to remove debug logging \n "
" [ \n "
" \" category \" (string) the valid logging category \n "
" ,... \n "
" ] \n "
" \n Result: \n "
" { (json object where keys are the logging categories, and values indicates its status \n "
" \" category \" : 0|1, (numeric) if being debug logged or not. 0:inactive, 1:active \n "
" ... \n "
" } \n "
2017-04-03 19:39:11 +02:00
" \n Examples: \n "
+ HelpExampleCli ( " logging " , " \" [ \\ \" all \\ \" ] \" \" [ \\ \" http \\ \" ] \" " )
+ HelpExampleRpc ( " logging " , " [ \" all \" ], \" [libevent] \" " )
) ;
}
2018-04-11 22:02:01 +02:00
uint32_t original_log_categories = g_logger - > GetCategoryMask ( ) ;
2017-08-15 01:38:18 +02:00
if ( request . params [ 0 ] . isArray ( ) ) {
2018-04-11 22:02:01 +02:00
EnableOrDisableLogCategories ( request . params [ 0 ] , true ) ;
2017-04-03 19:39:11 +02:00
}
2017-08-15 01:38:18 +02:00
if ( request . params [ 1 ] . isArray ( ) ) {
2018-04-11 22:02:01 +02:00
EnableOrDisableLogCategories ( request . params [ 1 ] , false ) ;
2017-04-03 19:39:11 +02:00
}
2018-04-11 22:02:01 +02:00
uint32_t updated_log_categories = g_logger - > GetCategoryMask ( ) ;
uint32_t changed_log_categories = original_log_categories ^ updated_log_categories ;
2017-04-03 19:39:11 +02:00
2017-04-10 16:34:23 +02:00
// Update libevent logging if BCLog::LIBEVENT has changed.
// If the library version doesn't allow it, UpdateHTTPServerLogging() returns false,
// in which case we should clear the BCLog::LIBEVENT flag.
// Throw an error if the user has explicitly asked to change only the libevent
// flag and it failed.
2018-04-11 22:02:01 +02:00
if ( changed_log_categories & BCLog : : LIBEVENT ) {
if ( ! UpdateHTTPServerLogging ( g_logger - > WillLogCategory ( BCLog : : LIBEVENT ) ) ) {
g_logger - > DisableCategory ( BCLog : : LIBEVENT ) ;
if ( changed_log_categories = = BCLog : : LIBEVENT ) {
2017-04-10 16:34:23 +02:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " libevent logging cannot be updated when using libevent before v2.1.1. " ) ;
}
}
}
2017-04-03 19:39:11 +02:00
UniValue result ( UniValue : : VOBJ ) ;
std : : vector < CLogCategoryActive > vLogCatActive = ListActiveLogCategories ( ) ;
for ( const auto & logCatActive : vLogCatActive ) {
result . pushKV ( logCatActive . category , logCatActive . active ) ;
}
return result ;
}
2018-05-02 17:14:48 +02:00
static UniValue echo ( const JSONRPCRequest & request )
2016-09-25 20:55:24 +02:00
{
if ( request . fHelp )
2017-01-04 05:22:19 +01:00
throw std : : runtime_error (
2016-11-22 14:56:29 +01:00
" echo|echojson \" message \" ... \n "
" \n Simply echo back the input arguments. This command is for testing. \n "
" \n The difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in "
" bitcoin-cli and the GUI. There is no server-side difference. "
2016-09-25 20:55:24 +02:00
) ;
return request . params ;
}
2018-08-20 14:19:43 +02:00
// clang-format off
2016-03-29 19:43:02 +02:00
static const CRPCCommand commands [ ] =
2017-06-09 02:38:23 +02:00
{ // category name actor (function) argNames
2016-03-29 19:43:02 +02:00
// --------------------- ------------------------ ----------------------- ----------
2017-06-09 02:38:23 +02:00
{ " control " , " getmemoryinfo " , & getmemoryinfo , { " mode " } } ,
2017-11-07 07:50:49 +01:00
{ " control " , " logging " , & logging , { " include " , " exclude " } } ,
2018-02-20 15:02:34 +01:00
{ " util " , " validateaddress " , & validateaddress , { " address " } } ,
2017-06-09 02:38:23 +02:00
{ " util " , " createmultisig " , & createmultisig , { " nrequired " , " keys " } } ,
{ " util " , " verifymessage " , & verifymessage , { " address " , " signature " , " message " } } ,
{ " util " , " signmessagewithprivkey " , & signmessagewithprivkey , { " privkey " , " message " } } ,
2016-03-29 19:43:02 +02:00
/* Not shown in help */
2017-06-09 02:38:23 +02:00
{ " hidden " , " setmocktime " , & setmocktime , { " timestamp " } } ,
{ " hidden " , " echo " , & echo , { " arg0 " , " arg1 " , " arg2 " , " arg3 " , " arg4 " , " arg5 " , " arg6 " , " arg7 " , " arg8 " , " arg9 " } } ,
{ " hidden " , " echojson " , & echo , { " arg0 " , " arg1 " , " arg2 " , " arg3 " , " arg4 " , " arg5 " , " arg6 " , " arg7 " , " arg8 " , " arg9 " } } ,
2016-03-29 19:43:02 +02:00
} ;
2018-08-20 14:19:43 +02:00
// clang-format on
2016-03-29 19:43:02 +02:00
2016-06-07 18:42:42 +02:00
void RegisterMiscRPCCommands ( CRPCTable & t )
2016-03-29 19:43:02 +02:00
{
for ( unsigned int vcidx = 0 ; vcidx < ARRAYLEN ( commands ) ; vcidx + + )
2016-06-07 18:42:42 +02:00
t . appendCommand ( commands [ vcidx ] . name , & commands [ vcidx ] ) ;
2016-03-29 19:43:02 +02:00
}