2017-11-09 19:34:51 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2010 Satoshi Nakamoto
* Copyright (C) 2009-2015 The Bitcoin Core developers
2021-01-20 19:21:53 +01:00
* Copyright (C) 2016-2021 Tom Zander <tom@flowee.org>
2017-11-09 19:34:51 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2013-12-13 16:01:22 +01:00
2019-04-11 11:33:27 +02:00
# include "encodings_legacy.h"
2014-10-28 21:33:23 -04:00
# include "clientversion.h"
2013-12-13 16:01:22 +01:00
# include "init.h"
# include "main.h"
2021-01-05 22:05:25 +01:00
# include <hash.h>
2013-12-13 16:01:22 +01:00
# include "net.h"
# include "netbase.h"
2014-01-11 18:14:29 +01:00
# include "rpcserver.h"
2014-06-19 15:08:37 +02:00
# include "timedata.h"
2013-12-13 16:01:22 +01:00
# include "util.h"
2015-07-05 14:17:46 +02:00
# include "utilstrencodings.h"
2013-12-13 16:01:22 +01:00
# ifdef ENABLE_WALLET
2015-02-03 21:09:47 +01:00
# include "wallet/wallet.h"
# include "wallet/walletdb.h"
2013-12-13 16:01:22 +01:00
# endif
# include <boost/assign/list_of.hpp>
2018-12-30 15:33:11 +01:00
# include <boost/foreach.hpp>
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
2014-07-28 19:30:43 +02:00
/**
* @note Do not add or change anything in the information returned by this
2014-11-20 10:19:29 +08:00
* method. `getinfo` exists for backwards-compatibility only. It combines
2014-07-28 19:30:43 +02:00
* information from wildly different sources in the program, which is a mess,
* and is thus planned to be deprecated eventually.
*
* Based on the source of the information, new information should be added to:
* - `getblockchaininfo`,
* - `getnetworkinfo` or
* - `getwalletinfo`
*
* Or alternatively, create a specific query method for the information.
**/
2015-05-18 14:02:18 +02:00
UniValue getinfo ( const UniValue & params , bool fHelp )
2013-12-13 16:03:57 +01:00
{
if ( fHelp | | params . size ( ) ! = 0 )
2017-08-02 19:53:22 +05:30
throw std : : runtime_error (
2013-12-13 16:03:57 +01:00
" getinfo \n "
" Returns an object containing various state info. \n "
" \n Result: \n "
" { \n "
" \" version \" : xxxxx, (numeric) the server version \n "
" \" protocolversion \" : xxxxx, (numeric) the protocol version \n "
" \" walletversion \" : xxxxx, (numeric) the wallet version \n "
" \" balance \" : xxxxxxx, (numeric) the total bitcoin balance of the wallet \n "
" \" blocks \" : xxxxxx, (numeric) the current number of blocks processed in the server \n "
" \" timeoffset \" : xxxxx, (numeric) the time offset \n "
" \" connections \" : xxxxx, (numeric) the number of connections \n "
" \" proxy \" : \" host:port \" , (string, optional) the proxy used by the server \n "
" \" difficulty \" : xxxxxx, (numeric) the current difficulty \n "
" \" testnet \" : true|false, (boolean) if the server is using testnet or not \n "
" \" keypoololdest \" : xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool \n "
" \" keypoolsize \" : xxxx, (numeric) how many new keys are pre-generated \n "
" \" unlocked_until \" : ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked \n "
2021-01-20 19:21:53 +01:00
" \" paytxfee \" : x.xxxx, (numeric) the transaction fee set in BCH/kB \n "
" \" relayfee \" : x.xxxx, (numeric) minimum relay fee for non-free transactions in BCH/kB \n "
2013-12-13 16:03:57 +01:00
" \" errors \" : \" ... \" (string) any error messages \n "
" } \n "
" \n Examples: \n "
+ HelpExampleCli ( " getinfo " , " " )
+ HelpExampleRpc ( " getinfo " , " " )
) ;
2014-10-19 04:46:17 -04:00
# ifdef ENABLE_WALLET
LOCK2 ( cs_main , pwalletMain ? & pwalletMain - > cs_wallet : NULL ) ;
# else
LOCK ( cs_main ) ;
# endif
2013-12-13 16:03:57 +01:00
proxyType proxy ;
2016-11-22 12:54:44 +01:00
GetProxy ( CNetAddr : : NET_IPV4 , proxy ) ;
2013-12-13 16:03:57 +01:00
2015-05-10 14:48:35 +02:00
UniValue obj ( UniValue : : VOBJ ) ;
2014-09-09 10:09:59 +02:00
obj . push_back ( Pair ( " version " , CLIENT_VERSION ) ) ;
obj . push_back ( Pair ( " protocolversion " , PROTOCOL_VERSION ) ) ;
2013-12-13 16:03:57 +01:00
# ifdef ENABLE_WALLET
if ( pwalletMain ) {
obj . push_back ( Pair ( " walletversion " , pwalletMain - > GetVersion ( ) ) ) ;
obj . push_back ( Pair ( " balance " , ValueFromAmount ( pwalletMain - > GetBalance ( ) ) ) ) ;
}
# endif
obj . push_back ( Pair ( " blocks " , ( int ) chainActive . Height ( ) ) ) ;
2014-05-06 14:58:43 +02:00
obj . push_back ( Pair ( " timeoffset " , GetTimeOffset ( ) ) ) ;
2013-12-13 16:03:57 +01:00
obj . push_back ( Pair ( " connections " , ( int ) vNodes . size ( ) ) ) ;
2017-08-02 19:53:22 +05:30
obj . push_back ( Pair ( " proxy " , ( proxy . IsValid ( ) ? proxy . proxy . ToStringIPPort ( ) : std : : string ( ) ) ) ) ;
2013-12-13 16:03:57 +01:00
obj . push_back ( Pair ( " difficulty " , ( double ) GetDifficulty ( ) ) ) ;
2014-08-31 22:32:52 +02:00
obj . push_back ( Pair ( " testnet " , Params ( ) . TestnetToBeDeprecatedFieldRPC ( ) ) ) ;
2013-12-13 16:03:57 +01:00
# ifdef ENABLE_WALLET
if ( pwalletMain ) {
2014-05-06 14:58:43 +02:00
obj . push_back ( Pair ( " keypoololdest " , pwalletMain - > GetOldestKeyPoolTime ( ) ) ) ;
2013-12-13 16:03:57 +01:00
obj . push_back ( Pair ( " keypoolsize " , ( int ) pwalletMain - > GetKeyPoolSize ( ) ) ) ;
}
if ( pwalletMain & & pwalletMain - > IsCrypted ( ) )
2014-05-06 14:58:43 +02:00
obj . push_back ( Pair ( " unlocked_until " , nWalletUnlockTime ) ) ;
2014-04-10 14:14:18 -04:00
obj . push_back ( Pair ( " paytxfee " , ValueFromAmount ( payTxFee . GetFeePerK ( ) ) ) ) ;
2013-12-13 16:03:57 +01:00
# endif
2014-07-03 14:25:32 -04:00
obj . push_back ( Pair ( " relayfee " , ValueFromAmount ( : : minRelayTxFee . GetFeePerK ( ) ) ) ) ;
2013-12-13 16:03:57 +01:00
obj . push_back ( Pair ( " errors " , GetWarnings ( " statusbar " ) ) ) ;
return obj ;
}
2013-12-13 16:18:00 +01:00
# ifdef ENABLE_WALLET
2015-05-18 14:02:18 +02:00
class DescribeAddressVisitor : public boost : : static_visitor < UniValue >
2013-12-13 16:18:00 +01:00
{
public :
2015-05-18 14:02:18 +02:00
UniValue operator ( ) ( const CNoDestination & dest ) const { return UniValue ( UniValue : : VOBJ ) ; }
2013-12-13 16:18:00 +01:00
2015-05-13 21:29:19 +02:00
UniValue operator ( ) ( const CKeyID & keyID ) const {
2015-05-10 14:48:35 +02:00
UniValue obj ( UniValue : : VOBJ ) ;
2013-12-13 16:18:00 +01:00
CPubKey vchPubKey ;
obj . push_back ( Pair ( " isscript " , false ) ) ;
2015-11-09 08:40:46 +01:00
if ( pwalletMain & & pwalletMain - > GetPubKey ( keyID , vchPubKey ) ) {
2013-07-26 01:06:01 +02:00
obj . push_back ( Pair ( " pubkey " , HexStr ( vchPubKey ) ) ) ;
2021-04-19 11:58:00 +02:00
obj . push_back ( Pair ( " iscompressed " , vchPubKey . isCompressed ( ) ) ) ;
2013-07-26 01:06:01 +02:00
}
2013-12-13 16:18:00 +01:00
return obj ;
}
2015-05-13 21:29:19 +02:00
UniValue operator ( ) ( const CScriptID & scriptID ) const {
2015-05-10 14:48:35 +02:00
UniValue obj ( UniValue : : VOBJ ) ;
2015-06-09 17:11:13 +02:00
CScript subscript ;
2013-12-13 16:18:00 +01:00
obj . push_back ( Pair ( " isscript " , true ) ) ;
2015-11-09 08:40:46 +01:00
if ( pwalletMain & & pwalletMain - > GetCScript ( scriptID , subscript ) ) {
2013-07-26 01:06:01 +02:00
std : : vector < CTxDestination > addresses ;
2019-06-06 21:37:49 +02:00
Script : : TxnOutType whichType ;
2013-07-26 01:06:01 +02:00
int nRequired ;
ExtractDestinations ( subscript , whichType , addresses , nRequired ) ;
2019-06-06 21:37:49 +02:00
obj . push_back ( Pair ( " script " , Script : : getTxnOutputType ( whichType ) ) ) ;
2013-07-26 01:06:01 +02:00
obj . push_back ( Pair ( " hex " , HexStr ( subscript . begin ( ) , subscript . end ( ) ) ) ) ;
2015-05-10 14:48:35 +02:00
UniValue a ( UniValue : : VARR ) ;
2019-06-06 21:37:49 +02:00
for ( const CTxDestination & addr : addresses )
2013-07-26 01:06:01 +02:00
a . push_back ( CBitcoinAddress ( addr ) . ToString ( ) ) ;
obj . push_back ( Pair ( " addresses " , a ) ) ;
2019-06-06 21:37:49 +02:00
if ( whichType = = Script : : TX_MULTISIG )
2013-07-26 01:06:01 +02:00
obj . push_back ( Pair ( " sigsrequired " , nRequired ) ) ;
}
2013-12-13 16:18:00 +01:00
return obj ;
}
} ;
# endif
2015-05-18 14:02:18 +02:00
UniValue validateaddress ( const UniValue & params , bool fHelp )
2013-12-13 16:18:00 +01:00
{
if ( fHelp | | params . size ( ) ! = 1 )
2017-08-02 19:53:22 +05:30
throw std : : runtime_error (
2013-12-13 16:18:00 +01:00
" validateaddress \" bitcoinaddress \" \n "
" \n Return information about the given bitcoin address. \n "
" \n Arguments: \n "
" 1. \" bitcoinaddress \" (string, required) The bitcoin address to validate \n "
" \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 "
2013-12-13 16:18:00 +01:00
" \" address \" : \" bitcoinaddress \" , (string) The bitcoin address validated \n "
2014-09-23 05:18:47 -04:00
" \" scriptPubKey \" : \" hex \" , (string) The hex encoded scriptPubKey generated by the address \n "
2015-08-10 20:10:56 +02:00
" \" ismine \" : true|false, (boolean) If the address is yours or not \n "
" \" iswatchonly \" : true|false, (boolean) If the address is watchonly \n "
" \" isscript \" : true|false, (boolean) If the key is a script \n "
2013-12-13 16:18:00 +01:00
" \" pubkey \" : \" publickeyhex \" , (string) The hex value of the raw public key \n "
2015-08-10 20:10:56 +02:00
" \" iscompressed \" : true|false, (boolean) If the address is compressed \n "
2014-12-30 14:32:07 +00:00
" \" account \" : \" account \" (string) DEPRECATED. The account associated with the address, \" \" is the default account \n "
2013-12-13 16:18:00 +01:00
" } \n "
" \n Examples: \n "
+ HelpExampleCli ( " validateaddress " , " \" 1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc \" " )
+ HelpExampleRpc ( " validateaddress " , " \" 1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc \" " )
) ;
2014-10-19 04:46:17 -04:00
# ifdef ENABLE_WALLET
LOCK2 ( cs_main , pwalletMain ? & pwalletMain - > cs_wallet : NULL ) ;
# else
LOCK ( cs_main ) ;
# endif
2013-12-13 16:18:00 +01:00
CBitcoinAddress address ( params [ 0 ] . get_str ( ) ) ;
bool isValid = address . IsValid ( ) ;
2015-05-10 14:48:35 +02:00
UniValue ret ( UniValue : : VOBJ ) ;
2013-12-13 16:18:00 +01:00
ret . push_back ( Pair ( " isvalid " , isValid ) ) ;
if ( isValid )
{
CTxDestination dest = address . Get ( ) ;
2017-08-02 19:53:22 +05:30
std : : string currentAddress = address . ToString ( ) ;
2013-12-13 16:18:00 +01:00
ret . push_back ( Pair ( " address " , currentAddress ) ) ;
2014-09-23 05:18:47 -04:00
CScript scriptPubKey = GetScriptForDestination ( dest ) ;
ret . push_back ( Pair ( " scriptPubKey " , HexStr ( scriptPubKey . begin ( ) , scriptPubKey . end ( ) ) ) ) ;
2013-12-13 16:18:00 +01:00
# ifdef ENABLE_WALLET
2014-07-01 11:00:22 +02:00
isminetype mine = pwalletMain ? IsMine ( * pwalletMain , dest ) : ISMINE_NO ;
ret . push_back ( Pair ( " ismine " , ( mine & ISMINE_SPENDABLE ) ? true : false ) ) ;
2015-06-09 17:11:13 +02:00
ret . push_back ( Pair ( " iswatchonly " , ( mine & ISMINE_WATCH_ONLY ) ? true : false ) ) ;
UniValue detail = boost : : apply_visitor ( DescribeAddressVisitor ( ) , dest ) ;
ret . pushKVs ( detail ) ;
2013-12-13 16:18:00 +01:00
if ( pwalletMain & & pwalletMain - > mapAddressBook . count ( dest ) )
ret . push_back ( Pair ( " account " , pwalletMain - > mapAddressBook [ dest ] . name ) ) ;
# endif
}
return ret ;
}
2014-11-20 10:19:29 +08:00
/**
* Used by addmultisigaddress / createmultisig:
*/
2015-05-18 14:02:18 +02:00
CScript _createmultisig_redeemScript ( const UniValue & params )
2013-12-13 16:21:38 +01:00
{
int nRequired = params [ 0 ] . get_int ( ) ;
2015-05-18 14:02:18 +02:00
const UniValue & keys = params [ 1 ] . get_array ( ) ;
2013-12-13 16:21:38 +01:00
// Gather public keys
if ( nRequired < 1 )
2017-08-02 19:53:22 +05:30
throw std : : runtime_error ( " a multisignature address must require at least one key to redeem " ) ;
2013-12-13 16:21:38 +01:00
if ( ( int ) keys . size ( ) < nRequired )
2017-08-02 19:53:22 +05:30
throw std : : runtime_error (
2013-12-13 16:21:38 +01:00
strprintf ( " not enough keys supplied "
2014-05-06 15:25:01 +02:00
" (got %u keys, but need at least %d to redeem) " , keys . size ( ) , nRequired ) ) ;
2015-01-25 18:11:57 +06:00
if ( keys . size ( ) > 16 )
2017-08-02 19:53:22 +05:30
throw std : : runtime_error ( " Number of addresses involved in the multisignature address creation > 16 \n Reduce the number " ) ;
2013-12-13 16:21:38 +01:00
std : : vector < CPubKey > pubkeys ;
pubkeys . resize ( keys . size ( ) ) ;
for ( unsigned int i = 0 ; i < keys . size ( ) ; i + + )
{
const std : : string & ks = keys [ i ] . get_str ( ) ;
# ifdef ENABLE_WALLET
// Case 1: Bitcoin address and we have full public key:
CBitcoinAddress address ( ks ) ;
if ( pwalletMain & & address . IsValid ( ) )
{
CKeyID keyID ;
if ( ! address . GetKeyID ( keyID ) )
2017-08-02 19:53:22 +05:30
throw std : : runtime_error (
2014-01-16 16:15:27 +01:00
strprintf ( " %s does not refer to a key " , ks ) ) ;
2013-12-13 16:21:38 +01:00
CPubKey vchPubKey ;
if ( ! pwalletMain - > GetPubKey ( keyID , vchPubKey ) )
2017-08-02 19:53:22 +05:30
throw std : : runtime_error (
2014-01-16 16:15:27 +01:00
strprintf ( " no full public key for address %s " , ks ) ) ;
2021-04-19 11:58:00 +02:00
if ( ! vchPubKey . isFullyValid ( ) )
2017-08-02 19:53:22 +05:30
throw std : : runtime_error ( " Invalid public key: " + ks ) ;
2013-12-13 16:21:38 +01:00
pubkeys [ i ] = vchPubKey ;
}
// Case 2: hex public key
else
# endif
if ( IsHex ( ks ) )
{
CPubKey vchPubKey ( ParseHex ( ks ) ) ;
2021-04-19 11:58:00 +02:00
if ( ! vchPubKey . isFullyValid ( ) )
2017-08-02 19:53:22 +05:30
throw std : : runtime_error ( " Invalid public key: " + ks ) ;
2013-12-13 16:21:38 +01:00
pubkeys [ i ] = vchPubKey ;
}
else
{
2017-08-02 19:53:22 +05:30
throw std : : runtime_error ( " Invalid public key: " + ks ) ;
2013-12-13 16:21:38 +01:00
}
}
2014-09-11 19:15:29 +02:00
CScript result = GetScriptForMultisig ( nRequired , pubkeys ) ;
2014-03-10 22:43:15 -04:00
if ( result . size ( ) > MAX_SCRIPT_ELEMENT_SIZE )
2017-08-02 19:53:22 +05:30
throw std : : runtime_error (
2014-03-10 22:43:15 -04:00
strprintf ( " redeemScript exceeds size limit: %d > %d " , result . size ( ) , MAX_SCRIPT_ELEMENT_SIZE ) ) ;
2013-12-13 16:21:38 +01:00
return result ;
}
2015-05-18 14:02:18 +02:00
UniValue createmultisig ( const UniValue & params , bool fHelp )
2013-12-13 16:21:38 +01:00
{
if ( fHelp | | params . size ( ) < 2 | | params . size ( ) > 2 )
{
2017-08-02 19:53:22 +05:30
std : : string msg = " createmultisig nrequired [ \" key \" ,...] \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 "
" 1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses. \n "
" 2. \" keys \" (string, required) A json array of keys which are bitcoin addresses or hex-encoded public keys \n "
" [ \n "
" \" key \" (string) bitcoin address or hex-encoded public key \n "
" ,... \n "
" ] \n "
" \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 "
" \n Create a multisig address from 2 addresses \n "
+ HelpExampleCli ( " createmultisig " , " 2 \" [ \\ \" 16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5 \\ \" , \\ \" 171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV \\ \" ] \" " ) +
" \n As a json rpc call \n "
2014-03-31 09:03:13 +02:00
+ HelpExampleRpc ( " createmultisig " , " 2, \" [ \\ \" 16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5 \\ \" , \\ \" 171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV \\ \" ] \" " )
2013-12-13 16:21:38 +01:00
;
2017-08-02 19:53:22 +05:30
throw std : : runtime_error ( msg ) ;
2013-12-13 16:21:38 +01:00
}
// Construct using pay-to-script-hash:
2014-03-10 22:43:15 -04:00
CScript inner = _createmultisig_redeemScript ( params ) ;
2014-09-24 22:24:46 -04:00
CScriptID innerID ( inner ) ;
2013-12-13 16:21:38 +01:00
CBitcoinAddress address ( innerID ) ;
2015-06-02 12:28:54 +02:00
UniValue result ( UniValue : : VOBJ ) ;
2013-12-13 16:21:38 +01:00
result . push_back ( Pair ( " address " , address . ToString ( ) ) ) ;
result . push_back ( Pair ( " redeemScript " , HexStr ( inner . begin ( ) , inner . end ( ) ) ) ) ;
return result ;
}
2015-05-18 14:02:18 +02:00
UniValue verifymessage ( const UniValue & params , bool fHelp )
2013-12-13 16:23:39 +01:00
{
if ( fHelp | | params . size ( ) ! = 3 )
2017-08-02 19:53:22 +05:30
throw std : : runtime_error (
2013-12-13 16:23:39 +01:00
" verifymessage \" bitcoinaddress \" \" signature \" \" message \" \n "
" \n Verify a signed message \n "
" \n Arguments: \n "
" 1. \" bitcoinaddress \" (string, required) The bitcoin address to use for the signature. \n "
" 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 "
+ HelpExampleCli ( " signmessage " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \" \" my message \" " ) +
" \n Verify the signature \n "
+ HelpExampleCli ( " verifymessage " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \" \" signature \" \" my message \" " ) +
" \n As json rpc \n "
+ HelpExampleRpc ( " verifymessage " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \" , \" signature \" , \" my message \" " )
) ;
2014-10-19 04:46:17 -04:00
LOCK ( cs_main ) ;
2017-08-02 19:53:22 +05:30
std : : string strAddress = params [ 0 ] . get_str ( ) ;
std : : string strSign = params [ 1 ] . get_str ( ) ;
std : : string strMessage = params [ 2 ] . get_str ( ) ;
2013-12-13 16:23:39 +01:00
CBitcoinAddress addr ( strAddress ) ;
if ( ! addr . IsValid ( ) )
throw JSONRPCError ( RPC_TYPE_ERROR , " Invalid address " ) ;
CKeyID keyID ;
if ( ! addr . GetKeyID ( keyID ) )
throw JSONRPCError ( RPC_TYPE_ERROR , " Address does not refer to key " ) ;
bool fInvalid = false ;
2017-08-02 19:53:22 +05:30
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 ;
2021-04-19 11:58:00 +02:00
if ( ! pubkey . recoverCompact ( ss . finalizeHash ( ) , vchSig ) )
2013-12-13 16:23:39 +01:00
return false ;
2021-04-19 11:58:00 +02:00
return ( pubkey . getKeyId ( ) = = keyID ) ;
2013-12-13 16:23:39 +01:00
}
2014-11-12 18:59:41 -05:00
2015-05-18 14:02:18 +02:00
UniValue setmocktime ( const UniValue & params , bool fHelp )
2014-11-12 18:59:41 -05:00
{
if ( fHelp | | params . size ( ) ! = 1 )
2017-08-02 19:53:22 +05:30
throw std : : runtime_error (
2014-11-12 18:59:41 -05: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-08-02 19:53:22 +05:30
throw std : : runtime_error ( " setmocktime for regression testing (-regtest mode) only " ) ;
2014-11-12 18:59:41 -05:00
2015-06-19 10:42:39 -04:00
// cs_vNodes is locked and node send/receive times are updated
// atomically with the time change to prevent peers from being
// disconnected because we think we haven't communicated with them
// in a long time.
LOCK2 ( cs_main , cs_vNodes ) ;
2014-10-19 04:46:17 -04:00
2015-05-10 13:35:44 +02:00
RPCTypeCheck ( params , boost : : assign : : list_of ( UniValue : : VNUM ) ) ;
2014-11-12 18:59:41 -05:00
SetMockTime ( params [ 0 ] . get_int64 ( ) ) ;
2015-06-19 10:42:39 -04:00
uint64_t t = GetTime ( ) ;
BOOST_FOREACH ( CNode * pnode , vNodes ) {
pnode - > nLastSend = pnode - > nLastRecv = t ;
}
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2014-11-12 18:59:41 -05:00
}
2016-05-06 14:35:21 +01:00
UniValue createaddress ( const UniValue & params , bool fHelp )
{
if ( fHelp | | params . size ( ) ! = 0 )
2017-08-02 19:53:22 +05:30
throw std : : runtime_error (
2016-05-06 14:35:21 +01:00
" createaddress \n "
" \n Creates a new address and returns the public and private keys, after which the server immediately forgets the address and keys \n "
" \n Result: \n "
" { \n "
" \" address \" : \" bitcoinaddress \" , (string) The bitcoin address \n "
2016-11-10 12:44:36 +01:00
" \" scriptPubKey \" : \" hex \" , (string) The byte-sequence to use pay to address \n "
2016-05-06 14:35:21 +01:00
" \" pubkey \" : \" hex \" , (string) The raw (hex encoded) pubkey \n "
2016-11-10 12:44:36 +01:00
" \" private \" : \" hex \" , (string) The base58 encoded private key \n "
2016-05-06 14:35:21 +01:00
" } \n "
) ;
CKey key ;
2018-11-13 12:33:34 +01:00
key . MakeNewKey ( ) ;
2016-05-06 14:35:21 +01:00
// return all useful descriptions of key
UniValue ret ( UniValue : : VOBJ ) ;
2016-11-10 12:44:36 +01:00
const CPubKey pubkey = key . GetPubKey ( ) ;
2021-04-19 11:58:00 +02:00
const CKeyID pubKeyId = pubkey . getKeyId ( ) ;
2016-11-10 12:44:36 +01:00
ret . push_back ( Pair ( " address " , CBitcoinAddress ( pubKeyId ) . ToString ( ) ) ) ;
const CScript scriptPubKey = GetScriptForDestination ( pubKeyId ) ;
ret . push_back ( Pair ( " scriptPubKey " , HexStr ( scriptPubKey ) ) ) ;
ret . push_back ( Pair ( " pubkey " , HexStr ( pubkey . begin ( ) , pubkey . end ( ) ) ) ) ;
2016-05-06 14:35:21 +01:00
ret . push_back ( Pair ( " private " , CBitcoinSecret ( key ) . ToString ( ) ) ) ;
return ret ;
}