2012-08-21 16:38:57 +02:00
// Copyright (c) 2010 Satoshi Nakamoto
2016-10-16 18:32:36 +02:00
// Copyright (c) 2009-2016 The Bitcoin Core developers
2014-11-20 03:19:29 +01:00
// Distributed under the MIT software license, see the accompanying
2012-08-21 16:38:57 +02:00
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2014-10-23 02:05:11 +02:00
# include "amount.h"
2013-04-13 07:13:08 +02:00
# include "base58.h"
2015-07-05 14:17:46 +02:00
# include "chain.h"
2016-10-25 20:27:04 +02:00
# include "consensus/validation.h"
2014-06-24 05:10:24 +02:00
# include "core_io.h"
2012-08-21 16:38:57 +02:00
# include "init.h"
2017-07-17 12:10:23 +02:00
# include "httpserver.h"
2016-12-02 01:06:41 +01:00
# include "validation.h"
2013-04-13 07:13:08 +02:00
# include "net.h"
2016-03-31 23:30:17 +02:00
# include "policy/feerate.h"
2017-02-15 21:23:34 +01:00
# include "policy/fees.h"
2016-12-09 19:45:27 +01:00
# include "policy/policy.h"
2015-12-16 20:57:54 +01:00
# include "policy/rbf.h"
2017-06-27 16:50:44 +02:00
# include "rpc/mining.h"
2016-01-15 01:55:17 +01:00
# include "rpc/server.h"
2016-12-09 19:45:27 +01:00
# include "script/sign.h"
2014-06-19 15:08:37 +02:00
# include "timedata.h"
2013-04-13 07:13:08 +02:00
# include "util.h"
2014-12-01 20:06:45 +01:00
# include "utilmoneystr.h"
2017-02-02 23:33:24 +01:00
# include "wallet/coincontrol.h"
2017-03-03 16:15:47 +01:00
# include "wallet/feebumper.h"
# include "wallet/wallet.h"
# include "wallet/walletdb.h"
2013-04-13 07:13:08 +02:00
# include <stdint.h>
2015-09-04 16:11:34 +02:00
# include <univalue.h>
2012-08-21 16:38:57 +02:00
2017-07-17 12:10:23 +02:00
static const std : : string WALLET_ENDPOINT_BASE = " /wallet/ " ;
2016-10-25 09:45:57 +02:00
CWallet * GetWalletForJSONRPCRequest ( const JSONRPCRequest & request )
{
2017-07-17 12:10:23 +02:00
if ( request . URI . substr ( 0 , WALLET_ENDPOINT_BASE . size ( ) ) = = WALLET_ENDPOINT_BASE ) {
// wallet endpoint was used
std : : string requestedWallet = urlDecode ( request . URI . substr ( WALLET_ENDPOINT_BASE . size ( ) ) ) ;
for ( CWalletRef pwallet : : : vpwallets ) {
if ( pwallet - > GetName ( ) = = requestedWallet ) {
return pwallet ;
}
}
2017-07-17 11:42:30 +02:00
throw JSONRPCError ( RPC_WALLET_NOT_FOUND , " Requested wallet does not exist or is not loaded " ) ;
2017-07-17 12:10:23 +02:00
}
return : : vpwallets . size ( ) = = 1 | | ( request . fHelp & & : : vpwallets . size ( ) > 0 ) ? : : vpwallets [ 0 ] : nullptr ;
2016-10-25 09:45:57 +02:00
}
2012-08-21 16:38:57 +02:00
2016-09-09 07:32:12 +02:00
std : : string HelpRequiringPassphrase ( CWallet * const pwallet )
2012-08-21 16:38:57 +02:00
{
2016-09-09 07:32:12 +02:00
return pwallet & & pwallet - > IsCrypted ( )
2013-10-29 12:29:44 +01:00
? " \n Requires wallet passphrase to be set with walletpassphrase call. "
2012-08-21 16:38:57 +02:00
: " " ;
}
2016-09-09 07:32:12 +02:00
bool EnsureWalletIsAvailable ( CWallet * const pwallet , bool avoidException )
2015-04-12 17:56:44 +02:00
{
2017-07-17 11:42:30 +02:00
if ( pwallet ) return true ;
if ( avoidException ) return false ;
if ( : : vpwallets . empty ( ) ) {
2017-07-26 15:35:17 +02:00
// Note: It isn't currently possible to trigger this error because
// wallet RPC methods aren't registered unless a wallet is loaded. But
// this error is being kept as a precaution, because it's possible in
// the future that wallet RPC methods might get or remain registered
// when no wallets are loaded.
throw JSONRPCError (
RPC_METHOD_NOT_FOUND , " Method not found (wallet method is disabled because no wallet is loaded) " ) ;
2015-04-12 17:56:44 +02:00
}
2017-07-17 11:42:30 +02:00
throw JSONRPCError ( RPC_WALLET_NOT_SPECIFIED ,
" Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path). " ) ;
2015-04-12 17:56:44 +02:00
}
2016-09-09 07:32:12 +02:00
void EnsureWalletIsUnlocked ( CWallet * const pwallet )
2012-08-21 16:38:57 +02:00
{
2016-10-25 10:04:23 +02:00
if ( pwallet - > IsLocked ( ) ) {
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_UNLOCK_NEEDED , " Error: Please enter the wallet passphrase with walletpassphrase first. " ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
}
2015-05-18 14:02:18 +02:00
void WalletTxToJSON ( const CWalletTx & wtx , UniValue & entry )
2012-08-21 16:38:57 +02:00
{
int confirms = wtx . GetDepthInMainChain ( ) ;
entry . push_back ( Pair ( " confirmations " , confirms ) ) ;
2012-06-02 04:33:28 +02:00
if ( wtx . IsCoinBase ( ) )
entry . push_back ( Pair ( " generated " , true ) ) ;
2014-02-12 19:43:07 +01:00
if ( confirms > 0 )
2012-08-21 16:38:57 +02:00
{
entry . push_back ( Pair ( " blockhash " , wtx . hashBlock . GetHex ( ) ) ) ;
entry . push_back ( Pair ( " blockindex " , wtx . nIndex ) ) ;
2014-06-28 23:36:06 +02:00
entry . push_back ( Pair ( " blocktime " , mapBlockIndex [ wtx . hashBlock ] - > GetBlockTime ( ) ) ) ;
2015-11-26 18:42:07 +01:00
} else {
entry . push_back ( Pair ( " trusted " , wtx . IsTrusted ( ) ) ) ;
2012-08-21 16:38:57 +02:00
}
2014-02-14 02:12:51 +01:00
uint256 hash = wtx . GetHash ( ) ;
entry . push_back ( Pair ( " txid " , hash . GetHex ( ) ) ) ;
2015-05-10 14:48:35 +02:00
UniValue conflicts ( UniValue : : VARR ) ;
2017-06-02 03:18:57 +02:00
for ( const uint256 & conflict : wtx . GetConflicts ( ) )
2014-02-14 02:12:51 +01:00
conflicts . push_back ( conflict . GetHex ( ) ) ;
entry . push_back ( Pair ( " walletconflicts " , conflicts ) ) ;
2014-05-06 14:58:43 +02:00
entry . push_back ( Pair ( " time " , wtx . GetTxTime ( ) ) ) ;
2014-05-05 20:08:13 +02:00
entry . push_back ( Pair ( " timereceived " , ( int64_t ) wtx . nTimeReceived ) ) ;
2015-12-16 20:57:54 +01:00
// Add opt-in RBF status
std : : string rbfStatus = " no " ;
if ( confirms < = 0 ) {
LOCK ( mempool . cs ) ;
2016-04-05 14:20:49 +02:00
RBFTransactionState rbfState = IsRBFOptIn ( wtx , mempool ) ;
if ( rbfState = = RBF_TRANSACTIONSTATE_UNKNOWN )
rbfStatus = " unknown " ;
else if ( rbfState = = RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125 )
2015-12-16 20:57:54 +01:00
rbfStatus = " yes " ;
}
entry . push_back ( Pair ( " bip125-replaceable " , rbfStatus ) ) ;
2017-06-02 03:28:42 +02:00
for ( const std : : pair < std : : string , std : : string > & item : wtx . mapValue )
2012-08-21 16:38:57 +02:00
entry . push_back ( Pair ( item . first , item . second ) ) ;
}
2017-01-27 02:33:45 +01:00
std : : string AccountFromValue ( const UniValue & value )
2012-08-21 16:38:57 +02:00
{
2017-01-27 02:33:45 +01:00
std : : string strAccount = value . get_str ( ) ;
2012-08-21 16:38:57 +02:00
if ( strAccount = = " * " )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_INVALID_ACCOUNT_NAME , " Invalid account name " ) ;
2012-08-21 16:38:57 +02:00
return strAccount ;
}
2016-09-22 09:46:41 +02:00
UniValue getnewaddress ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) > 1 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2013-10-29 12:29:44 +01:00
" getnewaddress ( \" account \" ) \n "
" \n Returns a new Bitcoin address for receiving payments. \n "
2014-12-30 15:32:07 +01:00
" If 'account' is specified (DEPRECATED), it is added to the address book \n "
2013-10-29 12:29:44 +01:00
" so payments received with the address will be credited to 'account'. \n "
" \n Arguments: \n "
2015-01-05 21:44:55 +01:00
" 1. \" account \" (string, optional) DEPRECATED. The account name for the address to be linked to. If not provided, the default account \" \" is used. It can also be set to the empty string \" \" to represent the default account. The account does not need to exist, it will be created if there is no account by the given name. \n "
2013-10-29 12:29:44 +01:00
" \n Result: \n "
2016-11-21 14:39:58 +01:00
" \" address \" (string) The new bitcoin address \n "
2013-10-29 12:29:44 +01:00
" \n Examples: \n "
+ HelpExampleCli ( " getnewaddress " , " " )
2014-12-30 15:32:07 +01:00
+ HelpExampleRpc ( " getnewaddress " , " " )
2013-10-29 12:29:44 +01:00
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2012-08-21 16:38:57 +02:00
// Parse the account first so we don't generate a key if there's an error
2017-01-27 02:33:45 +01:00
std : : string strAccount ;
2017-07-10 17:44:39 +02:00
if ( ! request . params [ 0 ] . isNull ( ) )
2016-09-22 09:46:41 +02:00
strAccount = AccountFromValue ( request . params [ 0 ] ) ;
2012-08-21 16:38:57 +02:00
2016-10-25 10:04:23 +02:00
if ( ! pwallet - > IsLocked ( ) ) {
2016-10-25 09:45:57 +02:00
pwallet - > TopUpKeyPool ( ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
// Generate a new key that is added to wallet
CPubKey newKey ;
2016-10-25 10:04:23 +02:00
if ( ! pwallet - > GetKeyFromPool ( newKey ) ) {
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_KEYPOOL_RAN_OUT , " Error: Keypool ran out, please call keypoolrefill first " ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
CKeyID keyID = newKey . GetID ( ) ;
2016-10-25 09:45:57 +02:00
pwallet - > SetAddressBook ( keyID , strAccount , " receive " ) ;
2012-08-21 16:38:57 +02:00
return CBitcoinAddress ( keyID ) . ToString ( ) ;
}
2017-01-27 02:33:45 +01:00
CBitcoinAddress GetAccountAddress ( CWallet * const pwallet , std : : string strAccount , bool bForceNew = false )
2012-08-21 16:38:57 +02:00
{
2016-06-03 08:16:42 +02:00
CPubKey pubKey ;
2016-09-09 07:32:12 +02:00
if ( ! pwallet - > GetAccountPubkey ( pubKey , strAccount , bForceNew ) ) {
2016-06-03 08:16:42 +02:00
throw JSONRPCError ( RPC_WALLET_KEYPOOL_RAN_OUT , " Error: Keypool ran out, please call keypoolrefill first " ) ;
2012-08-21 16:38:57 +02:00
}
2016-06-03 08:16:42 +02:00
return CBitcoinAddress ( pubKey . GetID ( ) ) ;
2012-08-21 16:38:57 +02:00
}
2016-09-22 09:46:41 +02:00
UniValue getaccountaddress ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 1 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2013-10-29 12:29:44 +01:00
" getaccountaddress \" account \" \n "
2014-12-30 15:32:07 +01:00
" \n DEPRECATED. Returns the current Bitcoin address for receiving payments to this account. \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
" 1. \" account \" (string, required) The account name for the address. It can also be set to the empty string \" \" to represent the default account. The account does not need to exist, it will be created and a new address created if there is no account by the given name. \n "
" \n Result: \n "
2016-12-09 18:06:42 +01:00
" \" address \" (string) The account bitcoin address \n "
2013-10-29 12:29:44 +01:00
" \n Examples: \n "
+ HelpExampleCli ( " getaccountaddress " , " " )
+ HelpExampleCli ( " getaccountaddress " , " \" \" " )
+ HelpExampleCli ( " getaccountaddress " , " \" myaccount \" " )
+ HelpExampleRpc ( " getaccountaddress " , " \" myaccount \" " )
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2012-08-21 16:38:57 +02:00
// Parse the account first so we don't generate a key if there's an error
2017-01-27 02:33:45 +01:00
std : : string strAccount = AccountFromValue ( request . params [ 0 ] ) ;
2012-08-21 16:38:57 +02:00
2015-05-18 14:02:18 +02:00
UniValue ret ( UniValue : : VSTR ) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
ret = GetAccountAddress ( pwallet , strAccount ) . ToString ( ) ;
2012-08-21 16:38:57 +02:00
return ret ;
}
2016-09-22 09:46:41 +02:00
UniValue getrawchangeaddress ( const JSONRPCRequest & request )
2013-08-28 22:29:52 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2017-07-10 17:43:17 +02:00
if ( request . fHelp | | request . params . size ( ) > 0 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2013-08-28 22:29:52 +02:00
" getrawchangeaddress \n "
2013-10-29 12:29:44 +01:00
" \n Returns a new Bitcoin address, for receiving change. \n "
" This is for use with raw transactions, NOT normal use. \n "
" \n Result: \n "
" \" address \" (string) The address \n "
" \n Examples: \n "
+ HelpExampleCli ( " getrawchangeaddress " , " " )
+ HelpExampleRpc ( " getrawchangeaddress " , " " )
) ;
2013-08-28 22:29:52 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2016-10-25 10:04:23 +02:00
if ( ! pwallet - > IsLocked ( ) ) {
2016-10-25 09:45:57 +02:00
pwallet - > TopUpKeyPool ( ) ;
2016-10-25 10:04:23 +02:00
}
2013-08-28 22:29:52 +02:00
2016-10-25 09:45:57 +02:00
CReserveKey reservekey ( pwallet ) ;
2013-08-28 22:29:52 +02:00
CPubKey vchPubKey ;
2017-01-10 16:45:30 +01:00
if ( ! reservekey . GetReservedKey ( vchPubKey , true ) )
2014-06-16 14:45:32 +02:00
throw JSONRPCError ( RPC_WALLET_KEYPOOL_RAN_OUT , " Error: Keypool ran out, please call keypoolrefill first " ) ;
2013-08-28 22:29:52 +02:00
reservekey . KeepKey ( ) ;
CKeyID keyID = vchPubKey . GetID ( ) ;
return CBitcoinAddress ( keyID ) . ToString ( ) ;
}
2012-08-21 16:38:57 +02:00
2016-09-22 09:46:41 +02:00
UniValue setaccount ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) < 1 | | request . params . size ( ) > 2 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2016-11-21 14:39:58 +01:00
" setaccount \" address \" \" account \" \n "
2014-12-30 15:32:07 +01:00
" \n DEPRECATED. Sets the account associated with the given address. \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
2016-12-09 18:06:42 +01:00
" 1. \" address \" (string, required) The bitcoin address to be associated with an account. \n "
2013-10-29 12:29:44 +01:00
" 2. \" account \" (string, required) The account to assign the address to. \n "
" \n Examples: \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleCli ( " setaccount " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \" \" tabby \" " )
+ HelpExampleRpc ( " setaccount " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \" , \" tabby \" " )
2013-10-29 12:29:44 +01:00
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2016-09-22 09:46:41 +02:00
CBitcoinAddress address ( request . params [ 0 ] . get_str ( ) ) ;
2012-08-21 16:38:57 +02:00
if ( ! address . IsValid ( ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Invalid Bitcoin address " ) ;
2012-08-21 16:38:57 +02:00
2017-01-27 02:33:45 +01:00
std : : string strAccount ;
2016-09-22 09:46:41 +02:00
if ( request . params . size ( ) > 1 )
strAccount = AccountFromValue ( request . params [ 1 ] ) ;
2012-08-21 16:38:57 +02:00
2014-09-26 00:39:28 +02:00
// Only add the account if the address is yours.
2016-10-25 10:04:23 +02:00
if ( IsMine ( * pwallet , address . Get ( ) ) ) {
2014-09-26 00:39:28 +02:00
// Detect when changing the account of an address that is the 'unused current key' of another account:
2016-10-25 10:04:23 +02:00
if ( pwallet - > mapAddressBook . count ( address . Get ( ) ) ) {
2017-01-27 02:33:45 +01:00
std : : string strOldAccount = pwallet - > mapAddressBook [ address . Get ( ) ] . name ;
2016-10-25 10:04:23 +02:00
if ( address = = GetAccountAddress ( pwallet , strOldAccount ) ) {
2016-10-25 09:45:57 +02:00
GetAccountAddress ( pwallet , strOldAccount , true ) ;
2016-10-25 10:04:23 +02:00
}
2014-09-26 00:39:28 +02:00
}
2016-10-25 09:45:57 +02:00
pwallet - > SetAddressBook ( address . Get ( ) , strAccount , " receive " ) ;
2012-08-21 16:38:57 +02:00
}
2014-09-26 00:39:28 +02:00
else
throw JSONRPCError ( RPC_MISC_ERROR , " setaccount can only be used with own address " ) ;
2012-08-21 16:38:57 +02:00
2014-08-20 21:15:16 +02:00
return NullUniValue ;
2012-08-21 16:38:57 +02:00
}
2016-09-22 09:46:41 +02:00
UniValue getaccount ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 1 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2016-11-21 14:39:58 +01:00
" getaccount \" address \" \n "
2014-12-30 15:32:07 +01:00
" \n DEPRECATED. Returns the account associated with the given address. \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
2016-12-09 18:06:42 +01:00
" 1. \" address \" (string, required) The bitcoin address for account lookup. \n "
2013-10-29 12:29:44 +01:00
" \n Result: \n "
" \" accountname \" (string) the account address \n "
" \n Examples: \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleCli ( " getaccount " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \" " )
+ HelpExampleRpc ( " getaccount " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \" " )
2013-10-29 12:29:44 +01:00
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2016-09-22 09:46:41 +02:00
CBitcoinAddress address ( request . params [ 0 ] . get_str ( ) ) ;
2012-08-21 16:38:57 +02:00
if ( ! address . IsValid ( ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Invalid Bitcoin address " ) ;
2012-08-21 16:38:57 +02:00
2017-01-27 02:33:45 +01:00
std : : string strAccount ;
std : : map < CTxDestination , CAddressBookData > : : iterator mi = pwallet - > mapAddressBook . find ( address . Get ( ) ) ;
2016-10-25 10:04:23 +02:00
if ( mi ! = pwallet - > mapAddressBook . end ( ) & & ! ( * mi ) . second . name . empty ( ) ) {
2013-07-15 07:20:50 +02:00
strAccount = ( * mi ) . second . name ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
return strAccount ;
}
2016-09-22 09:46:41 +02:00
UniValue getaddressesbyaccount ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 1 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2013-10-29 12:29:44 +01:00
" getaddressesbyaccount \" account \" \n "
2014-12-30 15:32:07 +01:00
" \n DEPRECATED. Returns the list of addresses for the given account. \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
2016-12-09 18:06:42 +01:00
" 1. \" account \" (string, required) The account name. \n "
2013-10-29 12:29:44 +01:00
" \n Result: \n "
" [ (json array of string) \n "
2016-12-09 18:06:42 +01:00
" \" address \" (string) a bitcoin address associated with the given account \n "
2013-10-29 12:29:44 +01:00
" ,... \n "
" ] \n "
" \n Examples: \n "
+ HelpExampleCli ( " getaddressesbyaccount " , " \" tabby \" " )
+ HelpExampleRpc ( " getaddressesbyaccount " , " \" tabby \" " )
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2017-01-27 02:33:45 +01:00
std : : string strAccount = AccountFromValue ( request . params [ 0 ] ) ;
2012-08-21 16:38:57 +02:00
// Find all addresses that have the given account
2015-05-10 14:48:35 +02:00
UniValue ret ( UniValue : : VARR ) ;
2016-10-25 10:04:23 +02:00
for ( const std : : pair < CBitcoinAddress , CAddressBookData > & item : pwallet - > mapAddressBook ) {
2012-08-21 16:38:57 +02:00
const CBitcoinAddress & address = item . first ;
2017-01-27 02:33:45 +01:00
const std : : string & strName = item . second . name ;
2012-08-21 16:38:57 +02:00
if ( strName = = strAccount )
ret . push_back ( address . ToString ( ) ) ;
}
return ret ;
}
2017-06-28 22:41:55 +02:00
static void SendMoney ( CWallet * const pwallet , const CTxDestination & address , CAmount nValue , bool fSubtractFeeFromAmount , CWalletTx & wtxNew , const CCoinControl & coin_control )
2014-12-01 20:06:45 +01:00
{
2016-09-09 07:32:12 +02:00
CAmount curBalance = pwallet - > GetBalance ( ) ;
2014-12-09 14:50:01 +01:00
2014-12-01 20:06:45 +01:00
// Check amount
if ( nValue < = 0 )
2014-12-05 17:22:06 +01:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Invalid amount " ) ;
2014-12-01 20:06:45 +01:00
2014-12-09 14:50:01 +01:00
if ( nValue > curBalance )
2014-12-01 20:06:45 +01:00
throw JSONRPCError ( RPC_WALLET_INSUFFICIENT_FUNDS , " Insufficient funds " ) ;
2016-10-25 10:04:23 +02:00
if ( pwallet - > GetBroadcastTransactions ( ) & & ! g_connman ) {
2016-05-25 02:56:17 +02:00
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
2016-10-25 10:04:23 +02:00
}
2016-05-25 02:56:17 +02:00
2014-12-01 20:06:45 +01:00
// Parse Bitcoin address
CScript scriptPubKey = GetScriptForDestination ( address ) ;
// Create and send the transaction
2016-09-09 07:32:12 +02:00
CReserveKey reservekey ( pwallet ) ;
2014-12-01 20:06:45 +01:00
CAmount nFeeRequired ;
2014-12-09 14:50:01 +01:00
std : : string strError ;
2017-01-27 02:33:45 +01:00
std : : vector < CRecipient > vecSend ;
2014-07-23 14:34:36 +02:00
int nChangePosRet = - 1 ;
CRecipient recipient = { scriptPubKey , nValue , fSubtractFeeFromAmount } ;
vecSend . push_back ( recipient ) ;
2017-06-14 21:15:40 +02:00
if ( ! pwallet - > CreateTransaction ( vecSend , wtxNew , reservekey , nFeeRequired , nChangePosRet , strError , coin_control ) ) {
2016-11-15 17:31:40 +01:00
if ( ! fSubtractFeeFromAmount & & nValue + nFeeRequired > curBalance )
2016-10-26 11:57:05 +02:00
strError = strprintf ( " Error: This transaction requires a transaction fee of at least %s " , FormatMoney ( nFeeRequired ) ) ;
2014-07-23 14:34:36 +02:00
throw JSONRPCError ( RPC_WALLET_ERROR , strError ) ;
2014-12-01 20:06:45 +01:00
}
2016-10-25 20:27:04 +02:00
CValidationState state ;
2016-09-09 07:32:12 +02:00
if ( ! pwallet - > CommitTransaction ( wtxNew , reservekey , g_connman . get ( ) , state ) ) {
2016-10-25 20:27:04 +02:00
strError = strprintf ( " Error: The transaction was rejected! Reason given: %s " , state . GetRejectReason ( ) ) ;
throw JSONRPCError ( RPC_WALLET_ERROR , strError ) ;
}
2014-12-01 20:06:45 +01:00
}
2016-09-22 09:46:41 +02:00
UniValue sendtoaddress ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2017-06-14 21:15:40 +02:00
if ( request . fHelp | | request . params . size ( ) < 2 | | request . params . size ( ) > 8 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2017-06-14 21:15:40 +02:00
" sendtoaddress \" address \" amount ( \" comment \" \" comment_to \" subtractfeefromamount replaceable conf_target \" estimate_mode \" ) \n "
2016-01-13 11:43:07 +01:00
" \n Send an amount to a given address. \n "
2016-10-25 09:45:57 +02:00
+ HelpRequiringPassphrase ( pwallet ) +
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
2016-12-09 18:06:42 +01:00
" 1. \" address \" (string, required) The bitcoin address to send to. \n "
" 2. \" amount \" (numeric or string, required) The amount in " + CURRENCY_UNIT + " to send. eg 0.1 \n "
" 3. \" comment \" (string, optional) A comment used to store what the transaction is for. \n "
2013-10-29 12:29:44 +01:00
" This is not part of the transaction, just kept in your wallet. \n "
2016-12-09 18:06:42 +01:00
" 4. \" comment_to \" (string, optional) A comment to store the name of the person or organization \n "
2013-10-29 12:29:44 +01:00
" to which you're sending the transaction. This is not part of the \n "
" transaction, just kept in your wallet. \n "
2014-07-23 14:34:36 +02:00
" 5. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent. \n "
" The recipient will receive less bitcoins than you enter in the amount field. \n "
2017-06-14 21:15:40 +02:00
" 6. replaceable (boolean, optional) Allow this transaction to be replaced by a transaction with higher fees via BIP 125 \n "
" 7. conf_target (numeric, optional) Confirmation target (in blocks) \n "
" 8. \" estimate_mode \" (string, optional, default=UNSET) The fee estimate mode, must be one of: \n "
" \" UNSET \" \n "
" \" ECONOMICAL \" \n "
" \" CONSERVATIVE \" \n "
2013-10-29 12:29:44 +01:00
" \n Result: \n "
2016-12-09 18:06:42 +01:00
" \" txid \" (string) The transaction id. \n "
2013-10-29 12:29:44 +01:00
" \n Examples: \n "
+ HelpExampleCli ( " sendtoaddress " , " \" 1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd \" 0.1 " )
+ HelpExampleCli ( " sendtoaddress " , " \" 1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd \" 0.1 \" donation \" \" seans outpost \" " )
2014-07-23 14:34:36 +02:00
+ HelpExampleCli ( " sendtoaddress " , " \" 1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd \" 0.1 \" \" \" \" true " )
2013-10-29 12:29:44 +01:00
+ HelpExampleRpc ( " sendtoaddress " , " \" 1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd \" , 0.1, \" donation \" , \" seans outpost \" " )
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2016-09-22 09:46:41 +02:00
CBitcoinAddress address ( request . params [ 0 ] . get_str ( ) ) ;
2012-08-21 16:38:57 +02:00
if ( ! address . IsValid ( ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Invalid Bitcoin address " ) ;
2012-08-21 16:38:57 +02:00
// Amount
2016-09-22 09:46:41 +02:00
CAmount nAmount = AmountFromValue ( request . params [ 1 ] ) ;
2015-06-06 09:41:12 +02:00
if ( nAmount < = 0 )
throw JSONRPCError ( RPC_TYPE_ERROR , " Invalid amount for send " ) ;
2012-08-21 16:38:57 +02:00
// Wallet comments
CWalletTx wtx ;
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 2 ] . isNull ( ) & & ! request . params [ 2 ] . get_str ( ) . empty ( ) )
2016-09-22 09:46:41 +02:00
wtx . mapValue [ " comment " ] = request . params [ 2 ] . get_str ( ) ;
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 3 ] . isNull ( ) & & ! request . params [ 3 ] . get_str ( ) . empty ( ) )
2016-09-22 09:46:41 +02:00
wtx . mapValue [ " to " ] = request . params [ 3 ] . get_str ( ) ;
2012-08-21 16:38:57 +02:00
2014-07-23 14:34:36 +02:00
bool fSubtractFeeFromAmount = false ;
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 4 ] . isNull ( ) ) {
2016-09-22 09:46:41 +02:00
fSubtractFeeFromAmount = request . params [ 4 ] . get_bool ( ) ;
2017-06-14 21:15:40 +02:00
}
CCoinControl coin_control ;
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 5 ] . isNull ( ) ) {
2017-06-14 21:15:40 +02:00
coin_control . signalRbf = request . params [ 5 ] . get_bool ( ) ;
}
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 6 ] . isNull ( ) ) {
2017-07-12 20:42:57 +02:00
coin_control . m_confirm_target = ParseConfirmTarget ( request . params [ 6 ] ) ;
2017-06-14 21:15:40 +02:00
}
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 7 ] . isNull ( ) ) {
2017-06-14 21:15:40 +02:00
if ( ! FeeModeFromString ( request . params [ 7 ] . get_str ( ) , coin_control . m_fee_mode ) ) {
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Invalid estimate_mode parameter " ) ;
}
}
2014-07-23 14:34:36 +02:00
2016-10-25 09:45:57 +02:00
EnsureWalletIsUnlocked ( pwallet ) ;
2012-08-21 16:38:57 +02:00
2017-06-28 22:41:55 +02:00
SendMoney ( pwallet , address . Get ( ) , nAmount , fSubtractFeeFromAmount , wtx , coin_control ) ;
2012-08-21 16:38:57 +02:00
return wtx . GetHash ( ) . GetHex ( ) ;
}
2016-09-22 09:46:41 +02:00
UniValue listaddressgroupings ( const JSONRPCRequest & request )
2012-08-01 18:48:42 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2017-07-10 17:43:17 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 0 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2012-08-20 19:43:33 +02:00
" listaddressgroupings \n "
2013-10-29 12:29:44 +01:00
" \n Lists groups of addresses which have had their common ownership \n "
2012-08-20 19:43:33 +02:00
" made public by common use as inputs or as the resulting change \n "
2013-10-29 12:29:44 +01:00
" in past transactions \n "
" \n Result: \n "
" [ \n "
" [ \n "
" [ \n "
2017-01-11 14:29:46 +01:00
" \" address \" , (string) The bitcoin address \n "
2015-08-01 21:15:23 +02:00
" amount, (numeric) The amount in " + CURRENCY_UNIT + " \n "
2017-01-11 14:29:46 +01:00
" \" account \" (string, optional) DEPRECATED. The account \n "
2013-10-29 12:29:44 +01:00
" ] \n "
" ,... \n "
" ] \n "
" ,... \n "
" ] \n "
" \n Examples: \n "
+ HelpExampleCli ( " listaddressgroupings " , " " )
+ HelpExampleRpc ( " listaddressgroupings " , " " )
) ;
2012-08-01 18:48:42 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2015-05-10 14:48:35 +02:00
UniValue jsonGroupings ( UniValue : : VARR ) ;
2017-01-27 02:33:45 +01:00
std : : map < CTxDestination , CAmount > balances = pwallet - > GetAddressBalances ( ) ;
for ( std : : set < CTxDestination > grouping : pwallet - > GetAddressGroupings ( ) ) {
2015-05-10 14:48:35 +02:00
UniValue jsonGrouping ( UniValue : : VARR ) ;
2017-06-02 03:18:57 +02:00
for ( CTxDestination address : grouping )
2012-08-01 18:48:42 +02:00
{
2015-05-10 14:48:35 +02:00
UniValue addressInfo ( UniValue : : VARR ) ;
2012-08-20 19:43:33 +02:00
addressInfo . push_back ( CBitcoinAddress ( address ) . ToString ( ) ) ;
2012-08-01 18:48:42 +02:00
addressInfo . push_back ( ValueFromAmount ( balances [ address ] ) ) ;
{
2016-10-25 10:04:23 +02:00
if ( pwallet - > mapAddressBook . find ( CBitcoinAddress ( address ) . Get ( ) ) ! = pwallet - > mapAddressBook . end ( ) ) {
2016-10-25 09:45:57 +02:00
addressInfo . push_back ( pwallet - > mapAddressBook . find ( CBitcoinAddress ( address ) . Get ( ) ) - > second . name ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-01 18:48:42 +02:00
}
jsonGrouping . push_back ( addressInfo ) ;
}
jsonGroupings . push_back ( jsonGrouping ) ;
}
return jsonGroupings ;
}
2016-09-22 09:46:41 +02:00
UniValue signmessage ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 2 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2016-11-21 14:39:58 +01:00
" signmessage \" address \" \" message \" \n "
2013-10-29 12:29:44 +01:00
" \n Sign a message with the private key of an address "
2016-10-25 09:45:57 +02:00
+ HelpRequiringPassphrase ( pwallet ) + " \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
2016-12-09 18:06:42 +01:00
" 1. \" address \" (string, required) The bitcoin address to use for the private key. \n "
2013-10-29 12:29:44 +01:00
" 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 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-10-29 12:29:44 +01:00
" \n Verify the signature \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleCli ( " verifymessage " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \" \" signature \" \" my message \" " ) +
2013-10-29 12:29:44 +01:00
" \n As json rpc \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleRpc ( " signmessage " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \" , \" my message \" " )
2013-10-29 12:29:44 +01:00
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2016-10-25 09:45:57 +02:00
EnsureWalletIsUnlocked ( pwallet ) ;
2012-08-21 16:38:57 +02:00
2017-01-27 02:33:45 +01:00
std : : string strAddress = request . params [ 0 ] . get_str ( ) ;
std : : string strMessage = request . params [ 1 ] . get_str ( ) ;
2012-08-21 16:38:57 +02:00
CBitcoinAddress addr ( strAddress ) ;
if ( ! addr . IsValid ( ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_TYPE_ERROR , " Invalid address " ) ;
2012-08-21 16:38:57 +02:00
CKeyID keyID ;
if ( ! addr . GetKeyID ( keyID ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_TYPE_ERROR , " Address does not refer to key " ) ;
2012-08-21 16:38:57 +02:00
CKey key ;
2016-10-25 10:04:23 +02:00
if ( ! pwallet - > GetKey ( keyID , key ) ) {
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_ERROR , " Private key not available " ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
2012-10-19 23:13:44 +02:00
CHashWriter ss ( SER_GETHASH , 0 ) ;
2012-08-21 16:38:57 +02:00
ss < < strMessageMagic ;
ss < < strMessage ;
2017-01-27 02:33:45 +01:00
std : : vector < unsigned char > vchSig ;
2012-10-19 23:13:44 +02:00
if ( ! key . SignCompact ( ss . GetHash ( ) , vchSig ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Sign failed " ) ;
2012-08-21 16:38:57 +02:00
return EncodeBase64 ( & vchSig [ 0 ] , vchSig . size ( ) ) ;
}
2016-09-22 09:46:41 +02:00
UniValue getreceivedbyaddress ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) < 1 | | request . params . size ( ) > 2 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2016-11-21 14:39:58 +01:00
" getreceivedbyaddress \" address \" ( minconf ) \n "
" \n Returns the total amount received by the given address in transactions with at least minconf confirmations. \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
2016-12-09 18:06:42 +01:00
" 1. \" address \" (string, required) The bitcoin address for transactions. \n "
2013-10-29 12:29:44 +01:00
" 2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times. \n "
" \n Result: \n "
2015-08-01 21:15:23 +02:00
" amount (numeric) The total amount in " + CURRENCY_UNIT + " received at this address. \n "
2013-10-29 12:29:44 +01:00
" \n Examples: \n "
" \n The amount from transactions with at least 1 confirmation \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleCli ( " getreceivedbyaddress " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \" " ) +
2013-10-29 12:29:44 +01:00
" \n The amount including unconfirmed transactions, zero confirmations \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleCli ( " getreceivedbyaddress " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \" 0 " ) +
2017-07-19 22:50:26 +02:00
" \n The amount with at least 6 confirmations \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleCli ( " getreceivedbyaddress " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \" 6 " ) +
2013-10-29 12:29:44 +01:00
" \n As a json rpc call \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleRpc ( " getreceivedbyaddress " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \" , 6 " )
2013-10-29 12:29:44 +01:00
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2012-08-21 16:38:57 +02:00
// Bitcoin address
2016-09-22 09:46:41 +02:00
CBitcoinAddress address = CBitcoinAddress ( request . params [ 0 ] . get_str ( ) ) ;
2012-08-21 16:38:57 +02:00
if ( ! address . IsValid ( ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Invalid Bitcoin address " ) ;
2014-09-11 19:15:29 +02:00
CScript scriptPubKey = GetScriptForDestination ( address . Get ( ) ) ;
2016-10-25 10:04:23 +02:00
if ( ! IsMine ( * pwallet , scriptPubKey ) ) {
2016-07-08 12:01:39 +02:00
return ValueFromAmount ( 0 ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
// Minimum confirmations
int nMinDepth = 1 ;
2017-07-10 17:44:39 +02:00
if ( ! request . params [ 1 ] . isNull ( ) )
2016-09-22 09:46:41 +02:00
nMinDepth = request . params [ 1 ] . get_int ( ) ;
2012-08-21 16:38:57 +02:00
// Tally
2014-04-23 00:46:19 +02:00
CAmount nAmount = 0 ;
2016-10-25 10:04:23 +02:00
for ( const std : : pair < uint256 , CWalletTx > & pairWtx : pwallet - > mapWallet ) {
const CWalletTx & wtx = pairWtx . second ;
2016-11-12 01:54:51 +01:00
if ( wtx . IsCoinBase ( ) | | ! CheckFinalTx ( * wtx . tx ) )
2012-08-21 16:38:57 +02:00
continue ;
2017-06-02 03:18:57 +02:00
for ( const CTxOut & txout : wtx . tx - > vout )
2012-08-21 16:38:57 +02:00
if ( txout . scriptPubKey = = scriptPubKey )
if ( wtx . GetDepthInMainChain ( ) > = nMinDepth )
nAmount + = txout . nValue ;
}
return ValueFromAmount ( nAmount ) ;
}
2016-09-22 09:46:41 +02:00
UniValue getreceivedbyaccount ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) < 1 | | request . params . size ( ) > 2 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2013-10-29 12:29:44 +01:00
" getreceivedbyaccount \" account \" ( minconf ) \n "
2014-12-30 15:32:07 +01:00
" \n DEPRECATED. Returns the total amount received by addresses with <account> in transactions with at least [minconf] confirmations. \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
" 1. \" account \" (string, required) The selected account, may be the default account using \" \" . \n "
" 2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times. \n "
" \n Result: \n "
2015-08-01 21:15:23 +02:00
" amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account. \n "
2013-10-29 12:29:44 +01:00
" \n Examples: \n "
" \n Amount received by the default account with at least 1 confirmation \n "
+ HelpExampleCli ( " getreceivedbyaccount " , " \" \" " ) +
" \n Amount received at the tabby account including unconfirmed amounts with zero confirmations \n "
+ HelpExampleCli ( " getreceivedbyaccount " , " \" tabby \" 0 " ) +
2017-07-19 22:50:26 +02:00
" \n The amount with at least 6 confirmations \n "
2013-10-29 12:29:44 +01:00
+ HelpExampleCli ( " getreceivedbyaccount " , " \" tabby \" 6 " ) +
" \n As a json rpc call \n "
+ HelpExampleRpc ( " getreceivedbyaccount " , " \" tabby \" , 6 " )
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2012-08-21 16:38:57 +02:00
// Minimum confirmations
int nMinDepth = 1 ;
2017-07-10 17:44:39 +02:00
if ( ! request . params [ 1 ] . isNull ( ) )
2016-09-22 09:46:41 +02:00
nMinDepth = request . params [ 1 ] . get_int ( ) ;
2012-08-21 16:38:57 +02:00
// Get the set of pub keys assigned to account
2017-01-27 02:33:45 +01:00
std : : string strAccount = AccountFromValue ( request . params [ 0 ] ) ;
std : : set < CTxDestination > setAddress = pwallet - > GetAccountAddresses ( strAccount ) ;
2012-08-21 16:38:57 +02:00
// Tally
2014-04-23 00:46:19 +02:00
CAmount nAmount = 0 ;
2016-10-25 10:04:23 +02:00
for ( const std : : pair < uint256 , CWalletTx > & pairWtx : pwallet - > mapWallet ) {
const CWalletTx & wtx = pairWtx . second ;
2016-11-12 01:54:51 +01:00
if ( wtx . IsCoinBase ( ) | | ! CheckFinalTx ( * wtx . tx ) )
2012-08-21 16:38:57 +02:00
continue ;
2017-06-02 03:18:57 +02:00
for ( const CTxOut & txout : wtx . tx - > vout )
2012-08-21 16:38:57 +02:00
{
CTxDestination address ;
2016-10-25 10:04:23 +02:00
if ( ExtractDestination ( txout . scriptPubKey , address ) & & IsMine ( * pwallet , address ) & & setAddress . count ( address ) ) {
2012-08-21 16:38:57 +02:00
if ( wtx . GetDepthInMainChain ( ) > = nMinDepth )
nAmount + = txout . nValue ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
}
}
2016-07-08 12:01:39 +02:00
return ValueFromAmount ( nAmount ) ;
2012-08-21 16:38:57 +02:00
}
2016-09-22 09:46:41 +02:00
UniValue getbalance ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) > 3 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2016-11-21 14:32:36 +01:00
" getbalance ( \" account \" minconf include_watchonly ) \n "
2013-10-29 12:29:44 +01:00
" \n If account is not specified, returns the server's total available balance. \n "
2014-12-30 15:32:07 +01:00
" If account is specified (DEPRECATED), returns the balance in the account. \n "
2013-10-29 12:29:44 +01:00
" Note that the account \" \" is not the same as leaving the parameter out. \n "
" The server total may be different to the balance in the default \" \" account. \n "
" \n Arguments: \n "
2017-01-23 15:54:11 +01:00
" 1. \" account \" (string, optional) DEPRECATED. The account string may be given as a \n "
" specific account name to find the balance associated with wallet keys in \n "
" a named account, or as the empty string ( \" \" ) to find the balance \n "
" associated with wallet keys not in any named account, or as \" * \" to find \n "
" the balance associated with all wallet keys regardless of account. \n "
" When this option is specified, it calculates the balance in a different \n "
" way than when it is not specified, and which can count spends twice when \n "
" there are conflicting pending transactions (such as those created by \n "
" the bumpfee command), temporarily resulting in low or even negative \n "
" balances. In general, account balance calculation is not considered \n "
" reliable and has resulted in confusing outcomes, so it is recommended to \n "
" avoid passing this argument. \n "
" 2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times. \n "
2017-01-11 14:29:46 +01:00
" 3. include_watchonly (bool, optional, default=false) Also include balance in watch-only addresses (see 'importaddress') \n "
2013-10-29 12:29:44 +01:00
" \n Result: \n "
2015-08-01 21:15:23 +02:00
" amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account. \n "
2013-10-29 12:29:44 +01:00
" \n Examples: \n "
2017-07-12 20:40:02 +02:00
" \n The total amount in the wallet with 1 or more confirmations \n "
2013-10-29 12:29:44 +01:00
+ HelpExampleCli ( " getbalance " , " " ) +
2017-07-12 20:40:02 +02:00
" \n The total amount in the wallet at least 6 blocks confirmed \n "
2014-01-29 13:41:34 +01:00
+ HelpExampleCli ( " getbalance " , " \" * \" 6 " ) +
2013-10-29 12:29:44 +01:00
" \n As a json rpc call \n "
2014-12-30 15:32:07 +01:00
+ HelpExampleRpc ( " getbalance " , " \" * \" , 6 " )
2013-10-29 12:29:44 +01:00
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2016-09-22 09:46:41 +02:00
if ( request . params . size ( ) = = 0 )
2016-10-25 09:45:57 +02:00
return ValueFromAmount ( pwallet - > GetBalance ( ) ) ;
2012-08-21 16:38:57 +02:00
2017-05-05 02:20:02 +02:00
const std : : string & account_param = request . params [ 0 ] . get_str ( ) ;
const std : : string * account = account_param ! = " * " ? & account_param : nullptr ;
2017-01-23 15:58:42 +01:00
2012-08-21 16:38:57 +02:00
int nMinDepth = 1 ;
2017-07-10 17:44:39 +02:00
if ( ! request . params [ 1 ] . isNull ( ) )
2016-09-22 09:46:41 +02:00
nMinDepth = request . params [ 1 ] . get_int ( ) ;
2014-07-01 11:00:22 +02:00
isminefilter filter = ISMINE_SPENDABLE ;
2017-07-10 17:44:39 +02:00
if ( ! request . params [ 2 ] . isNull ( ) )
2016-09-22 09:46:41 +02:00
if ( request . params [ 2 ] . get_bool ( ) )
2014-07-01 11:00:22 +02:00
filter = filter | ISMINE_WATCH_ONLY ;
2012-08-21 16:38:57 +02:00
2017-01-23 17:04:19 +01:00
return ValueFromAmount ( pwallet - > GetLegacyBalance ( filter , nMinDepth , account ) ) ;
2012-08-21 16:38:57 +02:00
}
2016-09-22 09:46:41 +02:00
UniValue getunconfirmedbalance ( const JSONRPCRequest & request )
2013-11-24 12:48:52 +01:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) > 0 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2013-11-24 12:48:52 +01:00
" getunconfirmedbalance \n "
" Returns the server's total unconfirmed balance \n " ) ;
2014-10-19 10:46:17 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2016-10-25 09:45:57 +02:00
return ValueFromAmount ( pwallet - > GetUnconfirmedBalance ( ) ) ;
2013-11-24 12:48:52 +01:00
}
2012-08-21 16:38:57 +02:00
2016-09-22 09:46:41 +02:00
UniValue movecmd ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) < 3 | | request . params . size ( ) > 5 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2013-10-29 12:29:44 +01:00
" move \" fromaccount \" \" toaccount \" amount ( minconf \" comment \" ) \n "
2014-12-30 15:32:07 +01:00
" \n DEPRECATED. Move a specified amount from one account in your wallet to another. \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
" 1. \" fromaccount \" (string, required) The name of the account to move funds from. May be the default account using \" \" . \n "
" 2. \" toaccount \" (string, required) The name of the account to move funds to. May be the default account using \" \" . \n "
2015-08-01 21:15:23 +02:00
" 3. amount (numeric) Quantity of " + CURRENCY_UNIT + " to move between accounts. \n "
2017-01-04 17:38:40 +01:00
" 4. (dummy) (numeric, optional) Ignored. Remains for backward compatibility. \n "
2015-08-01 21:15:23 +02:00
" 5. \" comment \" (string, optional) An optional comment, stored in the wallet only. \n "
2013-10-29 12:29:44 +01:00
" \n Result: \n "
2015-08-09 01:17:27 +02:00
" true|false (boolean) true if successful. \n "
2013-10-29 12:29:44 +01:00
" \n Examples: \n "
2015-08-01 21:15:23 +02:00
" \n Move 0.01 " + CURRENCY_UNIT + " from the default account to the account named tabby \n "
2013-10-29 12:29:44 +01:00
+ HelpExampleCli ( " move " , " \" \" \" tabby \" 0.01 " ) +
2015-08-01 21:15:23 +02:00
" \n Move 0.01 " + CURRENCY_UNIT + " timotei to akiko with a comment and funds have 6 confirmations \n "
2013-10-29 12:29:44 +01:00
+ HelpExampleCli ( " move " , " \" timotei \" \" akiko \" 0.01 6 \" happy birthday! \" " ) +
" \n As a json rpc call \n "
+ HelpExampleRpc ( " move " , " \" timotei \" , \" akiko \" , 0.01, 6, \" happy birthday! \" " )
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2017-01-27 02:33:45 +01:00
std : : string strFrom = AccountFromValue ( request . params [ 0 ] ) ;
std : : string strTo = AccountFromValue ( request . params [ 1 ] ) ;
2016-09-22 09:46:41 +02:00
CAmount nAmount = AmountFromValue ( request . params [ 2 ] ) ;
2015-06-06 09:41:12 +02:00
if ( nAmount < = 0 )
throw JSONRPCError ( RPC_TYPE_ERROR , " Invalid amount for send " ) ;
2016-09-22 09:46:41 +02:00
if ( request . params . size ( ) > 3 )
2012-08-21 16:38:57 +02:00
// unused parameter, used to be nMinDepth, keep type-checking it though
2016-09-22 09:46:41 +02:00
( void ) request . params [ 3 ] . get_int ( ) ;
2017-01-27 02:33:45 +01:00
std : : string strComment ;
2016-09-22 09:46:41 +02:00
if ( request . params . size ( ) > 4 )
strComment = request . params [ 4 ] . get_str ( ) ;
2012-08-21 16:38:57 +02:00
2016-10-25 10:04:23 +02:00
if ( ! pwallet - > AccountMove ( strFrom , strTo , nAmount , strComment ) ) {
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_DATABASE_ERROR , " database error " ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
return true ;
}
2016-09-22 09:46:41 +02:00
UniValue sendfrom ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) < 3 | | request . params . size ( ) > 6 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2016-11-21 14:39:58 +01:00
" sendfrom \" fromaccount \" \" toaddress \" amount ( minconf \" comment \" \" comment_to \" ) \n "
2016-01-13 11:43:07 +01:00
" \n DEPRECATED (use sendtoaddress). Sent an amount from an account to a bitcoin address. "
2016-10-25 09:45:57 +02:00
+ HelpRequiringPassphrase ( pwallet ) + " \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
" 1. \" fromaccount \" (string, required) The name of the account to send funds from. May be the default account using \" \" . \n "
2017-02-23 19:44:12 +01:00
" Specifying an account does not influence coin selection, but it does associate the newly created \n "
" transaction with the account, so the account's balance computation and transaction history can reflect \n "
" the spend. \n "
2016-12-09 18:06:42 +01:00
" 2. \" toaddress \" (string, required) The bitcoin address to send funds to. \n "
2016-01-13 11:43:07 +01:00
" 3. amount (numeric or string, required) The amount in " + CURRENCY_UNIT + " (transaction fee is added on top). \n "
2013-10-29 12:29:44 +01:00
" 4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations. \n "
" 5. \" comment \" (string, optional) A comment used to store what the transaction is for. \n "
" This is not part of the transaction, just kept in your wallet. \n "
2016-11-21 14:32:36 +01:00
" 6. \" comment_to \" (string, optional) An optional comment to store the name of the person or organization \n "
2013-10-29 12:29:44 +01:00
" to which you're sending the transaction. This is not part of the transaction, \n "
" it is just kept in your wallet. \n "
" \n Result: \n "
2016-12-09 18:06:42 +01:00
" \" txid \" (string) The transaction id. \n "
2013-10-29 12:29:44 +01:00
" \n Examples: \n "
2015-08-01 21:15:23 +02:00
" \n Send 0.01 " + CURRENCY_UNIT + " from the default account to the address, must have at least 1 confirmation \n "
2013-10-29 12:29:44 +01:00
+ HelpExampleCli ( " sendfrom " , " \" \" \" 1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd \" 0.01 " ) +
" \n Send 0.01 from the tabby account to the given address, funds must have at least 6 confirmations \n "
+ HelpExampleCli ( " sendfrom " , " \" tabby \" \" 1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd \" 0.01 6 \" donation \" \" seans outpost \" " ) +
" \n As a json rpc call \n "
+ HelpExampleRpc ( " sendfrom " , " \" tabby \" , \" 1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd \" , 0.01, 6, \" donation \" , \" seans outpost \" " )
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2017-01-27 02:33:45 +01:00
std : : string strAccount = AccountFromValue ( request . params [ 0 ] ) ;
2016-09-22 09:46:41 +02:00
CBitcoinAddress address ( request . params [ 1 ] . get_str ( ) ) ;
2012-08-21 16:38:57 +02:00
if ( ! address . IsValid ( ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Invalid Bitcoin address " ) ;
2016-09-22 09:46:41 +02:00
CAmount nAmount = AmountFromValue ( request . params [ 2 ] ) ;
2015-06-06 09:41:12 +02:00
if ( nAmount < = 0 )
throw JSONRPCError ( RPC_TYPE_ERROR , " Invalid amount for send " ) ;
2012-08-21 16:38:57 +02:00
int nMinDepth = 1 ;
2016-09-22 09:46:41 +02:00
if ( request . params . size ( ) > 3 )
nMinDepth = request . params [ 3 ] . get_int ( ) ;
2012-08-21 16:38:57 +02:00
CWalletTx wtx ;
wtx . strFromAccount = strAccount ;
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 4 ] . isNull ( ) & & ! request . params [ 4 ] . get_str ( ) . empty ( ) )
2016-09-22 09:46:41 +02:00
wtx . mapValue [ " comment " ] = request . params [ 4 ] . get_str ( ) ;
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 5 ] . isNull ( ) & & ! request . params [ 5 ] . get_str ( ) . empty ( ) )
2016-09-22 09:46:41 +02:00
wtx . mapValue [ " to " ] = request . params [ 5 ] . get_str ( ) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
EnsureWalletIsUnlocked ( pwallet ) ;
2012-08-21 16:38:57 +02:00
// Check funds
2017-01-23 17:04:19 +01:00
CAmount nBalance = pwallet - > GetLegacyBalance ( ISMINE_SPENDABLE , nMinDepth , & strAccount ) ;
2012-08-21 16:38:57 +02:00
if ( nAmount > nBalance )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_INSUFFICIENT_FUNDS , " Account has insufficient funds " ) ;
2012-08-21 16:38:57 +02:00
2017-06-28 22:41:55 +02:00
CCoinControl no_coin_control ; // This is a deprecated API
SendMoney ( pwallet , address . Get ( ) , nAmount , false , wtx , no_coin_control ) ;
2012-08-21 16:38:57 +02:00
return wtx . GetHash ( ) . GetHex ( ) ;
}
2016-09-22 09:46:41 +02:00
UniValue sendmany ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2017-06-14 21:15:40 +02:00
if ( request . fHelp | | request . params . size ( ) < 2 | | request . params . size ( ) > 8 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2017-06-14 21:15:40 +02:00
" sendmany \" fromaccount \" { \" address \" :amount,...} ( minconf \" comment \" [ \" address \" ,...] replaceable conf_target \" estimate_mode \" ) \n "
2013-10-29 12:29:44 +01:00
" \n Send multiple times. Amounts are double-precision floating point numbers. "
2016-10-25 09:45:57 +02:00
+ HelpRequiringPassphrase ( pwallet ) + " \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
2014-12-30 15:32:07 +01:00
" 1. \" fromaccount \" (string, required) DEPRECATED. The account to send the funds from. Should be \" \" for the default account \n "
2013-10-29 12:29:44 +01:00
" 2. \" amounts \" (string, required) A json object with addresses and amounts \n "
" { \n "
2016-01-13 11:43:07 +01:00
" \" address \" :amount (numeric or string) The bitcoin address is the key, the numeric amount (can be string) in " + CURRENCY_UNIT + " is the value \n "
2013-10-29 12:29:44 +01:00
" ,... \n "
" } \n "
" 3. minconf (numeric, optional, default=1) Only use the balance confirmed at least this many times. \n "
" 4. \" comment \" (string, optional) A comment \n "
2016-11-21 14:32:36 +01:00
" 5. subtractfeefrom (array, optional) A json array with addresses. \n "
2014-07-23 14:34:36 +02:00
" The fee will be equally deducted from the amount of each selected address. \n "
" Those recipients will receive less bitcoins than you enter in their corresponding amount field. \n "
2015-03-05 14:30:15 +01:00
" If no addresses are specified here, the sender pays the fee. \n "
" [ \n "
2016-12-09 18:06:42 +01:00
" \" address \" (string) Subtract fee from this address \n "
2014-07-23 14:34:36 +02:00
" ,... \n "
2015-03-05 14:30:15 +01:00
" ] \n "
2017-06-14 21:15:40 +02:00
" 6. replaceable (boolean, optional) Allow this transaction to be replaced by a transaction with higher fees via BIP 125 \n "
" 7. conf_target (numeric, optional) Confirmation target (in blocks) \n "
" 8. \" estimate_mode \" (string, optional, default=UNSET) The fee estimate mode, must be one of: \n "
" \" UNSET \" \n "
" \" ECONOMICAL \" \n "
" \" CONSERVATIVE \" \n "
" \n Result: \n "
2016-12-09 18:06:42 +01:00
" \" txid \" (string) The transaction id for the send. Only 1 transaction is created regardless of \n "
2014-05-29 18:17:34 +02:00
" the number of addresses. \n "
2013-10-29 12:29:44 +01:00
" \n Examples: \n "
" \n Send two amounts to two different addresses: \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleCli ( " sendmany " , " \" \" \" { \\ \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \\ \" :0.01, \\ \" 1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz \\ \" :0.02} \" " ) +
2013-10-29 12:29:44 +01:00
" \n Send two amounts to two different addresses setting the confirmation and comment: \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleCli ( " sendmany " , " \" \" \" { \\ \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \\ \" :0.01, \\ \" 1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz \\ \" :0.02} \" 6 \" testing \" " ) +
2014-07-23 14:34:36 +02:00
" \n Send two amounts to two different addresses, subtract fee from amount: \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleCli ( " sendmany " , " \" \" \" { \\ \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \\ \" :0.01, \\ \" 1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz \\ \" :0.02} \" 1 \" \" \" [ \\ \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \\ \" , \\ \" 1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz \\ \" ] \" " ) +
2013-10-29 12:29:44 +01:00
" \n As a json rpc call \n "
2017-02-26 14:01:05 +01:00
+ HelpExampleRpc ( " sendmany " , " \" \" , \" { \\ \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX \\ \" :0.01, \\ \" 1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz \\ \" :0.02} \" , 6, \" testing \" " )
2013-10-29 12:29:44 +01:00
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2016-10-25 10:04:23 +02:00
if ( pwallet - > GetBroadcastTransactions ( ) & & ! g_connman ) {
2016-05-25 02:56:17 +02:00
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
2016-10-25 10:04:23 +02:00
}
2016-05-25 02:56:17 +02:00
2017-01-27 02:33:45 +01:00
std : : string strAccount = AccountFromValue ( request . params [ 0 ] ) ;
2016-09-22 09:46:41 +02:00
UniValue sendTo = request . params [ 1 ] . get_obj ( ) ;
2012-08-21 16:38:57 +02:00
int nMinDepth = 1 ;
2017-07-10 17:44:39 +02:00
if ( ! request . params [ 2 ] . isNull ( ) )
2016-09-22 09:46:41 +02:00
nMinDepth = request . params [ 2 ] . get_int ( ) ;
2012-08-21 16:38:57 +02:00
CWalletTx wtx ;
wtx . strFromAccount = strAccount ;
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 3 ] . isNull ( ) & & ! request . params [ 3 ] . get_str ( ) . empty ( ) )
2016-09-22 09:46:41 +02:00
wtx . mapValue [ " comment " ] = request . params [ 3 ] . get_str ( ) ;
2012-08-21 16:38:57 +02:00
2015-05-10 14:48:35 +02:00
UniValue subtractFeeFromAmount ( UniValue : : VARR ) ;
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 4 ] . isNull ( ) )
2016-09-22 09:46:41 +02:00
subtractFeeFromAmount = request . params [ 4 ] . get_array ( ) ;
2014-07-23 14:34:36 +02:00
2017-06-14 21:15:40 +02:00
CCoinControl coin_control ;
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 5 ] . isNull ( ) ) {
2017-06-14 21:15:40 +02:00
coin_control . signalRbf = request . params [ 5 ] . get_bool ( ) ;
}
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 6 ] . isNull ( ) ) {
2017-07-12 20:42:57 +02:00
coin_control . m_confirm_target = ParseConfirmTarget ( request . params [ 6 ] ) ;
2017-06-14 21:15:40 +02:00
}
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 7 ] . isNull ( ) ) {
2017-06-14 21:15:40 +02:00
if ( ! FeeModeFromString ( request . params [ 7 ] . get_str ( ) , coin_control . m_fee_mode ) ) {
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Invalid estimate_mode parameter " ) ;
}
}
2017-01-27 02:33:45 +01:00
std : : set < CBitcoinAddress > setAddress ;
std : : vector < CRecipient > vecSend ;
2012-08-21 16:38:57 +02:00
2014-04-23 00:46:19 +02:00
CAmount totalAmount = 0 ;
2017-01-27 02:33:45 +01:00
std : : vector < std : : string > keys = sendTo . getKeys ( ) ;
2017-06-02 03:18:57 +02:00
for ( const std : : string & name_ : keys )
2012-08-21 16:38:57 +02:00
{
2014-08-20 21:15:16 +02:00
CBitcoinAddress address ( name_ ) ;
2012-08-21 16:38:57 +02:00
if ( ! address . IsValid ( ) )
2017-01-27 02:33:45 +01:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , std : : string ( " Invalid Bitcoin address: " ) + name_ ) ;
2012-08-21 16:38:57 +02:00
if ( setAddress . count ( address ) )
2017-01-27 02:33:45 +01:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , std : : string ( " Invalid parameter, duplicated address: " ) + name_ ) ;
2012-08-21 16:38:57 +02:00
setAddress . insert ( address ) ;
2014-09-11 19:15:29 +02:00
CScript scriptPubKey = GetScriptForDestination ( address . Get ( ) ) ;
2014-08-20 21:15:16 +02:00
CAmount nAmount = AmountFromValue ( sendTo [ name_ ] ) ;
2015-06-06 09:41:12 +02:00
if ( nAmount < = 0 )
throw JSONRPCError ( RPC_TYPE_ERROR , " Invalid amount for send " ) ;
2012-08-21 16:38:57 +02:00
totalAmount + = nAmount ;
2014-07-23 14:34:36 +02:00
bool fSubtractFeeFromAmount = false ;
2015-05-10 13:35:44 +02:00
for ( unsigned int idx = 0 ; idx < subtractFeeFromAmount . size ( ) ; idx + + ) {
2015-05-18 14:02:18 +02:00
const UniValue & addr = subtractFeeFromAmount [ idx ] ;
2015-05-10 13:35:44 +02:00
if ( addr . get_str ( ) = = name_ )
2014-07-23 14:34:36 +02:00
fSubtractFeeFromAmount = true ;
2015-05-10 13:35:44 +02:00
}
2014-07-23 14:34:36 +02:00
CRecipient recipient = { scriptPubKey , nAmount , fSubtractFeeFromAmount } ;
vecSend . push_back ( recipient ) ;
2012-08-21 16:38:57 +02:00
}
2016-10-25 09:45:57 +02:00
EnsureWalletIsUnlocked ( pwallet ) ;
2012-08-21 16:38:57 +02:00
// Check funds
2017-01-23 17:04:19 +01:00
CAmount nBalance = pwallet - > GetLegacyBalance ( ISMINE_SPENDABLE , nMinDepth , & strAccount ) ;
2012-08-21 16:38:57 +02:00
if ( totalAmount > nBalance )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_INSUFFICIENT_FUNDS , " Account has insufficient funds " ) ;
2012-08-21 16:38:57 +02:00
// Send
2016-10-25 09:45:57 +02:00
CReserveKey keyChange ( pwallet ) ;
2014-04-23 00:46:19 +02:00
CAmount nFeeRequired = 0 ;
2014-07-23 14:34:36 +02:00
int nChangePosRet = - 1 ;
2017-01-27 02:33:45 +01:00
std : : string strFailReason ;
2017-06-28 22:41:55 +02:00
bool fCreated = pwallet - > CreateTransaction ( vecSend , wtx , keyChange , nFeeRequired , nChangePosRet , strFailReason , coin_control ) ;
2012-08-21 16:38:57 +02:00
if ( ! fCreated )
2013-04-25 23:31:22 +02:00
throw JSONRPCError ( RPC_WALLET_INSUFFICIENT_FUNDS , strFailReason ) ;
2016-10-25 20:27:04 +02:00
CValidationState state ;
2016-10-25 09:45:57 +02:00
if ( ! pwallet - > CommitTransaction ( wtx , keyChange , g_connman . get ( ) , state ) ) {
2016-10-25 20:27:04 +02:00
strFailReason = strprintf ( " Transaction commit failed:: %s " , state . GetRejectReason ( ) ) ;
throw JSONRPCError ( RPC_WALLET_ERROR , strFailReason ) ;
}
2012-08-21 16:38:57 +02:00
return wtx . GetHash ( ) . GetHex ( ) ;
}
2016-01-15 02:55:57 +01:00
// Defined in rpc/misc.cpp
2016-09-09 07:32:12 +02:00
extern CScript _createmultisig_redeemScript ( CWallet * const pwallet , const UniValue & params ) ;
2012-09-10 15:32:40 +02:00
2016-09-22 09:46:41 +02:00
UniValue addmultisigaddress ( const JSONRPCRequest & request )
2012-09-10 15:32:40 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) < 2 | | request . params . size ( ) > 3 )
2012-09-10 15:32:40 +02:00
{
2017-01-27 02:33:45 +01:00
std : : string msg = " addmultisigaddress nrequired [ \" key \" ,...] ( \" account \" ) \n "
2013-10-29 12:29:44 +01:00
" \n Add a nrequired-to-sign multisignature address to the wallet. \n "
" Each key is a Bitcoin address or hex-encoded public key. \n "
2014-12-30 15:32:07 +01:00
" If 'account' is specified (DEPRECATED), assign address to that account. \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
" 1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses. \n "
2016-11-21 14:32:36 +01:00
" 2. \" keys \" (string, required) A json array of bitcoin addresses or hex-encoded public keys \n "
2013-10-29 12:29:44 +01:00
" [ \n "
" \" address \" (string) bitcoin address or hex-encoded public key \n "
" ..., \n "
" ] \n "
2014-12-30 15:32:07 +01:00
" 3. \" account \" (string, optional) DEPRECATED. An account to assign the addresses to. \n "
2013-10-29 12:29:44 +01:00
" \n Result: \n "
2016-12-09 18:06:42 +01:00
" \" address \" (string) A bitcoin address associated with the keys. \n "
2013-10-29 12:29:44 +01:00
" \n Examples: \n "
" \n Add a multisig address from 2 addresses \n "
+ HelpExampleCli ( " addmultisigaddress " , " 2 \" [ \\ \" 16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5 \\ \" , \\ \" 171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV \\ \" ] \" " ) +
" \n As json rpc call \n "
+ HelpExampleRpc ( " addmultisigaddress " , " 2, \" [ \\ \" 16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5 \\ \" , \\ \" 171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV \\ \" ] \" " )
;
2017-01-27 02:33:45 +01:00
throw std : : runtime_error ( msg ) ;
2012-09-10 15:32:40 +02:00
}
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2017-01-27 02:33:45 +01:00
std : : string strAccount ;
2016-09-22 09:46:41 +02:00
if ( request . params . size ( ) > 2 )
strAccount = AccountFromValue ( request . params [ 2 ] ) ;
2012-08-21 16:38:57 +02:00
// Construct using pay-to-script-hash:
2016-10-25 09:45:57 +02:00
CScript inner = _createmultisig_redeemScript ( pwallet , request . params ) ;
2014-09-25 04:24:46 +02:00
CScriptID innerID ( inner ) ;
2016-10-25 09:45:57 +02:00
pwallet - > AddCScript ( inner ) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
pwallet - > SetAddressBook ( innerID , strAccount , " send " ) ;
2012-08-21 16:38:57 +02:00
return CBitcoinAddress ( innerID ) . ToString ( ) ;
}
2015-12-30 01:13:08 +01:00
class Witnessifier : public boost : : static_visitor < bool >
{
public :
2016-09-09 07:32:12 +02:00
CWallet * const pwallet ;
2015-12-30 01:13:08 +01:00
CScriptID result ;
2016-09-09 07:32:12 +02:00
Witnessifier ( CWallet * _pwallet ) : pwallet ( _pwallet ) { }
2015-12-30 01:13:08 +01:00
bool operator ( ) ( const CNoDestination & dest ) const { return false ; }
bool operator ( ) ( const CKeyID & keyID ) {
2016-09-09 07:32:12 +02:00
if ( pwallet ) {
2016-10-16 18:32:36 +02:00
CScript basescript = GetScriptForDestination ( keyID ) ;
2015-12-30 01:13:08 +01:00
CScript witscript = GetScriptForWitness ( basescript ) ;
2017-07-11 03:31:57 +02:00
SignatureData sigs ;
// This check is to make sure that the script we created can actually be solved for and signed by us
// if we were to have the private keys. This is just to make sure that the script is valid and that,
// if found in a transaction, we would still accept and relay that transcation.
if ( ! ProduceSignature ( DummySignatureCreator ( pwallet ) , witscript , sigs ) | |
! VerifyScript ( sigs . scriptSig , witscript , & sigs . scriptWitness , MANDATORY_SCRIPT_VERIFY_FLAGS | SCRIPT_VERIFY_WITNESS_PUBKEYTYPE , DummySignatureCreator ( pwallet ) . Checker ( ) ) ) {
return false ;
}
2016-09-09 07:32:12 +02:00
pwallet - > AddCScript ( witscript ) ;
2015-12-30 01:13:08 +01:00
result = CScriptID ( witscript ) ;
return true ;
}
return false ;
}
bool operator ( ) ( const CScriptID & scriptID ) {
CScript subscript ;
2016-09-09 07:32:12 +02:00
if ( pwallet & & pwallet - > GetCScript ( scriptID , subscript ) ) {
2015-12-30 01:13:08 +01:00
int witnessversion ;
std : : vector < unsigned char > witprog ;
if ( subscript . IsWitnessProgram ( witnessversion , witprog ) ) {
result = scriptID ;
return true ;
}
CScript witscript = GetScriptForWitness ( subscript ) ;
2017-07-11 03:31:57 +02:00
SignatureData sigs ;
// This check is to make sure that the script we created can actually be solved for and signed by us
// if we were to have the private keys. This is just to make sure that the script is valid and that,
// if found in a transaction, we would still accept and relay that transcation.
if ( ! ProduceSignature ( DummySignatureCreator ( pwallet ) , witscript , sigs ) | |
! VerifyScript ( sigs . scriptSig , witscript , & sigs . scriptWitness , MANDATORY_SCRIPT_VERIFY_FLAGS | SCRIPT_VERIFY_WITNESS_PUBKEYTYPE , DummySignatureCreator ( pwallet ) . Checker ( ) ) ) {
return false ;
}
2016-09-09 07:32:12 +02:00
pwallet - > AddCScript ( witscript ) ;
2015-12-30 01:13:08 +01:00
result = CScriptID ( witscript ) ;
return true ;
}
return false ;
}
} ;
2016-09-22 09:46:41 +02:00
UniValue addwitnessaddress ( const JSONRPCRequest & request )
2015-12-30 01:13:08 +01:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-12-30 01:13:08 +01:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2015-12-30 01:13:08 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) < 1 | | request . params . size ( ) > 1 )
2015-12-30 01:13:08 +01:00
{
2017-01-27 02:33:45 +01:00
std : : string msg = " addwitnessaddress \" address \" \n "
2015-12-30 01:13:08 +01:00
" \n Add a witness address for a script (with pubkey or redeemscript known). \n "
" It returns the witness script. \n "
" \n Arguments: \n "
" 1. \" address \" (string, required) An address known to the wallet \n "
" \n Result: \n "
" \" witnessaddress \" , (string) The value of the new address (P2SH of witness script). \n "
" } \n "
;
2017-01-27 02:33:45 +01:00
throw std : : runtime_error ( msg ) ;
2015-12-30 01:13:08 +01:00
}
{
LOCK ( cs_main ) ;
2017-08-01 21:17:40 +02:00
if ( ! IsWitnessEnabled ( chainActive . Tip ( ) , Params ( ) . GetConsensus ( ) ) & & ! gArgs . GetBoolArg ( " -walletprematurewitness " , false ) ) {
2015-12-30 01:13:08 +01:00
throw JSONRPCError ( RPC_WALLET_ERROR , " Segregated witness not enabled on network " ) ;
}
}
2016-09-22 09:46:41 +02:00
CBitcoinAddress address ( request . params [ 0 ] . get_str ( ) ) ;
2015-12-30 01:13:08 +01:00
if ( ! address . IsValid ( ) )
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Invalid Bitcoin address " ) ;
2016-10-25 09:45:57 +02:00
Witnessifier w ( pwallet ) ;
2015-12-30 01:13:08 +01:00
CTxDestination dest = address . Get ( ) ;
bool ret = boost : : apply_visitor ( w , dest ) ;
if ( ! ret ) {
2016-10-16 18:32:36 +02:00
throw JSONRPCError ( RPC_WALLET_ERROR , " Public key or redeemscript not known to wallet, or the key is uncompressed " ) ;
2015-12-30 01:13:08 +01:00
}
2016-10-25 09:45:57 +02:00
pwallet - > SetAddressBook ( w . result , " " , " receive " ) ;
2016-09-09 18:13:18 +02:00
2015-12-30 01:13:08 +01:00
return CBitcoinAddress ( w . result ) . ToString ( ) ;
}
2012-08-21 16:38:57 +02:00
struct tallyitem
{
2014-04-23 00:46:19 +02:00
CAmount nAmount ;
2012-08-21 16:38:57 +02:00
int nConf ;
2017-01-27 02:33:45 +01:00
std : : vector < uint256 > txids ;
2014-05-31 16:57:26 +02:00
bool fIsWatchonly ;
2012-08-21 16:38:57 +02:00
tallyitem ( )
{
nAmount = 0 ;
nConf = std : : numeric_limits < int > : : max ( ) ;
2014-05-31 16:57:26 +02:00
fIsWatchonly = false ;
2012-08-21 16:38:57 +02:00
}
} ;
2016-09-09 07:32:12 +02:00
UniValue ListReceived ( CWallet * const pwallet , const UniValue & params , bool fByAccounts )
2012-08-21 16:38:57 +02:00
{
// Minimum confirmations
int nMinDepth = 1 ;
2017-07-10 17:44:39 +02:00
if ( ! params [ 0 ] . isNull ( ) )
2012-08-21 16:38:57 +02:00
nMinDepth = params [ 0 ] . get_int ( ) ;
// Whether to include empty accounts
bool fIncludeEmpty = false ;
2017-07-10 17:44:39 +02:00
if ( ! params [ 1 ] . isNull ( ) )
2012-08-21 16:38:57 +02:00
fIncludeEmpty = params [ 1 ] . get_bool ( ) ;
2014-07-01 11:00:22 +02:00
isminefilter filter = ISMINE_SPENDABLE ;
2017-07-10 17:44:39 +02:00
if ( ! params [ 2 ] . isNull ( ) )
2014-05-31 16:57:26 +02:00
if ( params [ 2 ] . get_bool ( ) )
2014-07-01 11:00:22 +02:00
filter = filter | ISMINE_WATCH_ONLY ;
2014-05-31 16:57:26 +02:00
2012-08-21 16:38:57 +02:00
// Tally
2017-01-27 02:33:45 +01:00
std : : map < CBitcoinAddress , tallyitem > mapTally ;
2016-10-25 10:04:23 +02:00
for ( const std : : pair < uint256 , CWalletTx > & pairWtx : pwallet - > mapWallet ) {
const CWalletTx & wtx = pairWtx . second ;
2012-08-21 16:38:57 +02:00
2016-11-12 01:54:51 +01:00
if ( wtx . IsCoinBase ( ) | | ! CheckFinalTx ( * wtx . tx ) )
2012-08-21 16:38:57 +02:00
continue ;
int nDepth = wtx . GetDepthInMainChain ( ) ;
if ( nDepth < nMinDepth )
continue ;
2017-06-02 03:18:57 +02:00
for ( const CTxOut & txout : wtx . tx - > vout )
2012-08-21 16:38:57 +02:00
{
CTxDestination address ;
2014-05-31 16:57:26 +02:00
if ( ! ExtractDestination ( txout . scriptPubKey , address ) )
continue ;
2016-09-09 07:32:12 +02:00
isminefilter mine = IsMine ( * pwallet , address ) ;
2014-06-22 23:29:33 +02:00
if ( ! ( mine & filter ) )
2012-08-21 16:38:57 +02:00
continue ;
tallyitem & item = mapTally [ address ] ;
item . nAmount + = txout . nValue ;
2017-01-27 02:33:45 +01:00
item . nConf = std : : min ( item . nConf , nDepth ) ;
2012-12-13 15:59:10 +01:00
item . txids . push_back ( wtx . GetHash ( ) ) ;
2014-07-01 11:00:22 +02:00
if ( mine & ISMINE_WATCH_ONLY )
2014-05-31 16:57:26 +02:00
item . fIsWatchonly = true ;
2012-08-21 16:38:57 +02:00
}
}
// Reply
2015-05-10 14:48:35 +02:00
UniValue ret ( UniValue : : VARR ) ;
2017-01-27 02:33:45 +01:00
std : : map < std : : string , tallyitem > mapAccountTally ;
2016-10-25 10:04:23 +02:00
for ( const std : : pair < CBitcoinAddress , CAddressBookData > & item : pwallet - > mapAddressBook ) {
2012-08-21 16:38:57 +02:00
const CBitcoinAddress & address = item . first ;
2017-01-27 02:33:45 +01:00
const std : : string & strAccount = item . second . name ;
std : : map < CBitcoinAddress , tallyitem > : : iterator it = mapTally . find ( address ) ;
2012-08-21 16:38:57 +02:00
if ( it = = mapTally . end ( ) & & ! fIncludeEmpty )
continue ;
2014-04-23 00:46:19 +02:00
CAmount nAmount = 0 ;
2012-08-21 16:38:57 +02:00
int nConf = std : : numeric_limits < int > : : max ( ) ;
2014-05-31 16:57:26 +02:00
bool fIsWatchonly = false ;
2012-08-21 16:38:57 +02:00
if ( it ! = mapTally . end ( ) )
{
nAmount = ( * it ) . second . nAmount ;
nConf = ( * it ) . second . nConf ;
2014-05-31 16:57:26 +02:00
fIsWatchonly = ( * it ) . second . fIsWatchonly ;
2012-08-21 16:38:57 +02:00
}
if ( fByAccounts )
{
2016-06-11 16:35:19 +02:00
tallyitem & _item = mapAccountTally [ strAccount ] ;
_item . nAmount + = nAmount ;
2017-01-27 02:33:45 +01:00
_item . nConf = std : : min ( _item . nConf , nConf ) ;
2016-06-11 16:35:19 +02:00
_item . fIsWatchonly = fIsWatchonly ;
2012-08-21 16:38:57 +02:00
}
else
{
2015-05-10 14:48:35 +02:00
UniValue obj ( UniValue : : VOBJ ) ;
2014-05-31 16:57:26 +02:00
if ( fIsWatchonly )
obj . push_back ( Pair ( " involvesWatchonly " , true ) ) ;
2012-08-21 16:38:57 +02:00
obj . push_back ( Pair ( " address " , address . ToString ( ) ) ) ;
obj . push_back ( Pair ( " account " , strAccount ) ) ;
obj . push_back ( Pair ( " amount " , ValueFromAmount ( nAmount ) ) ) ;
obj . push_back ( Pair ( " confirmations " , ( nConf = = std : : numeric_limits < int > : : max ( ) ? 0 : nConf ) ) ) ;
2014-12-30 15:12:37 +01:00
if ( ! fByAccounts )
obj . push_back ( Pair ( " label " , strAccount ) ) ;
2015-05-10 14:48:35 +02:00
UniValue transactions ( UniValue : : VARR ) ;
2012-12-16 20:10:32 +01:00
if ( it ! = mapTally . end ( ) )
2012-12-13 15:59:10 +01:00
{
2017-06-02 03:18:57 +02:00
for ( const uint256 & _item : ( * it ) . second . txids )
2012-12-16 20:10:32 +01:00
{
2016-06-11 16:35:19 +02:00
transactions . push_back ( _item . GetHex ( ) ) ;
2012-12-16 20:10:32 +01:00
}
2012-12-13 15:59:10 +01:00
}
obj . push_back ( Pair ( " txids " , transactions ) ) ;
2012-08-21 16:38:57 +02:00
ret . push_back ( obj ) ;
}
}
if ( fByAccounts )
{
2017-01-27 02:33:45 +01:00
for ( std : : map < std : : string , tallyitem > : : iterator it = mapAccountTally . begin ( ) ; it ! = mapAccountTally . end ( ) ; + + it )
2012-08-21 16:38:57 +02:00
{
2014-04-23 00:46:19 +02:00
CAmount nAmount = ( * it ) . second . nAmount ;
2012-08-21 16:38:57 +02:00
int nConf = ( * it ) . second . nConf ;
2015-05-10 14:48:35 +02:00
UniValue obj ( UniValue : : VOBJ ) ;
2014-05-31 16:57:26 +02:00
if ( ( * it ) . second . fIsWatchonly )
obj . push_back ( Pair ( " involvesWatchonly " , true ) ) ;
2012-08-21 16:38:57 +02:00
obj . push_back ( Pair ( " account " , ( * it ) . first ) ) ;
obj . push_back ( Pair ( " amount " , ValueFromAmount ( nAmount ) ) ) ;
obj . push_back ( Pair ( " confirmations " , ( nConf = = std : : numeric_limits < int > : : max ( ) ? 0 : nConf ) ) ) ;
ret . push_back ( obj ) ;
}
}
return ret ;
}
2016-09-22 09:46:41 +02:00
UniValue listreceivedbyaddress ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) > 3 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2016-11-21 14:32:36 +01:00
" listreceivedbyaddress ( minconf include_empty include_watchonly) \n "
2013-10-29 12:29:44 +01:00
" \n List balances by receiving address. \n "
" \n Arguments: \n "
2016-12-09 18:06:42 +01:00
" 1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included. \n "
" 2. include_empty (bool, optional, default=false) Whether to include addresses that haven't received any payments. \n "
2017-01-11 14:29:46 +01:00
" 3. include_watchonly (bool, optional, default=false) Whether to include watch-only addresses (see 'importaddress'). \n "
2013-10-29 12:29:44 +01:00
" \n Result: \n "
" [ \n "
" { \n "
2014-12-30 16:15:40 +01:00
" \" involvesWatchonly \" : true, (bool) Only returned if imported addresses were involved in transaction \n "
2013-10-29 12:29:44 +01:00
" \" address \" : \" receivingaddress \" , (string) The receiving address \n "
2014-12-30 15:32:07 +01:00
" \" account \" : \" accountname \" , (string) DEPRECATED. The account of the receiving address. The default account is \" \" . \n "
2015-08-01 21:15:23 +02:00
" \" amount \" : x.xxx, (numeric) The total amount in " + CURRENCY_UNIT + " received by the address \n "
2014-12-30 15:12:37 +01:00
" \" confirmations \" : n, (numeric) The number of confirmations of the most recent transaction included \n "
2017-01-11 14:29:46 +01:00
" \" label \" : \" label \" , (string) A comment for the address/transaction, if any \n "
" \" txids \" : [ \n "
" n, (numeric) The ids of transactions received with the address \n "
" ... \n "
" ] \n "
2013-10-29 12:29:44 +01:00
" } \n "
" ,... \n "
" ] \n "
" \n Examples: \n "
+ HelpExampleCli ( " listreceivedbyaddress " , " " )
+ HelpExampleCli ( " listreceivedbyaddress " , " 6 true " )
2014-05-31 16:57:26 +02:00
+ HelpExampleRpc ( " listreceivedbyaddress " , " 6, true, true " )
2013-10-29 12:29:44 +01:00
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2016-10-25 09:45:57 +02:00
return ListReceived ( pwallet , request . params , false ) ;
2012-08-21 16:38:57 +02:00
}
2016-09-22 09:46:41 +02:00
UniValue listreceivedbyaccount ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) > 3 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2016-11-21 14:32:36 +01:00
" listreceivedbyaccount ( minconf include_empty include_watchonly) \n "
2014-12-30 15:32:07 +01:00
" \n DEPRECATED. List balances by account. \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
2016-12-09 18:06:42 +01:00
" 1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included. \n "
" 2. include_empty (bool, optional, default=false) Whether to include accounts that haven't received any payments. \n "
2017-01-11 14:29:46 +01:00
" 3. include_watchonly (bool, optional, default=false) Whether to include watch-only addresses (see 'importaddress'). \n "
2013-10-29 12:29:44 +01:00
" \n Result: \n "
" [ \n "
" { \n "
2014-12-30 16:15:40 +01:00
" \" involvesWatchonly \" : true, (bool) Only returned if imported addresses were involved in transaction \n "
2013-10-29 12:29:44 +01:00
" \" account \" : \" accountname \" , (string) The account name of the receiving account \n "
" \" amount \" : x.xxx, (numeric) The total amount received by addresses with this account \n "
2014-12-30 15:12:37 +01:00
" \" confirmations \" : n, (numeric) The number of confirmations of the most recent transaction included \n "
" \" label \" : \" label \" (string) A comment for the address/transaction, if any \n "
2013-10-29 12:29:44 +01:00
" } \n "
" ,... \n "
" ] \n "
" \n Examples: \n "
+ HelpExampleCli ( " listreceivedbyaccount " , " " )
+ HelpExampleCli ( " listreceivedbyaccount " , " 6 true " )
2014-05-31 16:57:26 +02:00
+ HelpExampleRpc ( " listreceivedbyaccount " , " 6, true, true " )
2013-10-29 12:29:44 +01:00
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2016-10-25 09:45:57 +02:00
return ListReceived ( pwallet , request . params , true ) ;
2012-08-21 16:38:57 +02:00
}
2015-05-13 21:29:19 +02:00
static void MaybePushAddress ( UniValue & entry , const CTxDestination & dest )
2012-09-22 05:22:34 +02:00
{
CBitcoinAddress addr ;
if ( addr . Set ( dest ) )
entry . push_back ( Pair ( " address " , addr . ToString ( ) ) ) ;
}
2017-01-24 06:27:22 +01:00
/**
* List transactions based on the given criteria .
*
* @ param pwallet The wallet .
* @ param wtx The wallet transaction .
* @ param strAccount The account , if any , or " * " for all .
* @ param nMinDepth The minimum confirmation depth .
* @ param fLong Whether to include the JSON version of the transaction .
* @ param ret The UniValue into which the result is stored .
* @ param filter The " is mine " filter bool .
*/
2017-01-27 02:33:45 +01:00
void ListTransactions ( CWallet * const pwallet , const CWalletTx & wtx , const std : : string & strAccount , int nMinDepth , bool fLong , UniValue & ret , const isminefilter & filter )
2012-08-21 16:38:57 +02:00
{
2014-04-23 00:46:19 +02:00
CAmount nFee ;
2017-01-27 02:33:45 +01:00
std : : string strSentAccount ;
std : : list < COutputEntry > listReceived ;
std : : list < COutputEntry > listSent ;
2012-08-21 16:38:57 +02:00
2014-04-08 17:51:04 +02:00
wtx . GetAmounts ( listReceived , listSent , nFee , strSentAccount , filter ) ;
2012-08-21 16:38:57 +02:00
2017-01-27 02:33:45 +01:00
bool fAllAccounts = ( strAccount = = std : : string ( " * " ) ) ;
2014-07-01 11:00:22 +02:00
bool involvesWatchonly = wtx . IsFromMe ( ISMINE_WATCH_ONLY ) ;
2012-08-21 16:38:57 +02:00
// Sent
if ( ( ! listSent . empty ( ) | | nFee ! = 0 ) & & ( fAllAccounts | | strAccount = = strSentAccount ) )
{
2017-06-02 03:18:57 +02:00
for ( const COutputEntry & s : listSent )
2012-08-21 16:38:57 +02:00
{
2015-05-10 14:48:35 +02:00
UniValue entry ( UniValue : : VOBJ ) ;
2016-10-25 10:04:23 +02:00
if ( involvesWatchonly | | ( : : IsMine ( * pwallet , s . destination ) & ISMINE_WATCH_ONLY ) ) {
2014-04-09 17:20:07 +02:00
entry . push_back ( Pair ( " involvesWatchonly " , true ) ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
entry . push_back ( Pair ( " account " , strSentAccount ) ) ;
2014-05-30 00:54:00 +02:00
MaybePushAddress ( entry , s . destination ) ;
2014-02-21 16:31:49 +01:00
entry . push_back ( Pair ( " category " , " send " ) ) ;
2014-05-30 00:54:00 +02:00
entry . push_back ( Pair ( " amount " , ValueFromAmount ( - s . amount ) ) ) ;
2016-10-25 10:04:23 +02:00
if ( pwallet - > mapAddressBook . count ( s . destination ) ) {
2016-09-09 07:32:12 +02:00
entry . push_back ( Pair ( " label " , pwallet - > mapAddressBook [ s . destination ] . name ) ) ;
2016-10-25 10:04:23 +02:00
}
2014-05-30 00:54:00 +02:00
entry . push_back ( Pair ( " vout " , s . vout ) ) ;
2012-08-21 16:38:57 +02:00
entry . push_back ( Pair ( " fee " , ValueFromAmount ( - nFee ) ) ) ;
if ( fLong )
WalletTxToJSON ( wtx , entry ) ;
2016-03-17 17:46:06 +01:00
entry . push_back ( Pair ( " abandoned " , wtx . isAbandoned ( ) ) ) ;
2012-08-21 16:38:57 +02:00
ret . push_back ( entry ) ;
}
}
// Received
if ( listReceived . size ( ) > 0 & & wtx . GetDepthInMainChain ( ) > = nMinDepth )
{
2017-06-02 03:18:57 +02:00
for ( const COutputEntry & r : listReceived )
2012-08-21 16:38:57 +02:00
{
2017-01-27 02:33:45 +01:00
std : : string account ;
2016-10-25 10:04:23 +02:00
if ( pwallet - > mapAddressBook . count ( r . destination ) ) {
2016-09-09 07:32:12 +02:00
account = pwallet - > mapAddressBook [ r . destination ] . name ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
if ( fAllAccounts | | ( account = = strAccount ) )
{
2015-05-10 14:48:35 +02:00
UniValue entry ( UniValue : : VOBJ ) ;
2016-10-25 10:04:23 +02:00
if ( involvesWatchonly | | ( : : IsMine ( * pwallet , r . destination ) & ISMINE_WATCH_ONLY ) ) {
2014-04-09 17:20:07 +02:00
entry . push_back ( Pair ( " involvesWatchonly " , true ) ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
entry . push_back ( Pair ( " account " , account ) ) ;
2014-05-30 00:54:00 +02:00
MaybePushAddress ( entry , r . destination ) ;
2012-06-02 04:33:28 +02:00
if ( wtx . IsCoinBase ( ) )
{
if ( wtx . GetDepthInMainChain ( ) < 1 )
entry . push_back ( Pair ( " category " , " orphan " ) ) ;
else if ( wtx . GetBlocksToMaturity ( ) > 0 )
entry . push_back ( Pair ( " category " , " immature " ) ) ;
else
entry . push_back ( Pair ( " category " , " generate " ) ) ;
}
else
2014-02-12 19:43:07 +01:00
{
2014-02-21 16:31:49 +01:00
entry . push_back ( Pair ( " category " , " receive " ) ) ;
2014-02-12 19:43:07 +01:00
}
2014-05-30 00:54:00 +02:00
entry . push_back ( Pair ( " amount " , ValueFromAmount ( r . amount ) ) ) ;
2016-10-25 10:04:23 +02:00
if ( pwallet - > mapAddressBook . count ( r . destination ) ) {
2014-12-30 15:12:37 +01:00
entry . push_back ( Pair ( " label " , account ) ) ;
2016-10-25 10:04:23 +02:00
}
2014-05-30 00:54:00 +02:00
entry . push_back ( Pair ( " vout " , r . vout ) ) ;
2012-08-21 16:38:57 +02:00
if ( fLong )
WalletTxToJSON ( wtx , entry ) ;
ret . push_back ( entry ) ;
}
}
}
}
2017-01-27 02:33:45 +01:00
void AcentryToJSON ( const CAccountingEntry & acentry , const std : : string & strAccount , UniValue & ret )
2012-08-21 16:38:57 +02:00
{
2017-01-27 02:33:45 +01:00
bool fAllAccounts = ( strAccount = = std : : string ( " * " ) ) ;
2012-08-21 16:38:57 +02:00
if ( fAllAccounts | | acentry . strAccount = = strAccount )
{
2015-05-10 14:48:35 +02:00
UniValue entry ( UniValue : : VOBJ ) ;
2012-08-21 16:38:57 +02:00
entry . push_back ( Pair ( " account " , acentry . strAccount ) ) ;
entry . push_back ( Pair ( " category " , " move " ) ) ;
2014-05-06 14:58:43 +02:00
entry . push_back ( Pair ( " time " , acentry . nTime ) ) ;
2012-08-21 16:38:57 +02:00
entry . push_back ( Pair ( " amount " , ValueFromAmount ( acentry . nCreditDebit ) ) ) ;
entry . push_back ( Pair ( " otheraccount " , acentry . strOtherAccount ) ) ;
entry . push_back ( Pair ( " comment " , acentry . strComment ) ) ;
ret . push_back ( entry ) ;
}
}
2016-09-22 09:46:41 +02:00
UniValue listtransactions ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) > 4 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2016-12-09 18:06:42 +01:00
" listtransactions ( \" account \" count skip include_watchonly) \n "
2013-10-29 12:29:44 +01:00
" \n Returns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'. \n "
" \n Arguments: \n "
2014-12-30 15:32:07 +01:00
" 1. \" account \" (string, optional) DEPRECATED. The account name. Should be \" * \" . \n "
2013-10-29 12:29:44 +01:00
" 2. count (numeric, optional, default=10) The number of transactions to return \n "
2016-12-09 18:06:42 +01:00
" 3. skip (numeric, optional, default=0) The number of transactions to skip \n "
2017-01-11 14:29:46 +01:00
" 4. include_watchonly (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress') \n "
2013-10-29 12:29:44 +01:00
" \n Result: \n "
" [ \n "
" { \n "
2014-12-30 15:32:07 +01:00
" \" account \" : \" accountname \" , (string) DEPRECATED. The account name associated with the transaction. \n "
2013-10-29 12:29:44 +01:00
" It will be \" \" for the default account. \n "
2016-11-21 14:39:58 +01:00
" \" address \" : \" address \" , (string) The bitcoin address of the transaction. Not present for \n "
2013-10-29 12:29:44 +01:00
" move transactions (category = move). \n "
" \" category \" : \" send|receive|move \" , (string) The transaction category. 'move' is a local (off blockchain) \n "
" transaction between accounts, and not associated with an address, \n "
" transaction id or block. 'send' and 'receive' transactions are \n "
" associated with an address, transaction id and block details \n "
2015-08-01 21:15:23 +02:00
" \" amount \" : x.xxx, (numeric) The amount in " + CURRENCY_UNIT + " . This is negative for the 'send' category, and for the \n "
2013-10-29 12:29:44 +01:00
" 'move' category for moves outbound. It is positive for the 'receive' category, \n "
" and for the 'move' category for inbound funds. \n "
2017-01-11 14:29:46 +01:00
" \" label \" : \" label \" , (string) A comment for the address/transaction, if any \n "
2015-11-20 12:51:36 +01:00
" \" vout \" : n, (numeric) the vout value \n "
2015-08-01 21:15:23 +02:00
" \" fee \" : x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + " . This is negative and only available for the \n "
2013-10-29 12:29:44 +01:00
" 'send' category of transactions. \n "
" \" confirmations \" : n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n "
2015-11-26 18:42:07 +01:00
" 'receive' category of transactions. Negative confirmations indicate the \n "
2016-01-17 12:03:56 +01:00
" transaction conflicts with the block chain \n "
2017-01-11 14:29:46 +01:00
" \" trusted \" : xxx, (bool) Whether we consider the outputs of this unconfirmed transaction safe to spend. \n "
2013-10-29 12:29:44 +01:00
" \" blockhash \" : \" hashvalue \" , (string) The block hash containing the transaction. Available for 'send' and 'receive' \n "
" category of transactions. \n "
2016-02-16 20:42:14 +01:00
" \" blockindex \" : n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive' \n "
2013-10-29 12:29:44 +01:00
" category of transactions. \n "
2015-11-20 12:51:36 +01:00
" \" blocktime \" : xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT). \n "
2014-05-29 18:17:34 +02:00
" \" txid \" : \" transactionid \" , (string) The transaction id. Available for 'send' and 'receive' category of transactions. \n "
2013-10-29 12:29:44 +01:00
" \" time \" : xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT). \n "
" \" timereceived \" : xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n "
" for 'send' and 'receive' category of transactions. \n "
" \" comment \" : \" ... \" , (string) If a comment is associated with the transaction. \n "
2017-01-11 14:29:46 +01:00
" \" otheraccount \" : \" accountname \" , (string) DEPRECATED. For the 'move' category of transactions, the account the funds came \n "
2013-10-29 12:29:44 +01:00
" from (for receiving funds, positive amounts), or went to (for sending funds, \n "
" negative amounts). \n "
2017-01-11 14:29:46 +01:00
" \" bip125-replaceable \" : \" yes|no|unknown \" , (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee); \n "
2015-12-16 20:57:54 +01:00
" may be unknown for unconfirmed transactions not in the mempool \n "
2017-01-11 14:29:46 +01:00
" \" abandoned \" : xxx (bool) 'true' if the transaction has been abandoned (inputs are respendable). Only available for the \n "
" 'send' category of transactions. \n "
2013-10-29 12:29:44 +01:00
" } \n "
" ] \n "
" \n Examples: \n "
" \n List the most recent 10 transactions in the systems \n "
+ HelpExampleCli ( " listtransactions " , " " ) +
2014-12-30 15:32:07 +01:00
" \n List transactions 100 to 120 \n "
+ HelpExampleCli ( " listtransactions " , " \" * \" 20 100 " ) +
2013-10-29 12:29:44 +01:00
" \n As a json rpc call \n "
2014-12-30 15:32:07 +01:00
+ HelpExampleRpc ( " listtransactions " , " \" * \" , 20, 100 " )
2013-10-29 12:29:44 +01:00
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2017-01-27 02:33:45 +01:00
std : : string strAccount = " * " ;
2017-07-10 17:44:39 +02:00
if ( ! request . params [ 0 ] . isNull ( ) )
2016-09-22 09:46:41 +02:00
strAccount = request . params [ 0 ] . get_str ( ) ;
2012-08-21 16:38:57 +02:00
int nCount = 10 ;
2017-07-10 17:44:39 +02:00
if ( ! request . params [ 1 ] . isNull ( ) )
2016-09-22 09:46:41 +02:00
nCount = request . params [ 1 ] . get_int ( ) ;
2012-08-21 16:38:57 +02:00
int nFrom = 0 ;
2017-07-10 17:44:39 +02:00
if ( ! request . params [ 2 ] . isNull ( ) )
2016-09-22 09:46:41 +02:00
nFrom = request . params [ 2 ] . get_int ( ) ;
2014-07-01 11:00:22 +02:00
isminefilter filter = ISMINE_SPENDABLE ;
2017-07-10 17:44:39 +02:00
if ( ! request . params [ 3 ] . isNull ( ) )
2016-09-22 09:46:41 +02:00
if ( request . params [ 3 ] . get_bool ( ) )
2014-07-01 11:00:22 +02:00
filter = filter | ISMINE_WATCH_ONLY ;
2012-08-21 16:38:57 +02:00
if ( nCount < 0 )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Negative count " ) ;
2012-08-21 16:38:57 +02:00
if ( nFrom < 0 )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Negative from " ) ;
2012-08-21 16:38:57 +02:00
2015-05-10 14:48:35 +02:00
UniValue ret ( UniValue : : VARR ) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
const CWallet : : TxItems & txOrdered = pwallet - > wtxOrdered ;
2012-08-21 16:38:57 +02:00
// iterate backwards until we have nCount items to return:
2015-10-19 11:19:38 +02:00
for ( CWallet : : TxItems : : const_reverse_iterator it = txOrdered . rbegin ( ) ; it ! = txOrdered . rend ( ) ; + + it )
2012-08-21 16:38:57 +02:00
{
CWalletTx * const pwtx = ( * it ) . second . first ;
if ( pwtx ! = 0 )
2016-10-25 09:45:57 +02:00
ListTransactions ( pwallet , * pwtx , strAccount , 0 , true , ret , filter ) ;
2012-08-21 16:38:57 +02:00
CAccountingEntry * const pacentry = ( * it ) . second . second ;
if ( pacentry ! = 0 )
AcentryToJSON ( * pacentry , strAccount , ret ) ;
if ( ( int ) ret . size ( ) > = ( nCount + nFrom ) ) break ;
}
// ret is newest to oldest
if ( nFrom > ( int ) ret . size ( ) )
nFrom = ret . size ( ) ;
if ( ( nFrom + nCount ) > ( int ) ret . size ( ) )
nCount = ret . size ( ) - nFrom ;
2014-08-20 21:15:16 +02:00
2017-01-27 02:33:45 +01:00
std : : vector < UniValue > arrTmp = ret . getValues ( ) ;
2014-08-20 21:15:16 +02:00
2017-01-27 02:33:45 +01:00
std : : vector < UniValue > : : iterator first = arrTmp . begin ( ) ;
2012-08-21 16:38:57 +02:00
std : : advance ( first , nFrom ) ;
2017-01-27 02:33:45 +01:00
std : : vector < UniValue > : : iterator last = arrTmp . begin ( ) ;
2012-08-21 16:38:57 +02:00
std : : advance ( last , nFrom + nCount ) ;
2014-08-20 21:15:16 +02:00
if ( last ! = arrTmp . end ( ) ) arrTmp . erase ( last , arrTmp . end ( ) ) ;
if ( first ! = arrTmp . begin ( ) ) arrTmp . erase ( arrTmp . begin ( ) , first ) ;
2012-08-21 16:38:57 +02:00
2014-08-20 21:15:16 +02:00
std : : reverse ( arrTmp . begin ( ) , arrTmp . end ( ) ) ; // Return oldest to newest
ret . clear ( ) ;
2015-05-10 14:48:35 +02:00
ret . setArray ( ) ;
2014-08-20 21:15:16 +02:00
ret . push_backV ( arrTmp ) ;
2012-08-21 16:38:57 +02:00
return ret ;
}
2016-09-22 09:46:41 +02:00
UniValue listaccounts ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) > 2 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2016-11-21 14:32:36 +01:00
" listaccounts ( minconf include_watchonly) \n "
2014-12-30 15:32:07 +01:00
" \n DEPRECATED. Returns Object that has account names as keys, account balances as values. \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
2016-12-09 18:06:42 +01:00
" 1. minconf (numeric, optional, default=1) Only include transactions with at least this many confirmations \n "
2017-01-11 14:29:46 +01:00
" 2. include_watchonly (bool, optional, default=false) Include balances in watch-only addresses (see 'importaddress') \n "
2013-10-29 12:29:44 +01:00
" \n Result: \n "
" { (json object where keys are account names, and values are numeric balances \n "
" \" account \" : x.xxx, (numeric) The property name is the account name, and the value is the total balance for the account. \n "
" ... \n "
" } \n "
" \n Examples: \n "
" \n List account balances where there at least 1 confirmation \n "
+ HelpExampleCli ( " listaccounts " , " " ) +
" \n List account balances including zero confirmation transactions \n "
+ HelpExampleCli ( " listaccounts " , " 0 " ) +
" \n List account balances for 6 or more confirmations \n "
+ HelpExampleCli ( " listaccounts " , " 6 " ) +
" \n As json rpc call \n "
+ HelpExampleRpc ( " listaccounts " , " 6 " )
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2012-08-21 16:38:57 +02:00
int nMinDepth = 1 ;
2016-09-22 09:46:41 +02:00
if ( request . params . size ( ) > 0 )
nMinDepth = request . params [ 0 ] . get_int ( ) ;
2014-07-01 11:00:22 +02:00
isminefilter includeWatchonly = ISMINE_SPENDABLE ;
2016-09-22 09:46:41 +02:00
if ( request . params . size ( ) > 1 )
if ( request . params [ 1 ] . get_bool ( ) )
2014-07-01 11:00:22 +02:00
includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY ;
2012-08-21 16:38:57 +02:00
2017-01-27 02:33:45 +01:00
std : : map < std : : string , CAmount > mapAccountBalances ;
2016-10-25 10:04:23 +02:00
for ( const std : : pair < CTxDestination , CAddressBookData > & entry : pwallet - > mapAddressBook ) {
if ( IsMine ( * pwallet , entry . first ) & includeWatchonly ) { // This address belongs to me
2013-07-15 07:20:50 +02:00
mapAccountBalances [ entry . second . name ] = 0 ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
}
2016-10-25 10:04:23 +02:00
for ( const std : : pair < uint256 , CWalletTx > & pairWtx : pwallet - > mapWallet ) {
const CWalletTx & wtx = pairWtx . second ;
2014-04-23 00:46:19 +02:00
CAmount nFee ;
2017-01-27 02:33:45 +01:00
std : : string strSentAccount ;
std : : list < COutputEntry > listReceived ;
std : : list < COutputEntry > listSent ;
2014-02-15 22:38:28 +01:00
int nDepth = wtx . GetDepthInMainChain ( ) ;
if ( wtx . GetBlocksToMaturity ( ) > 0 | | nDepth < 0 )
2014-02-14 02:12:51 +01:00
continue ;
2014-04-08 16:13:15 +02:00
wtx . GetAmounts ( listReceived , listSent , nFee , strSentAccount , includeWatchonly ) ;
2012-08-21 16:38:57 +02:00
mapAccountBalances [ strSentAccount ] - = nFee ;
2017-06-02 03:18:57 +02:00
for ( const COutputEntry & s : listSent )
2014-05-30 00:54:00 +02:00
mapAccountBalances [ strSentAccount ] - = s . amount ;
2014-02-15 22:38:28 +01:00
if ( nDepth > = nMinDepth )
2012-08-21 16:38:57 +02:00
{
2017-06-02 03:18:57 +02:00
for ( const COutputEntry & r : listReceived )
2016-10-25 10:04:23 +02:00
if ( pwallet - > mapAddressBook . count ( r . destination ) ) {
2016-10-25 09:45:57 +02:00
mapAccountBalances [ pwallet - > mapAddressBook [ r . destination ] . name ] + = r . amount ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
else
2014-05-30 00:54:00 +02:00
mapAccountBalances [ " " ] + = r . amount ;
2012-08-21 16:38:57 +02:00
}
}
2017-01-27 02:33:45 +01:00
const std : : list < CAccountingEntry > & acentries = pwallet - > laccentries ;
2017-06-02 03:18:57 +02:00
for ( const CAccountingEntry & entry : acentries )
2012-08-21 16:38:57 +02:00
mapAccountBalances [ entry . strAccount ] + = entry . nCreditDebit ;
2015-05-10 14:48:35 +02:00
UniValue ret ( UniValue : : VOBJ ) ;
2017-06-02 03:28:42 +02:00
for ( const std : : pair < std : : string , CAmount > & accountBalance : mapAccountBalances ) {
2012-08-21 16:38:57 +02:00
ret . push_back ( Pair ( accountBalance . first , ValueFromAmount ( accountBalance . second ) ) ) ;
}
return ret ;
}
2016-09-22 09:46:41 +02:00
UniValue listsinceblock ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2017-01-24 06:27:22 +01:00
if ( request . fHelp | | request . params . size ( ) > 4 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2017-01-24 06:27:22 +01:00
" listsinceblock ( \" blockhash \" target_confirmations include_watchonly include_removed ) \n "
" \n Get all transactions in blocks since block [blockhash], or all transactions if omitted. \n "
" If \" blockhash \" is no longer a part of the main chain, transactions from the fork point onward are included. \n "
" Additionally, if include_removed is set, transactions affecting the wallet which were removed are returned in the \" removed \" array. \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
2016-12-09 18:06:42 +01:00
" 1. \" blockhash \" (string, optional) The block hash to list transactions since \n "
2017-07-25 21:25:07 +02:00
" 2. target_confirmations: (numeric, optional, default=1) Return the nth block hash from the main chain. e.g. 1 would mean the best block hash. Note: this is not used as a filter, but only affects [lastblock] in the return value \n "
2017-01-24 06:27:22 +01:00
" 3. include_watchonly: (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress') \n "
" 4. include_removed: (bool, optional, default=true) Show transactions that were removed due to a reorg in the \" removed \" array \n "
" (not guaranteed to work on pruned nodes) \n "
2013-10-29 12:29:44 +01:00
" \n Result: \n "
" { \n "
" \" transactions \" : [ \n "
2014-12-30 15:32:07 +01:00
" \" account \" : \" accountname \" , (string) DEPRECATED. The account name associated with the transaction. Will be \" \" for the default account. \n "
2016-11-21 14:39:58 +01:00
" \" address \" : \" address \" , (string) The bitcoin address of the transaction. Not present for move transactions (category = move). \n "
2013-10-29 12:29:44 +01:00
" \" category \" : \" send|receive \" , (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts. \n "
2015-08-01 21:15:23 +02:00
" \" amount \" : x.xxx, (numeric) The amount in " + CURRENCY_UNIT + " . This is negative for the 'send' category, and for the 'move' category for moves \n "
2013-10-29 12:29:44 +01:00
" outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds. \n "
2014-05-30 00:54:00 +02:00
" \" vout \" : n, (numeric) the vout value \n "
2015-08-01 21:15:23 +02:00
" \" fee \" : x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + " . This is negative and only available for the 'send' category of transactions. \n "
2013-10-29 12:29:44 +01:00
" \" confirmations \" : n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions. \n "
2016-12-21 02:39:49 +01:00
" When it's < 0, it means the transaction conflicted that many blocks ago. \n "
2013-10-29 12:29:44 +01:00
" \" blockhash \" : \" hashvalue \" , (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions. \n "
2016-02-16 20:42:14 +01:00
" \" blockindex \" : n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive' category of transactions. \n "
2013-10-29 12:29:44 +01:00
" \" blocktime \" : xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT). \n "
2014-05-29 18:17:34 +02:00
" \" txid \" : \" transactionid \" , (string) The transaction id. Available for 'send' and 'receive' category of transactions. \n "
2013-10-29 12:29:44 +01:00
" \" time \" : xxx, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT). \n "
" \" timereceived \" : xxx, (numeric) The time received in seconds since epoch (Jan 1 1970 GMT). Available for 'send' and 'receive' category of transactions. \n "
2017-01-11 14:29:46 +01:00
" \" bip125-replaceable \" : \" yes|no|unknown \" , (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee); \n "
" may be unknown for unconfirmed transactions not in the mempool \n "
" \" abandoned \" : xxx, (bool) 'true' if the transaction has been abandoned (inputs are respendable). Only available for the 'send' category of transactions. \n "
2013-10-29 12:29:44 +01:00
" \" comment \" : \" ... \" , (string) If a comment is associated with the transaction. \n "
2014-12-30 15:12:37 +01:00
" \" label \" : \" label \" (string) A comment for the address/transaction, if any \n "
2013-10-29 12:29:44 +01:00
" \" to \" : \" ... \" , (string) If a comment to is associated with the transaction. \n "
2017-01-24 06:27:22 +01:00
" ], \n "
" \" removed \" : [ \n "
" <structure is the same as \" transactions \" above, only present if include_removed=true> \n "
" Note: transactions that were readded in the active chain will appear as-is in this array, and may thus have a positive confirmation count. \n "
" ], \n "
2017-07-25 21:25:07 +02:00
" \" lastblock \" : \" lastblockhash \" (string) The hash of the block (target_confirmations-1) from the best block on the main chain. This is typically used to feed back into listsinceblock the next time you call it. So you would generally use a target_confirmations of say 6, so you will be continually re-notified of transactions until they've reached 6 confirmations plus any new ones \n "
2013-10-29 12:29:44 +01:00
" } \n "
" \n Examples: \n "
+ HelpExampleCli ( " listsinceblock " , " " )
+ HelpExampleCli ( " listsinceblock " , " \" 000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad \" 6 " )
+ HelpExampleRpc ( " listsinceblock " , " \" 000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad \" , 6 " )
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2017-08-07 07:36:37 +02:00
const CBlockIndex * pindex = nullptr ; // Block index of the specified block or the common ancestor, if the block provided was in a deactivated chain.
const CBlockIndex * paltindex = nullptr ; // Block index of the specified block, even if it's in a deactivated chain.
2012-08-21 16:38:57 +02:00
int target_confirms = 1 ;
2014-07-01 11:00:22 +02:00
isminefilter filter = ISMINE_SPENDABLE ;
2012-08-21 16:38:57 +02:00
2017-01-24 06:27:22 +01:00
if ( ! request . params [ 0 ] . isNull ( ) ) {
2014-12-15 09:11:16 +01:00
uint256 blockId ;
2012-08-21 16:38:57 +02:00
2016-09-22 09:46:41 +02:00
blockId . SetHex ( request . params [ 0 ] . get_str ( ) ) ;
2014-09-04 02:02:44 +02:00
BlockMap : : iterator it = mapBlockIndex . find ( blockId ) ;
2017-01-24 06:27:22 +01:00
if ( it ! = mapBlockIndex . end ( ) ) {
paltindex = pindex = it - > second ;
if ( chainActive [ pindex - > nHeight ] ! = pindex ) {
2017-01-11 07:31:16 +01:00
// the block being asked for is a part of a deactivated chain;
// we don't want to depend on its perceived height in the block
// chain, we want to instead use the last common ancestor
pindex = chainActive . FindFork ( pindex ) ;
}
}
2012-08-21 16:38:57 +02:00
}
2017-01-24 06:27:22 +01:00
if ( ! request . params [ 1 ] . isNull ( ) ) {
2016-09-22 09:46:41 +02:00
target_confirms = request . params [ 1 ] . get_int ( ) ;
2012-08-21 16:38:57 +02:00
2017-01-24 06:27:22 +01:00
if ( target_confirms < 1 ) {
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Invalid parameter " ) ;
2017-01-24 06:27:22 +01:00
}
2012-08-21 16:38:57 +02:00
}
2017-01-24 06:27:22 +01:00
if ( ! request . params [ 2 ] . isNull ( ) & & request . params [ 2 ] . get_bool ( ) ) {
2017-01-11 07:31:16 +01:00
filter = filter | ISMINE_WATCH_ONLY ;
}
2014-04-29 19:39:01 +02:00
2017-01-24 06:27:22 +01:00
bool include_removed = ( request . params [ 3 ] . isNull ( ) | | request . params [ 3 ] . get_bool ( ) ) ;
2013-10-10 23:07:44 +02:00
int depth = pindex ? ( 1 + chainActive . Height ( ) - pindex - > nHeight ) : - 1 ;
2012-08-21 16:38:57 +02:00
2015-05-10 14:48:35 +02:00
UniValue transactions ( UniValue : : VARR ) ;
2012-08-21 16:38:57 +02:00
2016-10-25 10:04:23 +02:00
for ( const std : : pair < uint256 , CWalletTx > & pairWtx : pwallet - > mapWallet ) {
CWalletTx tx = pairWtx . second ;
2012-08-21 16:38:57 +02:00
2017-01-24 06:27:22 +01:00
if ( depth = = - 1 | | tx . GetDepthInMainChain ( ) < depth ) {
2016-10-25 09:45:57 +02:00
ListTransactions ( pwallet , tx , " * " , 0 , true , transactions , filter ) ;
2017-01-24 06:27:22 +01:00
}
}
// when a reorg'd block is requested, we also list any relevant transactions
// in the blocks of the chain that was detached
UniValue removed ( UniValue : : VARR ) ;
while ( include_removed & & paltindex & & paltindex ! = pindex ) {
CBlock block ;
if ( ! ReadBlockFromDisk ( block , paltindex , Params ( ) . GetConsensus ( ) ) ) {
throw JSONRPCError ( RPC_INTERNAL_ERROR , " Can't read block from disk " ) ;
}
for ( const CTransactionRef & tx : block . vtx ) {
if ( pwallet - > mapWallet . count ( tx - > GetHash ( ) ) > 0 ) {
// We want all transactions regardless of confirmation count to appear here,
// even negative confirmation ones, hence the big negative.
ListTransactions ( pwallet , pwallet - > mapWallet [ tx - > GetHash ( ) ] , " * " , - 100000000 , true , removed , filter ) ;
}
}
paltindex = paltindex - > pprev ;
2012-08-21 16:38:57 +02:00
}
2013-10-10 23:07:44 +02:00
CBlockIndex * pblockLast = chainActive [ chainActive . Height ( ) + 1 - target_confirms ] ;
2014-12-15 09:11:16 +01:00
uint256 lastblock = pblockLast ? pblockLast - > GetBlockHash ( ) : uint256 ( ) ;
2012-08-21 16:38:57 +02:00
2015-05-10 14:48:35 +02:00
UniValue ret ( UniValue : : VOBJ ) ;
2012-08-21 16:38:57 +02:00
ret . push_back ( Pair ( " transactions " , transactions ) ) ;
2017-01-24 06:27:22 +01:00
if ( include_removed ) ret . push_back ( Pair ( " removed " , removed ) ) ;
2012-08-21 16:38:57 +02:00
ret . push_back ( Pair ( " lastblock " , lastblock . GetHex ( ) ) ) ;
return ret ;
}
2016-09-22 09:46:41 +02:00
UniValue gettransaction ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) < 1 | | request . params . size ( ) > 2 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2016-11-21 14:32:36 +01:00
" gettransaction \" txid \" ( include_watchonly ) \n "
2013-10-29 12:29:44 +01:00
" \n Get detailed information about in-wallet transaction <txid> \n "
" \n Arguments: \n "
2016-12-09 18:06:42 +01:00
" 1. \" txid \" (string, required) The transaction id \n "
2017-01-11 14:29:46 +01:00
" 2. \" include_watchonly \" (bool, optional, default=false) Whether to include watch-only addresses in balance calculation and details[] \n "
2013-10-29 12:29:44 +01:00
" \n Result: \n "
" { \n "
2015-08-01 21:15:23 +02:00
" \" amount \" : x.xxx, (numeric) The transaction amount in " + CURRENCY_UNIT + " \n "
2017-01-11 14:29:46 +01:00
" \" fee \" : x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + " . This is negative and only available for the \n "
" 'send' category of transactions. \n "
2013-10-29 12:29:44 +01:00
" \" confirmations \" : n, (numeric) The number of confirmations \n "
" \" blockhash \" : \" hash \" , (string) The block hash \n "
2016-02-16 20:42:14 +01:00
" \" blockindex \" : xx, (numeric) The index of the transaction in the block that includes it \n "
2013-10-29 12:29:44 +01:00
" \" blocktime \" : ttt, (numeric) The time in seconds since epoch (1 Jan 1970 GMT) \n "
2014-05-29 18:17:34 +02:00
" \" txid \" : \" transactionid \" , (string) The transaction id. \n "
2013-10-29 12:29:44 +01:00
" \" time \" : ttt, (numeric) The transaction time in seconds since epoch (1 Jan 1970 GMT) \n "
" \" timereceived \" : ttt, (numeric) The time received in seconds since epoch (1 Jan 1970 GMT) \n "
2017-01-11 14:29:46 +01:00
" \" bip125-replaceable \" : \" yes|no|unknown \" , (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee); \n "
2015-12-16 20:57:54 +01:00
" may be unknown for unconfirmed transactions not in the mempool \n "
2013-10-29 12:29:44 +01:00
" \" details \" : [ \n "
" { \n "
2017-01-11 14:29:46 +01:00
" \" account \" : \" accountname \" , (string) DEPRECATED. The account name involved in the transaction, can be \" \" for the default account. \n "
" \" address \" : \" address \" , (string) The bitcoin address involved in the transaction \n "
2013-10-29 12:29:44 +01:00
" \" category \" : \" send|receive \" , (string) The category, either 'send' or 'receive' \n "
2014-12-30 15:12:37 +01:00
" \" amount \" : x.xxx, (numeric) The amount in " + CURRENCY_UNIT + " \n "
" \" label \" : \" label \" , (string) A comment for the address/transaction, if any \n "
2014-05-30 00:54:00 +02:00
" \" vout \" : n, (numeric) the vout value \n "
2017-01-11 14:29:46 +01:00
" \" fee \" : x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + " . This is negative and only available for the \n "
" 'send' category of transactions. \n "
" \" abandoned \" : xxx (bool) 'true' if the transaction has been abandoned (inputs are respendable). Only available for the \n "
2017-01-16 09:00:23 +01:00
" 'send' category of transactions. \n "
2013-10-29 12:29:44 +01:00
" } \n "
" ,... \n "
2014-02-13 17:28:32 +01:00
" ], \n "
" \" hex \" : \" data \" (string) Raw data for transaction \n "
2013-10-29 12:29:44 +01:00
" } \n "
2014-08-09 06:13:06 +02:00
" \n Examples: \n "
2013-10-29 12:29:44 +01:00
+ HelpExampleCli ( " gettransaction " , " \" 1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d \" " )
2014-09-07 14:37:13 +02:00
+ HelpExampleCli ( " gettransaction " , " \" 1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d \" true " )
2013-10-29 12:29:44 +01:00
+ HelpExampleRpc ( " gettransaction " , " \" 1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d \" " )
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2012-08-21 16:38:57 +02:00
uint256 hash ;
2016-09-22 09:46:41 +02:00
hash . SetHex ( request . params [ 0 ] . get_str ( ) ) ;
2012-08-21 16:38:57 +02:00
2014-07-01 11:00:22 +02:00
isminefilter filter = ISMINE_SPENDABLE ;
2017-07-10 17:44:39 +02:00
if ( ! request . params [ 1 ] . isNull ( ) )
2016-09-22 09:46:41 +02:00
if ( request . params [ 1 ] . get_bool ( ) )
2014-07-01 11:00:22 +02:00
filter = filter | ISMINE_WATCH_ONLY ;
2014-05-23 00:58:15 +02:00
2015-05-10 14:48:35 +02:00
UniValue entry ( UniValue : : VOBJ ) ;
2016-10-25 10:04:23 +02:00
if ( ! pwallet - > mapWallet . count ( hash ) ) {
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Invalid or non-wallet transaction id " ) ;
2016-10-25 10:04:23 +02:00
}
2016-10-25 09:45:57 +02:00
const CWalletTx & wtx = pwallet - > mapWallet [ hash ] ;
2012-08-21 16:38:57 +02:00
2014-07-26 21:05:11 +02:00
CAmount nCredit = wtx . GetCredit ( filter ) ;
2014-04-23 00:46:19 +02:00
CAmount nDebit = wtx . GetDebit ( filter ) ;
CAmount nNet = nCredit - nDebit ;
2016-11-12 01:54:51 +01:00
CAmount nFee = ( wtx . IsFromMe ( filter ) ? wtx . tx - > GetValueOut ( ) - nDebit : 0 ) ;
2012-08-21 16:38:57 +02:00
entry . push_back ( Pair ( " amount " , ValueFromAmount ( nNet - nFee ) ) ) ;
2014-06-19 15:24:17 +02:00
if ( wtx . IsFromMe ( filter ) )
2012-08-21 16:38:57 +02:00
entry . push_back ( Pair ( " fee " , ValueFromAmount ( nFee ) ) ) ;
WalletTxToJSON ( wtx , entry ) ;
2015-05-10 14:48:35 +02:00
UniValue details ( UniValue : : VARR ) ;
2016-10-25 09:45:57 +02:00
ListTransactions ( pwallet , wtx , " * " , 0 , false , details , filter ) ;
2012-08-21 16:38:57 +02:00
entry . push_back ( Pair ( " details " , details ) ) ;
2017-01-27 02:33:45 +01:00
std : : string strHex = EncodeHexTx ( static_cast < CTransaction > ( wtx ) , RPCSerializationFlags ( ) ) ;
2014-02-13 17:28:32 +01:00
entry . push_back ( Pair ( " hex " , strHex ) ) ;
2012-08-21 16:38:57 +02:00
return entry ;
}
2016-09-22 09:46:41 +02:00
UniValue abandontransaction ( const JSONRPCRequest & request )
2016-01-07 22:31:27 +01:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2016-01-07 22:31:27 +01:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-07 22:31:27 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 1 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2016-01-07 22:31:27 +01:00
" abandontransaction \" txid \" \n "
" \n Mark in-wallet transaction <txid> as abandoned \n "
" This will mark this transaction and all its in-wallet descendants as abandoned which will allow \n "
" for their inputs to be respent. It can be used to replace \" stuck \" or evicted transactions. \n "
" It only works on transactions which are not included in a block and are not currently in the mempool. \n "
" It has no effect on transactions which are already conflicted or abandoned. \n "
" \n Arguments: \n "
" 1. \" txid \" (string, required) The transaction id \n "
" \n Result: \n "
" \n Examples: \n "
+ HelpExampleCli ( " abandontransaction " , " \" 1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d \" " )
+ HelpExampleRpc ( " abandontransaction " , " \" 1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d \" " )
) ;
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2016-01-07 22:31:27 +01:00
uint256 hash ;
2016-09-22 09:46:41 +02:00
hash . SetHex ( request . params [ 0 ] . get_str ( ) ) ;
2016-01-07 22:31:27 +01:00
2016-10-25 10:04:23 +02:00
if ( ! pwallet - > mapWallet . count ( hash ) ) {
2016-01-07 22:31:27 +01:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Invalid or non-wallet transaction id " ) ;
2016-10-25 10:04:23 +02:00
}
if ( ! pwallet - > AbandonTransaction ( hash ) ) {
2016-01-07 22:31:27 +01:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Transaction not eligible for abandonment " ) ;
2016-10-25 10:04:23 +02:00
}
2016-01-07 22:31:27 +01:00
return NullUniValue ;
}
2012-08-21 16:38:57 +02:00
2016-09-22 09:46:41 +02:00
UniValue backupwallet ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 1 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2013-10-29 12:29:44 +01:00
" backupwallet \" destination \" \n "
2016-02-26 12:48:53 +01:00
" \n Safely copies current wallet file to destination, which can be a directory or a path with filename. \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
" 1. \" destination \" (string) The destination directory or file \n "
" \n Examples: \n "
+ HelpExampleCli ( " backupwallet " , " \" backup.dat \" " )
+ HelpExampleRpc ( " backupwallet " , " \" backup.dat \" " )
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2017-01-27 02:33:45 +01:00
std : : string strDest = request . params [ 0 ] . get_str ( ) ;
2016-10-25 10:04:23 +02:00
if ( ! pwallet - > BackupWallet ( strDest ) ) {
2012-11-27 16:27:54 +01:00
throw JSONRPCError ( RPC_WALLET_ERROR , " Error: Wallet backup failed! " ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
2014-08-20 21:15:16 +02:00
return NullUniValue ;
2012-08-21 16:38:57 +02:00
}
2016-09-22 09:46:41 +02:00
UniValue keypoolrefill ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) > 1 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2013-10-29 12:29:44 +01:00
" keypoolrefill ( newsize ) \n "
" \n Fills the keypool. "
2016-10-25 09:45:57 +02:00
+ HelpRequiringPassphrase ( pwallet ) + " \n "
2013-10-29 12:29:44 +01:00
" \n Arguments \n "
" 1. newsize (numeric, optional, default=100) The new keypool size \n "
" \n Examples: \n "
+ HelpExampleCli ( " keypoolrefill " , " " )
+ HelpExampleRpc ( " keypoolrefill " , " " )
) ;
2012-08-21 16:38:57 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2013-10-28 11:58:39 +01:00
// 0 is interpreted by TopUpKeyPool() as the default keypool size given by -keypool
unsigned int kpSize = 0 ;
2017-07-10 17:44:39 +02:00
if ( ! request . params [ 0 ] . isNull ( ) ) {
2016-09-22 09:46:41 +02:00
if ( request . params [ 0 ] . get_int ( ) < 0 )
2013-10-28 11:58:39 +01:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Invalid parameter, expected valid size. " ) ;
2016-09-22 09:46:41 +02:00
kpSize = ( unsigned int ) request . params [ 0 ] . get_int ( ) ;
2013-06-25 22:21:42 +02:00
}
2016-10-25 09:45:57 +02:00
EnsureWalletIsUnlocked ( pwallet ) ;
pwallet - > TopUpKeyPool ( kpSize ) ;
2012-08-21 16:38:57 +02:00
2016-10-25 10:04:23 +02:00
if ( pwallet - > GetKeyPoolSize ( ) < kpSize ) {
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_ERROR , " Error refreshing keypool. " ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
2014-08-20 21:15:16 +02:00
return NullUniValue ;
2012-08-21 16:38:57 +02:00
}
2013-05-07 16:47:00 +02:00
static void LockWallet ( CWallet * pWallet )
2012-08-21 16:38:57 +02:00
{
2016-09-09 09:48:10 +02:00
LOCK ( pWallet - > cs_wallet ) ;
pWallet - > nRelockTime = 0 ;
2013-05-07 16:47:00 +02:00
pWallet - > Lock ( ) ;
2012-08-21 16:38:57 +02:00
}
2016-09-22 09:46:41 +02:00
UniValue walletpassphrase ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-10-25 10:04:23 +02:00
if ( pwallet - > IsCrypted ( ) & & ( request . fHelp | | request . params . size ( ) ! = 2 ) ) {
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2013-10-29 12:29:44 +01:00
" walletpassphrase \" passphrase \" timeout \n "
" \n Stores the wallet decryption key in memory for 'timeout' seconds. \n "
" This is needed prior to performing transactions related to private keys such as sending bitcoins \n "
" \n Arguments: \n "
" 1. \" passphrase \" (string, required) The wallet passphrase \n "
" 2. timeout (numeric, required) The time to keep the decryption key in seconds. \n "
2014-02-16 10:23:59 +01:00
" \n Note: \n "
" Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock \n "
" time that overrides the old one. \n "
2013-10-29 12:29:44 +01:00
" \n Examples: \n "
2017-07-19 22:50:26 +02:00
" \n Unlock the wallet for 60 seconds \n "
2013-10-29 12:29:44 +01:00
+ HelpExampleCli ( " walletpassphrase " , " \" my pass phrase \" 60 " ) +
" \n Lock the wallet again (before 60 seconds) \n "
+ HelpExampleCli ( " walletlock " , " " ) +
" \n As json rpc call \n "
+ HelpExampleRpc ( " walletpassphrase " , " \" my pass phrase \" , 60 " )
) ;
2016-10-25 10:04:23 +02:00
}
2013-10-29 12:29:44 +01:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp )
2012-08-21 16:38:57 +02:00
return true ;
2016-10-25 10:04:23 +02:00
if ( ! pwallet - > IsCrypted ( ) ) {
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_WRONG_ENC_STATE , " Error: running with an unencrypted wallet, but walletpassphrase was called. " ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
2016-09-22 09:46:41 +02:00
// Note that the walletpassphrase is stored in request.params[0] which is not mlock()ed
2012-08-21 16:38:57 +02:00
SecureString strWalletPass ;
strWalletPass . reserve ( 100 ) ;
// TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
2016-09-22 09:46:41 +02:00
// Alternately, find a way to make request.params[0] mlock()'d to begin with.
strWalletPass = request . params [ 0 ] . get_str ( ) . c_str ( ) ;
2012-08-21 16:38:57 +02:00
if ( strWalletPass . length ( ) > 0 )
{
2016-10-25 10:04:23 +02:00
if ( ! pwallet - > Unlock ( strWalletPass ) ) {
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_PASSPHRASE_INCORRECT , " Error: The wallet passphrase entered was incorrect. " ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
}
else
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2012-08-21 16:38:57 +02:00
" walletpassphrase <passphrase> <timeout> \n "
" Stores the wallet decryption key in memory for <timeout> seconds. " ) ;
2016-10-25 09:45:57 +02:00
pwallet - > TopUpKeyPool ( ) ;
2013-05-07 16:47:00 +02:00
2016-09-22 09:46:41 +02:00
int64_t nSleepTime = request . params [ 1 ] . get_int64 ( ) ;
2016-09-09 09:48:10 +02:00
pwallet - > nRelockTime = GetTime ( ) + nSleepTime ;
2017-03-08 11:48:58 +01:00
RPCRunLater ( strprintf ( " lockwallet(%s) " , pwallet - > GetName ( ) ) , boost : : bind ( LockWallet , pwallet ) , nSleepTime ) ;
2012-08-21 16:38:57 +02:00
2014-08-20 21:15:16 +02:00
return NullUniValue ;
2012-08-21 16:38:57 +02:00
}
2016-09-22 09:46:41 +02:00
UniValue walletpassphrasechange ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-10-25 10:04:23 +02:00
if ( pwallet - > IsCrypted ( ) & & ( request . fHelp | | request . params . size ( ) ! = 2 ) ) {
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2013-10-29 12:29:44 +01:00
" walletpassphrasechange \" oldpassphrase \" \" newpassphrase \" \n "
" \n Changes the wallet passphrase from 'oldpassphrase' to 'newpassphrase'. \n "
" \n Arguments: \n "
" 1. \" oldpassphrase \" (string) The current passphrase \n "
" 2. \" newpassphrase \" (string) The new passphrase \n "
" \n Examples: \n "
+ HelpExampleCli ( " walletpassphrasechange " , " \" old one \" \" new one \" " )
+ HelpExampleRpc ( " walletpassphrasechange " , " \" old one \" , \" new one \" " )
) ;
2016-10-25 10:04:23 +02:00
}
2013-10-29 12:29:44 +01:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp )
2012-08-21 16:38:57 +02:00
return true ;
2016-10-25 10:04:23 +02:00
if ( ! pwallet - > IsCrypted ( ) ) {
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_WRONG_ENC_STATE , " Error: running with an unencrypted wallet, but walletpassphrasechange was called. " ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
// TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string)
2016-09-22 09:46:41 +02:00
// Alternately, find a way to make request.params[0] mlock()'d to begin with.
2012-08-21 16:38:57 +02:00
SecureString strOldWalletPass ;
strOldWalletPass . reserve ( 100 ) ;
2016-09-22 09:46:41 +02:00
strOldWalletPass = request . params [ 0 ] . get_str ( ) . c_str ( ) ;
2012-08-21 16:38:57 +02:00
SecureString strNewWalletPass ;
strNewWalletPass . reserve ( 100 ) ;
2016-09-22 09:46:41 +02:00
strNewWalletPass = request . params [ 1 ] . get_str ( ) . c_str ( ) ;
2012-08-21 16:38:57 +02:00
if ( strOldWalletPass . length ( ) < 1 | | strNewWalletPass . length ( ) < 1 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2012-08-21 16:38:57 +02:00
" walletpassphrasechange <oldpassphrase> <newpassphrase> \n "
" Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>. " ) ;
2016-10-25 10:04:23 +02:00
if ( ! pwallet - > ChangeWalletPassphrase ( strOldWalletPass , strNewWalletPass ) ) {
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_PASSPHRASE_INCORRECT , " Error: The wallet passphrase entered was incorrect. " ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
2014-08-20 21:15:16 +02:00
return NullUniValue ;
2012-08-21 16:38:57 +02:00
}
2016-09-22 09:46:41 +02:00
UniValue walletlock ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-10-25 10:04:23 +02:00
if ( pwallet - > IsCrypted ( ) & & ( request . fHelp | | request . params . size ( ) ! = 0 ) ) {
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2012-08-21 16:38:57 +02:00
" walletlock \n "
2013-10-29 12:29:44 +01:00
" \n Removes the wallet encryption key from memory, locking the wallet. \n "
2012-08-21 16:38:57 +02:00
" After calling this method, you will need to call walletpassphrase again \n "
2013-10-29 12:29:44 +01:00
" before being able to call any methods which require the wallet to be unlocked. \n "
" \n Examples: \n "
" \n Set the passphrase for 2 minutes to perform a transaction \n "
+ HelpExampleCli ( " walletpassphrase " , " \" my pass phrase \" 120 " ) +
" \n Perform a send (requires passphrase set) \n "
+ HelpExampleCli ( " sendtoaddress " , " \" 1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd \" 1.0 " ) +
" \n Clear the passphrase since we are done before 2 minutes is up \n "
+ HelpExampleCli ( " walletlock " , " " ) +
" \n As json rpc call \n "
+ HelpExampleRpc ( " walletlock " , " " )
) ;
2016-10-25 10:04:23 +02:00
}
2013-10-29 12:29:44 +01:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp )
2012-08-21 16:38:57 +02:00
return true ;
2016-10-25 10:04:23 +02:00
if ( ! pwallet - > IsCrypted ( ) ) {
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_WRONG_ENC_STATE , " Error: running with an unencrypted wallet, but walletlock was called. " ) ;
2012-08-21 16:38:57 +02:00
}
2016-09-09 09:48:10 +02:00
pwallet - > Lock ( ) ;
pwallet - > nRelockTime = 0 ;
2012-08-21 16:38:57 +02:00
2014-08-20 21:15:16 +02:00
return NullUniValue ;
2012-08-21 16:38:57 +02:00
}
2016-09-22 09:46:41 +02:00
UniValue encryptwallet ( const JSONRPCRequest & request )
2012-08-21 16:38:57 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-10-25 10:04:23 +02:00
if ( ! pwallet - > IsCrypted ( ) & & ( request . fHelp | | request . params . size ( ) ! = 1 ) ) {
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2013-10-29 12:29:44 +01:00
" encryptwallet \" passphrase \" \n "
" \n Encrypts the wallet with 'passphrase'. This is for first time encryption. \n "
" After this, any calls that interact with private keys such as sending or signing \n "
" will require the passphrase to be set prior the making these calls. \n "
" Use the walletpassphrase call for this, and then walletlock call. \n "
" If the wallet is already encrypted, use the walletpassphrasechange call. \n "
" Note that this will shutdown the server. \n "
" \n Arguments: \n "
" 1. \" passphrase \" (string) The pass phrase to encrypt the wallet with. It must be at least 1 character, but should be long. \n "
" \n Examples: \n "
2017-07-19 22:50:26 +02:00
" \n Encrypt your wallet \n "
2013-10-29 12:29:44 +01:00
+ HelpExampleCli ( " encryptwallet " , " \" my pass phrase \" " ) +
" \n Now set the passphrase to use the wallet, such as for signing or sending bitcoin \n "
+ HelpExampleCli ( " walletpassphrase " , " \" my pass phrase \" " ) +
2017-07-19 22:50:26 +02:00
" \n Now we can do something like sign \n "
2016-11-21 14:39:58 +01:00
+ HelpExampleCli ( " signmessage " , " \" address \" \" test message \" " ) +
2013-10-29 12:29:44 +01:00
" \n Now lock the wallet again by removing the passphrase \n "
+ HelpExampleCli ( " walletlock " , " " ) +
" \n As a json rpc call \n "
+ HelpExampleRpc ( " encryptwallet " , " \" my pass phrase \" " )
) ;
2016-10-25 10:04:23 +02:00
}
2013-10-29 12:29:44 +01:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp )
2012-08-21 16:38:57 +02:00
return true ;
2016-10-25 10:04:23 +02:00
if ( pwallet - > IsCrypted ( ) ) {
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_WRONG_ENC_STATE , " Error: running with an encrypted wallet, but encryptwallet was called. " ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
// TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
2016-09-22 09:46:41 +02:00
// Alternately, find a way to make request.params[0] mlock()'d to begin with.
2012-08-21 16:38:57 +02:00
SecureString strWalletPass ;
strWalletPass . reserve ( 100 ) ;
2016-09-22 09:46:41 +02:00
strWalletPass = request . params [ 0 ] . get_str ( ) . c_str ( ) ;
2012-08-21 16:38:57 +02:00
if ( strWalletPass . length ( ) < 1 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2012-08-21 16:38:57 +02:00
" encryptwallet <passphrase> \n "
" Encrypts the wallet with <passphrase>. " ) ;
2016-10-25 10:04:23 +02:00
if ( ! pwallet - > EncryptWallet ( strWalletPass ) ) {
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_ENCRYPTION_FAILED , " Error: Failed to encrypt the wallet. " ) ;
2016-10-25 10:04:23 +02:00
}
2012-08-21 16:38:57 +02:00
// BDB seems to have a bad habit of writing old data into
// slack space in .dat files; that is bad if the old data is
2012-08-23 14:19:13 +02:00
// unencrypted private keys. So:
2012-08-21 16:38:57 +02:00
StartShutdown ( ) ;
2016-07-21 21:19:02 +02:00
return " wallet encrypted; Bitcoin server stopping, restart to run with encrypted wallet. The keypool has been flushed and a new HD seed was generated (if you are using HD). You need to make a new backup. " ;
2012-08-21 16:38:57 +02:00
}
2016-09-22 09:46:41 +02:00
UniValue lockunspent ( const JSONRPCRequest & request )
2012-09-27 19:52:09 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) < 1 | | request . params . size ( ) > 2 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2016-03-23 16:44:18 +01:00
" lockunspent unlock ([{ \" txid \" : \" txid \" , \" vout \" :n},...]) \n "
2013-10-29 12:29:44 +01:00
" \n Updates list of temporarily unspendable outputs. \n "
2014-05-09 21:39:24 +02:00
" Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs. \n "
2016-03-23 16:44:18 +01:00
" If no transaction outputs are specified when unlocking then all current locked transaction outputs are unlocked. \n "
2013-10-29 12:29:44 +01:00
" A locked transaction output will not be chosen by automatic coin selection, when spending bitcoins. \n "
" Locks are stored in memory only. Nodes start with zero locked outputs, and the locked output list \n "
" is always cleared (by virtue of process exit) when a node stops or fails. \n "
" Also see the listunspent call \n "
" \n Arguments: \n "
" 1. unlock (boolean, required) Whether to unlock (true) or lock (false) the specified transactions \n "
2016-03-23 16:44:18 +01:00
" 2. \" transactions \" (string, optional) A json array of objects. Each object the txid (string) vout (numeric) \n "
2013-10-29 12:29:44 +01:00
" [ (json array of json objects) \n "
" { \n "
" \" txid \" : \" id \" , (string) The transaction id \n "
" \" vout \" : n (numeric) The output number \n "
" } \n "
" ,... \n "
" ] \n "
" \n Result: \n "
" true|false (boolean) Whether the command was successful or not \n "
" \n Examples: \n "
" \n List the unspent transactions \n "
+ HelpExampleCli ( " listunspent " , " " ) +
" \n Lock an unspent transaction \n "
+ HelpExampleCli ( " lockunspent " , " false \" [{ \\ \" txid \\ \" : \\ \" a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0 \\ \" , \\ \" vout \\ \" :1}] \" " ) +
" \n List the locked transactions \n "
+ HelpExampleCli ( " listlockunspent " , " " ) +
" \n Unlock the transaction again \n "
+ HelpExampleCli ( " lockunspent " , " true \" [{ \\ \" txid \\ \" : \\ \" a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0 \\ \" , \\ \" vout \\ \" :1}] \" " ) +
" \n As a json rpc call \n "
+ HelpExampleRpc ( " lockunspent " , " false, \" [{ \\ \" txid \\ \" : \\ \" a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0 \\ \" , \\ \" vout \\ \" :1}] \" " )
) ;
2012-09-27 19:52:09 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2016-09-22 09:46:41 +02:00
if ( request . params . size ( ) = = 1 )
2017-06-06 21:15:28 +02:00
RPCTypeCheck ( request . params , { UniValue : : VBOOL } ) ;
2012-09-27 19:52:09 +02:00
else
2017-06-06 21:15:28 +02:00
RPCTypeCheck ( request . params , { UniValue : : VBOOL , UniValue : : VARR } ) ;
2012-09-27 19:52:09 +02:00
2016-09-22 09:46:41 +02:00
bool fUnlock = request . params [ 0 ] . get_bool ( ) ;
2012-09-27 19:52:09 +02:00
2016-09-22 09:46:41 +02:00
if ( request . params . size ( ) = = 1 ) {
2012-09-27 19:52:09 +02:00
if ( fUnlock )
2016-10-25 09:45:57 +02:00
pwallet - > UnlockAllCoins ( ) ;
2012-09-27 19:52:09 +02:00
return true ;
}
2016-09-22 09:46:41 +02:00
UniValue outputs = request . params [ 1 ] . get_array ( ) ;
2014-08-20 21:15:16 +02:00
for ( unsigned int idx = 0 ; idx < outputs . size ( ) ; idx + + ) {
const UniValue & output = outputs [ idx ] ;
if ( ! output . isObject ( ) )
2013-08-06 13:52:38 +02:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Invalid parameter, expected object " ) ;
2015-05-18 14:02:18 +02:00
const UniValue & o = output . get_obj ( ) ;
2012-09-27 19:52:09 +02:00
2016-06-06 17:50:50 +02:00
RPCTypeCheckObj ( o ,
{
{ " txid " , UniValueType ( UniValue : : VSTR ) } ,
{ " vout " , UniValueType ( UniValue : : VNUM ) } ,
} ) ;
2012-09-27 19:52:09 +02:00
2017-01-27 02:33:45 +01:00
std : : string txid = find_value ( o , " txid " ) . get_str ( ) ;
2012-09-27 19:52:09 +02:00
if ( ! IsHex ( txid ) )
2013-08-06 13:52:38 +02:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Invalid parameter, expected hex txid " ) ;
2012-09-27 19:52:09 +02:00
int nOutput = find_value ( o , " vout " ) . get_int ( ) ;
if ( nOutput < 0 )
2013-08-06 13:52:38 +02:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Invalid parameter, vout must be positive " ) ;
2012-09-27 19:52:09 +02:00
2014-12-16 14:50:05 +01:00
COutPoint outpt ( uint256S ( txid ) , nOutput ) ;
2012-09-27 19:52:09 +02:00
if ( fUnlock )
2016-10-25 09:45:57 +02:00
pwallet - > UnlockCoin ( outpt ) ;
2012-09-27 19:52:09 +02:00
else
2016-10-25 09:45:57 +02:00
pwallet - > LockCoin ( outpt ) ;
2012-09-27 19:52:09 +02:00
}
return true ;
}
2016-09-22 09:46:41 +02:00
UniValue listlockunspent ( const JSONRPCRequest & request )
2012-09-27 19:52:09 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) > 0 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2012-09-27 19:52:09 +02:00
" listlockunspent \n "
2013-10-29 12:29:44 +01:00
" \n Returns list of temporarily unspendable outputs. \n "
" See the lockunspent call to lock and unlock transactions for spending. \n "
" \n Result: \n "
" [ \n "
" { \n "
" \" txid \" : \" transactionid \" , (string) The transaction id locked \n "
" \" vout \" : n (numeric) The vout value \n "
" } \n "
" ,... \n "
" ] \n "
" \n Examples: \n "
" \n List the unspent transactions \n "
+ HelpExampleCli ( " listunspent " , " " ) +
" \n Lock an unspent transaction \n "
+ HelpExampleCli ( " lockunspent " , " false \" [{ \\ \" txid \\ \" : \\ \" a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0 \\ \" , \\ \" vout \\ \" :1}] \" " ) +
" \n List the locked transactions \n "
+ HelpExampleCli ( " listlockunspent " , " " ) +
" \n Unlock the transaction again \n "
+ HelpExampleCli ( " lockunspent " , " true \" [{ \\ \" txid \\ \" : \\ \" a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0 \\ \" , \\ \" vout \\ \" :1}] \" " ) +
" \n As a json rpc call \n "
+ HelpExampleRpc ( " listlockunspent " , " " )
) ;
2012-09-27 19:52:09 +02:00
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2017-01-27 02:33:45 +01:00
std : : vector < COutPoint > vOutpts ;
2016-10-25 09:45:57 +02:00
pwallet - > ListLockedCoins ( vOutpts ) ;
2012-09-27 19:52:09 +02:00
2015-05-10 14:48:35 +02:00
UniValue ret ( UniValue : : VARR ) ;
2012-09-27 19:52:09 +02:00
2017-06-02 03:18:57 +02:00
for ( COutPoint & outpt : vOutpts ) {
2015-05-10 14:48:35 +02:00
UniValue o ( UniValue : : VOBJ ) ;
2012-09-27 19:52:09 +02:00
o . push_back ( Pair ( " txid " , outpt . hash . GetHex ( ) ) ) ;
o . push_back ( Pair ( " vout " , ( int ) outpt . n ) ) ;
ret . push_back ( o ) ;
}
return ret ;
}
2016-09-22 09:46:41 +02:00
UniValue settxfee ( const JSONRPCRequest & request )
2013-12-13 16:06:32 +01:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) < 1 | | request . params . size ( ) > 1 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2013-12-13 16:06:32 +01:00
" settxfee amount \n "
2015-09-14 17:42:05 +02:00
" \n Set the transaction fee per kB. Overwrites the paytxfee parameter. \n "
2013-12-13 16:06:32 +01:00
" \n Arguments: \n "
2016-05-10 17:54:34 +02:00
" 1. amount (numeric or string, required) The transaction fee in " + CURRENCY_UNIT + " /kB \n "
2013-12-13 16:06:32 +01:00
" \n Result \n "
" true|false (boolean) Returns true if successful \n "
" \n Examples: \n "
+ HelpExampleCli ( " settxfee " , " 0.00001 " )
+ HelpExampleRpc ( " settxfee " , " 0.00001 " )
) ;
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2013-12-13 16:06:32 +01:00
// Amount
2016-09-22 09:46:41 +02:00
CAmount nAmount = AmountFromValue ( request . params [ 0 ] ) ;
2013-12-13 16:06:32 +01:00
2014-04-10 20:14:18 +02:00
payTxFee = CFeeRate ( nAmount , 1000 ) ;
2013-12-13 16:06:32 +01:00
return true ;
}
2016-09-22 09:46:41 +02:00
UniValue getwalletinfo ( const JSONRPCRequest & request )
2014-02-21 05:56:04 +01:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 0 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2014-02-21 05:56:04 +01:00
" getwalletinfo \n "
" Returns an object containing various wallet state info. \n "
" \n Result: \n "
" { \n "
2017-06-15 17:45:08 +02:00
" \" walletname \" : xxxxx, (string) the wallet name \n "
2017-01-10 16:45:30 +01:00
" \" walletversion \" : xxxxx, (numeric) the wallet version \n "
" \" balance \" : xxxxxxx, (numeric) the total confirmed balance of the wallet in " + CURRENCY_UNIT + " \n "
" \" unconfirmed_balance \" : xxx, (numeric) the total unconfirmed balance of the wallet in " + CURRENCY_UNIT + " \n "
" \" immature_balance \" : xxxxxx, (numeric) the total immature balance of the wallet in " + CURRENCY_UNIT + " \n "
" \" txcount \" : xxxxxxx, (numeric) the total number of transactions in the wallet \n "
" \" keypoololdest \" : xxxxxx, (numeric) the timestamp (seconds since Unix epoch) of the oldest pre-generated key in the key pool \n "
2017-01-17 08:55:30 +01:00
" \" keypoolsize \" : xxxx, (numeric) how many new keys are pre-generated (only counts external keys) \n "
2017-01-17 15:50:11 +01:00
" \" keypoolsize_hd_internal \" : xxxx, (numeric) how many new keys are pre-generated for internal use (used for change outputs, only appears if the wallet is using this feature, otherwise external keys are used) \n "
2017-01-10 16:45:30 +01:00
" \" 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 "
" \" paytxfee \" : x.xxxx, (numeric) the transaction fee configuration, set in " + CURRENCY_UNIT + " /kB \n "
" \" hdmasterkeyid \" : \" <hash160> \" (string) the Hash160 of the HD master pubkey \n "
2014-02-21 05:56:04 +01:00
" } \n "
" \n Examples: \n "
+ HelpExampleCli ( " getwalletinfo " , " " )
+ HelpExampleRpc ( " getwalletinfo " , " " )
) ;
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2014-10-19 10:46:17 +02:00
2015-05-10 14:48:35 +02:00
UniValue obj ( UniValue : : VOBJ ) ;
2017-01-26 20:52:57 +01:00
2017-03-28 09:18:20 +02:00
size_t kpExternalSize = pwallet - > KeypoolCountExternalKeys ( ) ;
2017-06-15 17:45:08 +02:00
obj . push_back ( Pair ( " walletname " , pwallet - > GetName ( ) ) ) ;
2016-10-25 09:45:57 +02:00
obj . push_back ( Pair ( " walletversion " , pwallet - > GetVersion ( ) ) ) ;
obj . push_back ( Pair ( " balance " , ValueFromAmount ( pwallet - > GetBalance ( ) ) ) ) ;
obj . push_back ( Pair ( " unconfirmed_balance " , ValueFromAmount ( pwallet - > GetUnconfirmedBalance ( ) ) ) ) ;
obj . push_back ( Pair ( " immature_balance " , ValueFromAmount ( pwallet - > GetImmatureBalance ( ) ) ) ) ;
obj . push_back ( Pair ( " txcount " , ( int ) pwallet - > mapWallet . size ( ) ) ) ;
obj . push_back ( Pair ( " keypoololdest " , pwallet - > GetOldestKeyPoolTime ( ) ) ) ;
2017-01-10 16:45:30 +01:00
obj . push_back ( Pair ( " keypoolsize " , ( int64_t ) kpExternalSize ) ) ;
CKeyID masterKeyID = pwallet - > GetHDChain ( ) . masterKeyID ;
2017-01-17 15:50:11 +01:00
if ( ! masterKeyID . IsNull ( ) & & pwallet - > CanSupportFeature ( FEATURE_HD_SPLIT ) ) {
2017-01-10 16:45:30 +01:00
obj . push_back ( Pair ( " keypoolsize_hd_internal " , ( int64_t ) ( pwallet - > GetKeyPoolSize ( ) - kpExternalSize ) ) ) ;
}
2016-10-25 10:04:23 +02:00
if ( pwallet - > IsCrypted ( ) ) {
2016-09-09 09:48:10 +02:00
obj . push_back ( Pair ( " unlocked_until " , pwallet - > nRelockTime ) ) ;
2016-10-25 10:04:23 +02:00
}
2015-06-11 22:12:34 +02:00
obj . push_back ( Pair ( " paytxfee " , ValueFromAmount ( payTxFee . GetFeePerK ( ) ) ) ) ;
2016-07-09 11:25:02 +02:00
if ( ! masterKeyID . IsNull ( ) )
2016-07-21 21:52:30 +02:00
obj . push_back ( Pair ( " hdmasterkeyid " , masterKeyID . GetHex ( ) ) ) ;
2014-02-21 05:56:04 +01:00
return obj ;
}
2015-03-23 18:47:18 +01:00
2017-06-27 15:46:55 +02:00
UniValue listwallets ( const JSONRPCRequest & request )
{
if ( request . fHelp | | request . params . size ( ) ! = 0 )
throw std : : runtime_error (
" listwallets \n "
" Returns a list of currently loaded wallets. \n "
" For full information on the wallet, use \" getwalletinfo \" \n "
" \n Result: \n "
" [ (json array of strings) \n "
" \" walletname \" (string) the wallet name \n "
" ... \n "
" ] \n "
" \n Examples: \n "
+ HelpExampleCli ( " listwallets " , " " )
+ HelpExampleRpc ( " listwallets " , " " )
) ;
UniValue obj ( UniValue : : VARR ) ;
for ( CWalletRef pwallet : vpwallets ) {
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
return NullUniValue ;
}
LOCK ( pwallet - > cs_wallet ) ;
obj . push_back ( pwallet - > GetName ( ) ) ;
}
return obj ;
}
2016-09-22 09:46:41 +02:00
UniValue resendwallettransactions ( const JSONRPCRequest & request )
2015-03-23 18:47:18 +01:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2016-09-22 09:46:41 +02:00
if ( request . fHelp | | request . params . size ( ) ! = 0 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2015-03-23 18:47:18 +01:00
" resendwallettransactions \n "
" Immediately re-broadcast unconfirmed wallet transactions to all peers. \n "
" Intended only for testing; the wallet code periodically re-broadcasts \n "
" automatically. \n "
2017-08-05 19:48:37 +02:00
" Returns an RPC error if -walletbroadcast is set to false. \n "
2015-03-23 18:47:18 +01:00
" Returns array of transaction ids that were re-broadcast. \n "
) ;
2016-05-25 02:56:17 +02:00
if ( ! g_connman )
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2015-03-23 18:47:18 +01:00
2017-08-05 19:48:37 +02:00
if ( ! pwallet - > GetBroadcastTransactions ( ) ) {
2017-08-07 21:50:01 +02:00
throw JSONRPCError ( RPC_WALLET_ERROR , " Error: Wallet transaction broadcasting is disabled with -walletbroadcast " ) ;
2017-08-05 19:48:37 +02:00
}
2016-10-25 09:45:57 +02:00
std : : vector < uint256 > txids = pwallet - > ResendWalletTransactionsBefore ( GetTime ( ) , g_connman . get ( ) ) ;
2015-05-10 14:48:35 +02:00
UniValue result ( UniValue : : VARR ) ;
2017-06-02 03:18:57 +02:00
for ( const uint256 & txid : txids )
2015-03-23 18:47:18 +01:00
{
result . push_back ( txid . ToString ( ) ) ;
}
return result ;
}
2015-04-12 17:56:32 +02:00
2016-09-22 09:46:41 +02:00
UniValue listunspent ( const JSONRPCRequest & request )
2015-04-12 17:56:32 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2016-01-15 01:55:17 +01:00
2017-03-07 19:17:32 +01:00
if ( request . fHelp | | request . params . size ( ) > 5 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2017-03-07 19:17:32 +01:00
" listunspent ( minconf maxconf [ \" addresses \" ,...] [include_unsafe] [query_options]) \n "
2015-04-13 15:04:08 +02:00
" \n Returns array of unspent transaction outputs \n "
" with between minconf and maxconf (inclusive) confirmations. \n "
" Optionally filter to only include txouts paid to specified addresses. \n "
" \n Arguments: \n "
" 1. minconf (numeric, optional, default=1) The minimum confirmations to filter \n "
" 2. maxconf (numeric, optional, default=9999999) The maximum confirmations to filter \n "
2017-03-07 19:17:32 +01:00
" 3. \" addresses \" (string) A json array of bitcoin addresses to filter \n "
2015-04-13 15:04:08 +02:00
" [ \n "
2017-03-07 19:17:32 +01:00
" \" address \" (string) bitcoin address \n "
2015-04-13 15:04:08 +02:00
" ,... \n "
" ] \n "
2017-01-17 16:40:41 +01:00
" 4. include_unsafe (bool, optional, default=true) Include outputs that are not safe to spend \n "
2017-02-23 06:58:31 +01:00
" See description of \" safe \" attribute below. \n "
2017-03-07 19:17:32 +01:00
" 5. query_options (json, optional) JSON with query options \n "
" { \n "
" \" minimumAmount \" (numeric or string, default=0) Minimum value of each UTXO in " + CURRENCY_UNIT + " \n "
" \" maximumAmount \" (numeric or string, default=unlimited) Maximum value of each UTXO in " + CURRENCY_UNIT + " \n "
" \" maximumCount \" (numeric or string, default=unlimited) Maximum number of UTXOs \n "
" \" minimumSumAmount \" (numeric or string, default=unlimited) Minimum sum value of all UTXOs in " + CURRENCY_UNIT + " \n "
" } \n "
2015-04-13 15:04:08 +02:00
" \n Result \n "
" [ (array of json object) \n "
" { \n "
2016-03-08 11:37:18 +01:00
" \" txid \" : \" txid \" , (string) the transaction id \n "
2015-04-13 15:04:08 +02:00
" \" vout \" : n, (numeric) the vout value \n "
2016-03-08 11:37:18 +01:00
" \" address \" : \" address \" , (string) the bitcoin address \n "
" \" account \" : \" account \" , (string) DEPRECATED. The associated account, or \" \" for the default account \n "
" \" scriptPubKey \" : \" key \" , (string) the script key \n "
2017-02-01 18:18:31 +01:00
" \" amount \" : x.xxx, (numeric) the transaction output amount in " + CURRENCY_UNIT + " \n "
2016-03-14 19:22:11 +01:00
" \" confirmations \" : n, (numeric) The number of confirmations \n "
2016-03-08 11:37:18 +01:00
" \" redeemScript \" : n (string) The redeemScript if scriptPubKey is P2SH \n "
2016-03-14 19:22:11 +01:00
" \" spendable \" : xxx, (bool) Whether we have the private keys to spend this output \n "
2017-02-23 06:58:31 +01:00
" \" solvable \" : xxx, (bool) Whether we know how to spend this output, ignoring the lack of keys \n "
" \" safe \" : xxx (bool) Whether this output is considered safe to spend. Unconfirmed transactions \n "
" from outside keys and unconfirmed replacement transactions are considered unsafe \n "
" and are not eligible for spending by fundrawtransaction and sendtoaddress. \n "
2015-04-13 15:04:08 +02:00
" } \n "
" ,... \n "
" ] \n "
" \n Examples \n "
+ HelpExampleCli ( " listunspent " , " " )
+ HelpExampleCli ( " listunspent " , " 6 9999999 \" [ \\ \" 1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg \\ \" , \\ \" 1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP \\ \" ] \" " )
+ HelpExampleRpc ( " listunspent " , " 6, 9999999 \" [ \\ \" 1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg \\ \" , \\ \" 1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP \\ \" ] \" " )
2017-03-07 19:17:32 +01:00
+ HelpExampleCli ( " listunspent " , " 6 9999999 '[]' true '{ \" minimumAmount \" : 0.005 }' " )
+ HelpExampleRpc ( " listunspent " , " 6, 9999999, [] , true, { \" minimumAmount \" : 0.005 } " )
2015-04-13 15:04:08 +02:00
) ;
2015-04-12 17:56:32 +02:00
int nMinDepth = 1 ;
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 0 ] . isNull ( ) ) {
2017-01-17 16:40:41 +01:00
RPCTypeCheckArgument ( request . params [ 0 ] , UniValue : : VNUM ) ;
2016-09-22 09:46:41 +02:00
nMinDepth = request . params [ 0 ] . get_int ( ) ;
2017-01-17 16:40:41 +01:00
}
2015-04-13 15:04:08 +02:00
2015-04-12 17:56:32 +02:00
int nMaxDepth = 9999999 ;
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 1 ] . isNull ( ) ) {
2017-01-17 16:40:41 +01:00
RPCTypeCheckArgument ( request . params [ 1 ] , UniValue : : VNUM ) ;
2016-09-22 09:46:41 +02:00
nMaxDepth = request . params [ 1 ] . get_int ( ) ;
2017-01-17 16:40:41 +01:00
}
2015-04-13 15:04:08 +02:00
2017-01-27 02:33:45 +01:00
std : : set < CBitcoinAddress > setAddress ;
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 2 ] . isNull ( ) ) {
2017-01-17 16:40:41 +01:00
RPCTypeCheckArgument ( request . params [ 2 ] , UniValue : : VARR ) ;
2016-09-22 09:46:41 +02:00
UniValue inputs = request . params [ 2 ] . get_array ( ) ;
2015-05-10 13:35:44 +02:00
for ( unsigned int idx = 0 ; idx < inputs . size ( ) ; idx + + ) {
2015-05-18 14:02:18 +02:00
const UniValue & input = inputs [ idx ] ;
2015-04-12 17:56:32 +02:00
CBitcoinAddress address ( input . get_str ( ) ) ;
if ( ! address . IsValid ( ) )
2017-01-27 02:33:45 +01:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , std : : string ( " Invalid Bitcoin address: " ) + input . get_str ( ) ) ;
2015-04-12 17:56:32 +02:00
if ( setAddress . count ( address ) )
2017-01-27 02:33:45 +01:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , std : : string ( " Invalid parameter, duplicated address: " ) + input . get_str ( ) ) ;
2015-04-13 15:04:08 +02:00
setAddress . insert ( address ) ;
2015-04-12 17:56:32 +02:00
}
}
2015-04-13 15:04:08 +02:00
2017-01-17 16:40:41 +01:00
bool include_unsafe = true ;
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 3 ] . isNull ( ) ) {
2017-01-17 16:40:41 +01:00
RPCTypeCheckArgument ( request . params [ 3 ] , UniValue : : VBOOL ) ;
include_unsafe = request . params [ 3 ] . get_bool ( ) ;
}
2017-03-07 19:17:32 +01:00
CAmount nMinimumAmount = 0 ;
CAmount nMaximumAmount = MAX_MONEY ;
CAmount nMinimumSumAmount = MAX_MONEY ;
uint64_t nMaximumCount = 0 ;
2017-07-10 17:44:39 +02:00
if ( ! request . params [ 4 ] . isNull ( ) ) {
2017-03-07 19:17:32 +01:00
const UniValue & options = request . params [ 4 ] . get_obj ( ) ;
if ( options . exists ( " minimumAmount " ) )
nMinimumAmount = AmountFromValue ( options [ " minimumAmount " ] ) ;
if ( options . exists ( " maximumAmount " ) )
nMaximumAmount = AmountFromValue ( options [ " maximumAmount " ] ) ;
if ( options . exists ( " minimumSumAmount " ) )
nMinimumSumAmount = AmountFromValue ( options [ " minimumSumAmount " ] ) ;
if ( options . exists ( " maximumCount " ) )
nMaximumCount = options [ " maximumCount " ] . get_int64 ( ) ;
}
2015-05-10 14:48:35 +02:00
UniValue results ( UniValue : : VARR ) ;
2017-01-27 02:33:45 +01:00
std : : vector < COutput > vecOutputs ;
2017-08-07 07:36:37 +02:00
assert ( pwallet ! = nullptr ) ;
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
2015-04-13 15:04:08 +02:00
2017-08-07 07:36:37 +02:00
pwallet - > AvailableCoins ( vecOutputs , ! include_unsafe , nullptr , nMinimumAmount , nMaximumAmount , nMinimumSumAmount , nMaximumCount , nMinDepth , nMaxDepth ) ;
2017-06-02 03:18:57 +02:00
for ( const COutput & out : vecOutputs ) {
2016-03-08 11:37:18 +01:00
CTxDestination address ;
2016-11-12 01:54:51 +01:00
const CScript & scriptPubKey = out . tx - > tx - > vout [ out . i ] . scriptPubKey ;
2016-03-08 11:37:18 +01:00
bool fValidAddress = ExtractDestination ( scriptPubKey , address ) ;
2015-04-13 15:04:08 +02:00
2016-03-08 11:37:18 +01:00
if ( setAddress . size ( ) & & ( ! fValidAddress | | ! setAddress . count ( address ) ) )
continue ;
2015-04-13 15:04:08 +02:00
2015-05-10 14:48:35 +02:00
UniValue entry ( UniValue : : VOBJ ) ;
2015-04-12 17:56:32 +02:00
entry . push_back ( Pair ( " txid " , out . tx - > GetHash ( ) . GetHex ( ) ) ) ;
entry . push_back ( Pair ( " vout " , out . i ) ) ;
2016-03-08 11:37:18 +01:00
if ( fValidAddress ) {
2015-04-12 17:56:32 +02:00
entry . push_back ( Pair ( " address " , CBitcoinAddress ( address ) . ToString ( ) ) ) ;
2016-03-08 11:37:18 +01:00
2016-10-25 10:04:23 +02:00
if ( pwallet - > mapAddressBook . count ( address ) ) {
2016-10-25 09:45:57 +02:00
entry . push_back ( Pair ( " account " , pwallet - > mapAddressBook [ address ] . name ) ) ;
2016-10-25 10:04:23 +02:00
}
2016-03-08 11:37:18 +01:00
if ( scriptPubKey . IsPayToScriptHash ( ) ) {
2015-04-28 17:38:50 +02:00
const CScriptID & hash = boost : : get < CScriptID > ( address ) ;
2015-04-12 17:56:32 +02:00
CScript redeemScript ;
2016-10-25 10:04:23 +02:00
if ( pwallet - > GetCScript ( hash , redeemScript ) ) {
2015-04-13 15:04:08 +02:00
entry . push_back ( Pair ( " redeemScript " , HexStr ( redeemScript . begin ( ) , redeemScript . end ( ) ) ) ) ;
2016-10-25 10:04:23 +02:00
}
2015-04-12 17:56:32 +02:00
}
}
2016-03-08 11:37:18 +01:00
entry . push_back ( Pair ( " scriptPubKey " , HexStr ( scriptPubKey . begin ( ) , scriptPubKey . end ( ) ) ) ) ;
2016-11-12 01:54:51 +01:00
entry . push_back ( Pair ( " amount " , ValueFromAmount ( out . tx - > tx - > vout [ out . i ] . nValue ) ) ) ;
2016-03-08 11:37:18 +01:00
entry . push_back ( Pair ( " confirmations " , out . nDepth ) ) ;
2015-04-12 17:56:32 +02:00
entry . push_back ( Pair ( " spendable " , out . fSpendable ) ) ;
2016-03-14 19:22:11 +01:00
entry . push_back ( Pair ( " solvable " , out . fSolvable ) ) ;
2017-02-23 06:58:31 +01:00
entry . push_back ( Pair ( " safe " , out . fSafe ) ) ;
2015-04-12 17:56:32 +02:00
results . push_back ( entry ) ;
}
2015-04-13 15:04:08 +02:00
2015-04-12 17:56:32 +02:00
return results ;
2015-06-06 09:41:12 +02:00
}
2015-04-25 03:27:30 +02:00
2016-09-22 09:46:41 +02:00
UniValue fundrawtransaction ( const JSONRPCRequest & request )
2015-04-25 03:27:30 +02:00
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2016-10-25 10:04:23 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2015-04-25 03:27:30 +02:00
return NullUniValue ;
2016-10-25 10:04:23 +02:00
}
2015-04-25 03:27:30 +02:00
2017-07-10 17:43:17 +02:00
if ( request . fHelp | | request . params . size ( ) < 1 | | request . params . size ( ) > 2 )
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2016-03-30 03:04:22 +02:00
" fundrawtransaction \" hexstring \" ( options ) \n "
2015-04-25 03:27:30 +02:00
" \n Add inputs to a transaction until it has enough in value to meet its out value. \n "
2016-12-13 22:36:23 +01:00
" This will not modify existing inputs, and will add at most one change output to the outputs. \n "
" No existing outputs will be modified unless \" subtractFeeFromOutputs \" is specified. \n "
2015-04-25 03:27:30 +02:00
" Note that inputs which were signed may need to be resigned after completion since in/outputs have been added. \n "
" The inputs added will not be signed, use signrawtransaction for that. \n "
2015-04-24 06:42:49 +02:00
" Note that all existing inputs must have their previous output transaction be in the wallet. \n "
2016-04-16 22:42:28 +02:00
" Note that all inputs selected must be of standard form and P2SH scripts must be \n "
2015-04-24 06:42:49 +02:00
" in the wallet using importaddress or addmultisigaddress (to calculate fees). \n "
2016-03-14 19:22:11 +01:00
" You can see whether this is the case by checking the \" solvable \" field in the listunspent output. \n "
2015-04-24 06:42:49 +02:00
" Only pay-to-pubkey, multisig, and P2SH versions thereof are currently supported for watch-only \n "
2015-04-25 03:27:30 +02:00
" \n Arguments: \n "
2016-03-30 03:04:22 +02:00
" 1. \" hexstring \" (string, required) The hex string of the raw transaction \n "
2016-12-09 18:06:42 +01:00
" 2. options (object, optional) \n "
2016-03-30 03:04:22 +02:00
" { \n "
2016-12-13 22:36:23 +01:00
" \" changeAddress \" (string, optional, default pool address) The bitcoin address to receive the change \n "
" \" changePosition \" (numeric, optional, default random) The index of the change output \n "
" \" includeWatching \" (boolean, optional, default false) Also select inputs which are watch only \n "
" \" lockUnspents \" (boolean, optional, default false) Lock selected unspent outputs \n "
" \" feeRate \" (numeric, optional, default not set: makes wallet determine the fee) Set a specific feerate ( " + CURRENCY_UNIT + " per KB) \n "
" \" subtractFeeFromOutputs \" (array, optional) A json array of integers. \n "
" The fee will be equally deducted from the amount of each specified output. \n "
" The outputs are specified by their zero-based index, before any change output is added. \n "
" Those recipients will receive less bitcoins than you enter in their corresponding amount field. \n "
" If no outputs are specified here, the sender pays the fee. \n "
" [vout_index,...] \n "
2017-06-28 23:53:06 +02:00
" \" replaceable \" (boolean, optional) Marks this transaction as BIP125 replaceable. \n "
" Allows this transaction to be replaced by a transaction with higher fees \n "
2017-06-14 21:15:40 +02:00
" \" conf_target \" (numeric, optional) Confirmation target (in blocks) \n "
" \" estimate_mode \" (string, optional, default=UNSET) The fee estimate mode, must be one of: \n "
" \" UNSET \" \n "
" \" ECONOMICAL \" \n "
" \" CONSERVATIVE \" \n "
2016-03-30 03:04:22 +02:00
" } \n "
2016-04-17 09:01:49 +02:00
" for backward compatibility: passing in a true instead of an object will result in { \" includeWatching \" :true} \n "
2015-04-25 03:27:30 +02:00
" \n Result: \n "
" { \n "
" \" hex \" : \" value \" , (string) The resulting raw transaction (hex-encoded string) \n "
2016-06-03 19:07:08 +02:00
" \" fee \" : n, (numeric) Fee in " + CURRENCY_UNIT + " the resulting transaction pays \n "
2015-04-25 03:27:30 +02:00
" \" changepos \" : n (numeric) The position of the added change output, or -1 \n "
" } \n "
" \n Examples: \n "
" \n Create a transaction with no inputs \n "
+ HelpExampleCli ( " createrawtransaction " , " \" [] \" \" { \\ \" myaddress \\ \" :0.01} \" " ) +
" \n Add sufficient unsigned inputs to meet the output value \n "
+ HelpExampleCli ( " fundrawtransaction " , " \" rawtransactionhex \" " ) +
" \n Sign the transaction \n "
+ HelpExampleCli ( " signrawtransaction " , " \" fundedtransactionhex \" " ) +
" \n Send the transaction \n "
+ HelpExampleCli ( " sendrawtransaction " , " \" signedtransactionhex \" " )
) ;
2017-06-06 21:15:28 +02:00
RPCTypeCheck ( request . params , { UniValue : : VSTR } ) ;
2016-03-30 03:04:22 +02:00
2017-02-02 23:33:24 +01:00
CCoinControl coinControl ;
2016-03-30 03:04:22 +02:00
int changePosition = - 1 ;
2016-04-06 16:56:14 +02:00
bool lockUnspents = false ;
2016-12-13 22:36:23 +01:00
UniValue subtractFeeFromOutputs ;
2017-01-27 02:33:45 +01:00
std : : set < int > setSubtractFeeFromOutputs ;
2016-03-30 03:04:22 +02:00
2017-07-10 17:44:39 +02:00
if ( ! request . params [ 1 ] . isNull ( ) ) {
2016-09-22 09:46:41 +02:00
if ( request . params [ 1 ] . type ( ) = = UniValue : : VBOOL ) {
2016-03-30 03:04:22 +02:00
// backward compatibility bool only fallback
2017-02-02 23:33:24 +01:00
coinControl . fAllowWatchOnly = request . params [ 1 ] . get_bool ( ) ;
2016-03-30 03:04:22 +02:00
}
else {
2017-06-06 21:15:28 +02:00
RPCTypeCheck ( request . params , { UniValue : : VSTR , UniValue : : VOBJ } ) ;
2016-03-30 03:04:22 +02:00
2016-09-22 09:46:41 +02:00
UniValue options = request . params [ 1 ] ;
2016-03-30 03:04:22 +02:00
2016-06-06 17:50:50 +02:00
RPCTypeCheckObj ( options ,
{
{ " changeAddress " , UniValueType ( UniValue : : VSTR ) } ,
{ " changePosition " , UniValueType ( UniValue : : VNUM ) } ,
{ " includeWatching " , UniValueType ( UniValue : : VBOOL ) } ,
{ " lockUnspents " , UniValueType ( UniValue : : VBOOL ) } ,
2017-07-10 20:29:06 +02:00
{ " reserveChangeKey " , UniValueType ( UniValue : : VBOOL ) } , // DEPRECATED (and ignored), should be removed in 0.16 or so.
2016-06-06 17:50:50 +02:00
{ " feeRate " , UniValueType ( ) } , // will be checked below
2016-12-13 22:36:23 +01:00
{ " subtractFeeFromOutputs " , UniValueType ( UniValue : : VARR ) } ,
2017-06-28 23:53:06 +02:00
{ " replaceable " , UniValueType ( UniValue : : VBOOL ) } ,
2017-06-14 21:15:40 +02:00
{ " conf_target " , UniValueType ( UniValue : : VNUM ) } ,
{ " estimate_mode " , UniValueType ( UniValue : : VSTR ) } ,
2016-06-06 17:50:50 +02:00
} ,
true , true ) ;
2016-03-30 03:04:22 +02:00
if ( options . exists ( " changeAddress " ) ) {
CBitcoinAddress address ( options [ " changeAddress " ] . get_str ( ) ) ;
if ( ! address . IsValid ( ) )
2017-02-07 20:27:57 +01:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " changeAddress must be a valid bitcoin address " ) ;
2016-03-30 03:04:22 +02:00
2017-02-02 23:33:24 +01:00
coinControl . destChange = address . Get ( ) ;
2016-03-30 03:04:22 +02:00
}
if ( options . exists ( " changePosition " ) )
changePosition = options [ " changePosition " ] . get_int ( ) ;
if ( options . exists ( " includeWatching " ) )
2017-02-02 23:33:24 +01:00
coinControl . fAllowWatchOnly = options [ " includeWatching " ] . get_bool ( ) ;
2016-04-06 16:56:14 +02:00
if ( options . exists ( " lockUnspents " ) )
lockUnspents = options [ " lockUnspents " ] . get_bool ( ) ;
2016-04-28 22:04:07 +02:00
if ( options . exists ( " feeRate " ) )
2016-05-06 11:01:50 +02:00
{
2017-06-28 23:23:46 +02:00
coinControl . m_feerate = CFeeRate ( AmountFromValue ( options [ " feeRate " ] ) ) ;
2017-02-02 23:33:24 +01:00
coinControl . fOverrideFeeRate = true ;
2016-05-06 11:01:50 +02:00
}
2016-12-13 22:36:23 +01:00
if ( options . exists ( " subtractFeeFromOutputs " ) )
subtractFeeFromOutputs = options [ " subtractFeeFromOutputs " ] . get_array ( ) ;
2017-02-02 23:36:50 +01:00
2017-06-28 23:53:06 +02:00
if ( options . exists ( " replaceable " ) ) {
coinControl . signalRbf = options [ " replaceable " ] . get_bool ( ) ;
2017-02-02 23:36:50 +01:00
}
2017-06-14 21:15:40 +02:00
if ( options . exists ( " conf_target " ) ) {
2017-07-12 02:59:46 +02:00
if ( options . exists ( " feeRate " ) ) {
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Cannot specify both conf_target and feeRate " ) ;
}
2017-07-12 20:42:57 +02:00
coinControl . m_confirm_target = ParseConfirmTarget ( options [ " conf_target " ] ) ;
2017-06-14 21:15:40 +02:00
}
if ( options . exists ( " estimate_mode " ) ) {
2017-07-12 02:59:46 +02:00
if ( options . exists ( " feeRate " ) ) {
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Cannot specify both estimate_mode and feeRate " ) ;
}
2017-06-14 21:15:40 +02:00
if ( ! FeeModeFromString ( options [ " estimate_mode " ] . get_str ( ) , coinControl . m_fee_mode ) ) {
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Invalid estimate_mode parameter " ) ;
}
}
2016-03-30 03:04:22 +02:00
}
}
2015-04-25 03:27:30 +02:00
// parse hex string from parameter
2016-11-30 23:50:20 +01:00
CMutableTransaction tx ;
if ( ! DecodeHexTx ( tx , request . params [ 0 ] . get_str ( ) , true ) )
2015-04-25 03:27:30 +02:00
throw JSONRPCError ( RPC_DESERIALIZATION_ERROR , " TX decode failed " ) ;
2016-11-30 23:50:20 +01:00
if ( tx . vout . size ( ) = = 0 )
2015-11-13 21:52:07 +01:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " TX must have at least one output " ) ;
2016-11-30 23:50:20 +01:00
if ( changePosition ! = - 1 & & ( changePosition < 0 | | ( unsigned int ) changePosition > tx . vout . size ( ) ) )
2016-03-30 03:04:22 +02:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " changePosition out of bounds " ) ;
2015-04-24 06:42:49 +02:00
2016-12-13 22:36:23 +01:00
for ( unsigned int idx = 0 ; idx < subtractFeeFromOutputs . size ( ) ; idx + + ) {
int pos = subtractFeeFromOutputs [ idx ] . get_int ( ) ;
if ( setSubtractFeeFromOutputs . count ( pos ) )
throw JSONRPCError ( RPC_INVALID_PARAMETER , strprintf ( " Invalid parameter, duplicated position: %d " , pos ) ) ;
if ( pos < 0 )
throw JSONRPCError ( RPC_INVALID_PARAMETER , strprintf ( " Invalid parameter, negative position: %d " , pos ) ) ;
if ( pos > = int ( tx . vout . size ( ) ) )
throw JSONRPCError ( RPC_INVALID_PARAMETER , strprintf ( " Invalid parameter, position too large: %d " , pos ) ) ;
setSubtractFeeFromOutputs . insert ( pos ) ;
}
2016-04-28 22:04:07 +02:00
CAmount nFeeOut ;
2017-01-27 02:33:45 +01:00
std : : string strFailReason ;
2016-03-30 03:04:22 +02:00
2017-07-10 20:29:06 +02:00
if ( ! pwallet - > FundTransaction ( tx , nFeeOut , changePosition , strFailReason , lockUnspents , setSubtractFeeFromOutputs , coinControl ) ) {
2017-02-09 21:48:39 +01:00
throw JSONRPCError ( RPC_WALLET_ERROR , strFailReason ) ;
2016-10-25 10:04:23 +02:00
}
2015-04-25 03:27:30 +02:00
UniValue result ( UniValue : : VOBJ ) ;
result . push_back ( Pair ( " hex " , EncodeHexTx ( tx ) ) ) ;
2016-03-30 03:04:22 +02:00
result . push_back ( Pair ( " changepos " , changePosition ) ) ;
2016-04-28 22:04:07 +02:00
result . push_back ( Pair ( " fee " , ValueFromAmount ( nFeeOut ) ) ) ;
2015-04-25 03:27:30 +02:00
return result ;
}
2016-01-07 08:33:49 +01:00
2016-12-09 19:45:27 +01:00
UniValue bumpfee ( const JSONRPCRequest & request )
{
2016-10-25 09:45:57 +02:00
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) )
2016-12-09 19:45:27 +01:00
return NullUniValue ;
if ( request . fHelp | | request . params . size ( ) < 1 | | request . params . size ( ) > 2 ) {
2017-01-27 02:33:45 +01:00
throw std : : runtime_error (
2016-12-09 19:45:27 +01:00
" bumpfee \" txid \" ( options ) \n "
" \n Bumps the fee of an opt-in-RBF transaction T, replacing it with a new transaction B. \n "
" An opt-in RBF transaction with the given txid must be in the wallet. \n "
" The command will pay the additional fee by decreasing (or perhaps removing) its change output. \n "
" If the change output is not big enough to cover the increased fee, the command will currently fail \n "
" instead of adding new inputs to compensate. (A future implementation could improve this.) \n "
" The command will fail if the wallet or mempool contains a transaction that spends one of T's outputs. \n "
" By default, the new fee will be calculated automatically using estimatefee. \n "
" The user can specify a confirmation target for estimatefee. \n "
2017-05-17 04:13:40 +02:00
" Alternatively, the user can specify totalFee, or use RPC settxfee to set a higher fee rate. \n "
2017-01-20 03:18:46 +01:00
" At a minimum, the new fee rate must be high enough to pay an additional new relay fee (incrementalfee \n "
" returned by getnetworkinfo) to enter the node's mempool. \n "
2016-12-09 19:45:27 +01:00
" \n Arguments: \n "
" 1. txid (string, required) The txid to be bumped \n "
" 2. options (object, optional) \n "
" { \n "
" \" confTarget \" (numeric, optional) Confirmation target (in blocks) \n "
" \" totalFee \" (numeric, optional) Total fee (NOT feerate) to pay, in satoshis. \n "
" In rare cases, the actual fee paid might be slightly higher than the specified \n "
" totalFee if the tx change output has to be removed because it is too close to \n "
" the dust threshold. \n "
" \" replaceable \" (boolean, optional, default true) Whether the new transaction should still be \n "
" marked bip-125 replaceable. If true, the sequence numbers in the transaction will \n "
" be left unchanged from the original. If false, any input sequence numbers in the \n "
" original transaction that were less than 0xfffffffe will be increased to 0xfffffffe \n "
" so the new transaction will not be explicitly bip-125 replaceable (though it may \n "
2017-02-06 15:16:18 +01:00
" still be replaceable in practice, for example if it has unconfirmed ancestors which \n "
2016-12-09 19:45:27 +01:00
" are replaceable). \n "
2017-06-14 21:15:40 +02:00
" \" estimate_mode \" (string, optional, default=UNSET) The fee estimate mode, must be one of: \n "
" \" UNSET \" \n "
" \" ECONOMICAL \" \n "
" \" CONSERVATIVE \" \n "
2016-12-09 19:45:27 +01:00
" } \n "
" \n Result: \n "
" { \n "
" \" txid \" : \" value \" , (string) The id of the new transaction \n "
2017-01-23 19:15:48 +01:00
" \" origfee \" : n, (numeric) Fee of the replaced transaction \n "
" \" fee \" : n, (numeric) Fee of the new transaction \n "
2017-01-26 18:57:42 +01:00
" \" errors \" : [ str... ] (json array of strings) Errors encountered during processing (may be empty) \n "
2016-12-09 19:45:27 +01:00
" } \n "
" \n Examples: \n "
" \n Bump the fee, get the new transaction \' s txid \n " +
HelpExampleCli ( " bumpfee " , " <txid> " ) ) ;
}
2017-06-06 21:15:28 +02:00
RPCTypeCheck ( request . params , { UniValue : : VSTR , UniValue : : VOBJ } ) ;
2016-12-09 19:45:27 +01:00
uint256 hash ;
hash . SetHex ( request . params [ 0 ] . get_str ( ) ) ;
2017-02-02 22:03:55 +01:00
// optional parameters
CAmount totalFee = 0 ;
2017-06-28 23:23:46 +02:00
CCoinControl coin_control ;
coin_control . signalRbf = true ;
2017-07-10 17:44:39 +02:00
if ( ! request . params [ 1 ] . isNull ( ) ) {
2017-02-02 22:03:55 +01:00
UniValue options = request . params [ 1 ] ;
RPCTypeCheckObj ( options ,
{
{ " confTarget " , UniValueType ( UniValue : : VNUM ) } ,
{ " totalFee " , UniValueType ( UniValue : : VNUM ) } ,
{ " replaceable " , UniValueType ( UniValue : : VBOOL ) } ,
2017-06-14 21:15:40 +02:00
{ " estimate_mode " , UniValueType ( UniValue : : VSTR ) } ,
2017-02-02 22:03:55 +01:00
} ,
true , true ) ;
if ( options . exists ( " confTarget " ) & & options . exists ( " totalFee " ) ) {
throw JSONRPCError ( RPC_INVALID_PARAMETER , " confTarget and totalFee options should not both be set. Please provide either a confirmation target for fee estimation or an explicit total fee for the transaction. " ) ;
2017-07-12 20:42:57 +02:00
} else if ( options . exists ( " confTarget " ) ) { // TODO: alias this to conf_target
coin_control . m_confirm_target = ParseConfirmTarget ( options [ " confTarget " ] ) ;
2017-02-02 22:03:55 +01:00
} else if ( options . exists ( " totalFee " ) ) {
totalFee = options [ " totalFee " ] . get_int64 ( ) ;
2017-03-27 13:55:28 +02:00
if ( totalFee < = 0 ) {
throw JSONRPCError ( RPC_INVALID_PARAMETER , strprintf ( " Invalid totalFee %s (must be greater than 0) " , FormatMoney(totalFee))) ;
}
2017-02-02 22:03:55 +01:00
}
if ( options . exists ( " replaceable " ) ) {
2017-06-28 23:23:46 +02:00
coin_control . signalRbf = options [ " replaceable " ] . get_bool ( ) ;
2017-02-02 22:03:55 +01:00
}
2017-06-14 21:15:40 +02:00
if ( options . exists ( " estimate_mode " ) ) {
2017-06-28 23:23:46 +02:00
if ( ! FeeModeFromString ( options [ " estimate_mode " ] . get_str ( ) , coin_control . m_fee_mode ) ) {
2017-06-14 21:15:40 +02:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Invalid estimate_mode parameter " ) ;
}
}
2017-02-02 22:03:55 +01:00
}
2016-10-25 09:45:57 +02:00
LOCK2 ( cs_main , pwallet - > cs_wallet ) ;
EnsureWalletIsUnlocked ( pwallet ) ;
2016-12-09 19:45:27 +01:00
2017-06-28 23:23:46 +02:00
CFeeBumper feeBump ( pwallet , hash , coin_control , totalFee ) ;
2017-03-03 16:15:47 +01:00
BumpFeeResult res = feeBump . getResult ( ) ;
if ( res ! = BumpFeeResult : : OK )
2016-12-09 19:45:27 +01:00
{
2017-03-03 16:15:47 +01:00
switch ( res ) {
case BumpFeeResult : : INVALID_ADDRESS_OR_KEY :
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , feeBump . getErrors ( ) [ 0 ] ) ;
break ;
case BumpFeeResult : : INVALID_REQUEST :
throw JSONRPCError ( RPC_INVALID_REQUEST , feeBump . getErrors ( ) [ 0 ] ) ;
break ;
case BumpFeeResult : : INVALID_PARAMETER :
throw JSONRPCError ( RPC_INVALID_PARAMETER , feeBump . getErrors ( ) [ 0 ] ) ;
break ;
case BumpFeeResult : : WALLET_ERROR :
throw JSONRPCError ( RPC_WALLET_ERROR , feeBump . getErrors ( ) [ 0 ] ) ;
break ;
default :
throw JSONRPCError ( RPC_MISC_ERROR , feeBump . getErrors ( ) [ 0 ] ) ;
break ;
2016-12-09 19:45:27 +01:00
}
}
2017-03-03 16:15:47 +01:00
// sign bumped transaction
2017-03-30 09:26:21 +02:00
if ( ! feeBump . signTransaction ( pwallet ) ) {
2017-03-03 16:15:47 +01:00
throw JSONRPCError ( RPC_WALLET_ERROR , " Can't sign transaction. " ) ;
2016-12-09 19:45:27 +01:00
}
2017-03-03 16:15:47 +01:00
// commit the bumped transaction
if ( ! feeBump . commit ( pwallet ) ) {
throw JSONRPCError ( RPC_WALLET_ERROR , feeBump . getErrors ( ) [ 0 ] ) ;
2017-01-23 19:15:24 +01:00
}
2016-12-09 19:45:27 +01:00
UniValue result ( UniValue : : VOBJ ) ;
2017-03-03 16:15:47 +01:00
result . push_back ( Pair ( " txid " , feeBump . getBumpedTxId ( ) . GetHex ( ) ) ) ;
result . push_back ( Pair ( " origfee " , ValueFromAmount ( feeBump . getOldFee ( ) ) ) ) ;
result . push_back ( Pair ( " fee " , ValueFromAmount ( feeBump . getNewFee ( ) ) ) ) ;
UniValue errors ( UniValue : : VARR ) ;
for ( const std : : string & err : feeBump . getErrors ( ) )
errors . push_back ( err ) ;
2017-05-24 22:15:26 +02:00
result . push_back ( Pair ( " errors " , errors ) ) ;
2016-12-09 19:45:27 +01:00
return result ;
}
2017-06-27 16:50:44 +02:00
UniValue generate ( const JSONRPCRequest & request )
{
CWallet * const pwallet = GetWalletForJSONRPCRequest ( request ) ;
2017-06-28 08:32:21 +02:00
if ( ! EnsureWalletIsAvailable ( pwallet , request . fHelp ) ) {
2017-06-27 16:50:44 +02:00
return NullUniValue ;
2017-06-28 08:32:21 +02:00
}
2017-06-27 16:50:44 +02:00
2017-06-28 08:32:21 +02:00
if ( request . fHelp | | request . params . size ( ) < 1 | | request . params . size ( ) > 2 ) {
2017-06-27 16:50:44 +02:00
throw std : : runtime_error (
" generate nblocks ( maxtries ) \n "
" \n Mine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet. \n "
" \n Arguments: \n "
" 1. nblocks (numeric, required) How many blocks are generated immediately. \n "
" 2. maxtries (numeric, optional) How many iterations to try (default = 1000000). \n "
" \n Result: \n "
" [ blockhashes ] (array) hashes of blocks generated \n "
" \n Examples: \n "
" \n Generate 11 blocks \n "
+ HelpExampleCli ( " generate " , " 11 " )
) ;
2017-06-28 08:32:21 +02:00
}
2017-06-27 16:50:44 +02:00
2017-06-28 08:32:21 +02:00
int num_generate = request . params [ 0 ] . get_int ( ) ;
uint64_t max_tries = 1000000 ;
2017-08-15 01:38:18 +02:00
if ( ! request . params [ 1 ] . isNull ( ) ) {
2017-06-28 08:32:21 +02:00
max_tries = request . params [ 1 ] . get_int ( ) ;
2017-06-27 16:50:44 +02:00
}
2017-06-28 08:32:21 +02:00
std : : shared_ptr < CReserveScript > coinbase_script ;
pwallet - > GetScriptForMining ( coinbase_script ) ;
2017-06-27 16:50:44 +02:00
// If the keypool is exhausted, no script is returned at all. Catch this.
2017-06-28 08:32:21 +02:00
if ( ! coinbase_script ) {
2017-06-27 16:50:44 +02:00
throw JSONRPCError ( RPC_WALLET_KEYPOOL_RAN_OUT , " Error: Keypool ran out, please call keypoolrefill first " ) ;
2017-06-28 08:32:21 +02:00
}
2017-06-27 16:50:44 +02:00
//throw an error if no script was provided
2017-06-28 08:32:21 +02:00
if ( coinbase_script - > reserveScript . empty ( ) ) {
throw JSONRPCError ( RPC_INTERNAL_ERROR , " No coinbase script available " ) ;
}
2017-06-27 16:50:44 +02:00
2017-06-28 08:32:21 +02:00
return generateBlocks ( coinbase_script , num_generate , max_tries , true ) ;
2017-06-27 16:50:44 +02:00
}
2017-04-17 16:32:29 +02:00
extern UniValue abortrescan ( const JSONRPCRequest & request ) ; // in rpcdump.cpp
2016-09-22 09:46:41 +02:00
extern UniValue dumpprivkey ( const JSONRPCRequest & request ) ; // in rpcdump.cpp
extern UniValue importprivkey ( const JSONRPCRequest & request ) ;
extern UniValue importaddress ( const JSONRPCRequest & request ) ;
extern UniValue importpubkey ( const JSONRPCRequest & request ) ;
extern UniValue dumpwallet ( const JSONRPCRequest & request ) ;
extern UniValue importwallet ( const JSONRPCRequest & request ) ;
extern UniValue importprunedfunds ( const JSONRPCRequest & request ) ;
extern UniValue removeprunedfunds ( const JSONRPCRequest & request ) ;
2016-06-16 16:57:48 +02:00
extern UniValue importmulti ( const JSONRPCRequest & request ) ;
2016-01-07 08:33:49 +01:00
2016-03-29 19:43:02 +02:00
static const CRPCCommand commands [ ] =
2016-01-07 08:33:49 +01:00
{ // category name actor (function) okSafeMode
// --------------------- ------------------------ ----------------------- ----------
2016-11-21 14:32:36 +01:00
{ " rawtransactions " , " fundrawtransaction " , & fundrawtransaction , false , { " hexstring " , " options " } } ,
{ " hidden " , " resendwallettransactions " , & resendwallettransactions , true , { } } ,
{ " wallet " , " abandontransaction " , & abandontransaction , false , { " txid " } } ,
2017-04-17 16:32:29 +02:00
{ " wallet " , " abortrescan " , & abortrescan , false , { } } ,
2016-11-21 14:32:36 +01:00
{ " wallet " , " addmultisigaddress " , & addmultisigaddress , true , { " nrequired " , " keys " , " account " } } ,
{ " wallet " , " addwitnessaddress " , & addwitnessaddress , true , { " address " } } ,
{ " wallet " , " backupwallet " , & backupwallet , true , { " destination " } } ,
2016-12-09 19:45:27 +01:00
{ " wallet " , " bumpfee " , & bumpfee , true , { " txid " , " options " } } ,
2016-11-21 14:39:58 +01:00
{ " wallet " , " dumpprivkey " , & dumpprivkey , true , { " address " } } ,
2016-11-21 14:32:36 +01:00
{ " wallet " , " dumpwallet " , & dumpwallet , true , { " filename " } } ,
{ " wallet " , " encryptwallet " , & encryptwallet , true , { " passphrase " } } ,
{ " wallet " , " getaccountaddress " , & getaccountaddress , true , { " account " } } ,
2016-11-21 14:39:58 +01:00
{ " wallet " , " getaccount " , & getaccount , true , { " address " } } ,
2016-11-21 14:32:36 +01:00
{ " wallet " , " getaddressesbyaccount " , & getaddressesbyaccount , true , { " account " } } ,
{ " wallet " , " getbalance " , & getbalance , false , { " account " , " minconf " , " include_watchonly " } } ,
{ " wallet " , " getnewaddress " , & getnewaddress , true , { " account " } } ,
{ " wallet " , " getrawchangeaddress " , & getrawchangeaddress , true , { } } ,
{ " wallet " , " getreceivedbyaccount " , & getreceivedbyaccount , false , { " account " , " minconf " } } ,
2016-11-21 14:39:58 +01:00
{ " wallet " , " getreceivedbyaddress " , & getreceivedbyaddress , false , { " address " , " minconf " } } ,
2016-11-21 14:32:36 +01:00
{ " wallet " , " gettransaction " , & gettransaction , false , { " txid " , " include_watchonly " } } ,
{ " wallet " , " getunconfirmedbalance " , & getunconfirmedbalance , false , { } } ,
{ " wallet " , " getwalletinfo " , & getwalletinfo , false , { } } ,
{ " wallet " , " importmulti " , & importmulti , true , { " requests " , " options " } } ,
2016-11-21 14:39:58 +01:00
{ " wallet " , " importprivkey " , & importprivkey , true , { " privkey " , " label " , " rescan " } } ,
2016-11-21 14:32:36 +01:00
{ " wallet " , " importwallet " , & importwallet , true , { " filename " } } ,
{ " wallet " , " importaddress " , & importaddress , true , { " address " , " label " , " rescan " , " p2sh " } } ,
{ " wallet " , " importprunedfunds " , & importprunedfunds , true , { " rawtransaction " , " txoutproof " } } ,
{ " wallet " , " importpubkey " , & importpubkey , true , { " pubkey " , " label " , " rescan " } } ,
{ " wallet " , " keypoolrefill " , & keypoolrefill , true , { " newsize " } } ,
{ " wallet " , " listaccounts " , & listaccounts , false , { " minconf " , " include_watchonly " } } ,
{ " wallet " , " listaddressgroupings " , & listaddressgroupings , false , { } } ,
{ " wallet " , " listlockunspent " , & listlockunspent , false , { } } ,
{ " wallet " , " listreceivedbyaccount " , & listreceivedbyaccount , false , { " minconf " , " include_empty " , " include_watchonly " } } ,
{ " wallet " , " listreceivedbyaddress " , & listreceivedbyaddress , false , { " minconf " , " include_empty " , " include_watchonly " } } ,
2017-01-24 06:27:22 +01:00
{ " wallet " , " listsinceblock " , & listsinceblock , false , { " blockhash " , " target_confirmations " , " include_watchonly " , " include_removed " } } ,
2016-12-09 18:06:42 +01:00
{ " wallet " , " listtransactions " , & listtransactions , false , { " account " , " count " , " skip " , " include_watchonly " } } ,
2017-03-07 19:17:32 +01:00
{ " wallet " , " listunspent " , & listunspent , false , { " minconf " , " maxconf " , " addresses " , " include_unsafe " , " query_options " } } ,
2017-06-27 15:46:55 +02:00
{ " wallet " , " listwallets " , & listwallets , true , { } } ,
2016-11-21 14:32:36 +01:00
{ " wallet " , " lockunspent " , & lockunspent , true , { " unlock " , " transactions " } } ,
{ " wallet " , " move " , & movecmd , false , { " fromaccount " , " toaccount " , " amount " , " minconf " , " comment " } } ,
2016-11-21 14:39:58 +01:00
{ " wallet " , " sendfrom " , & sendfrom , false , { " fromaccount " , " toaddress " , " amount " , " minconf " , " comment " , " comment_to " } } ,
2017-06-14 21:15:40 +02:00
{ " wallet " , " sendmany " , & sendmany , false , { " fromaccount " , " amounts " , " minconf " , " comment " , " subtractfeefrom " , " replaceable " , " conf_target " , " estimate_mode " } } ,
{ " wallet " , " sendtoaddress " , & sendtoaddress , false , { " address " , " amount " , " comment " , " comment_to " , " subtractfeefromamount " , " replaceable " , " conf_target " , " estimate_mode " } } ,
2016-11-21 14:39:58 +01:00
{ " wallet " , " setaccount " , & setaccount , true , { " address " , " account " } } ,
2016-11-21 14:32:36 +01:00
{ " wallet " , " settxfee " , & settxfee , true , { " amount " } } ,
2016-11-21 14:39:58 +01:00
{ " wallet " , " signmessage " , & signmessage , true , { " address " , " message " } } ,
2016-11-21 14:32:36 +01:00
{ " wallet " , " walletlock " , & walletlock , true , { } } ,
{ " wallet " , " walletpassphrasechange " , & walletpassphrasechange , true , { " oldpassphrase " , " newpassphrase " } } ,
{ " wallet " , " walletpassphrase " , & walletpassphrase , true , { " passphrase " , " timeout " } } ,
{ " wallet " , " removeprunedfunds " , & removeprunedfunds , true , { " txid " } } ,
2017-06-27 16:50:44 +02:00
{ " generating " , " generate " , & generate , true , { " nblocks " , " maxtries " } } ,
2016-01-07 08:33:49 +01:00
} ;
2016-06-07 18:42:42 +02:00
void RegisterWalletRPCCommands ( CRPCTable & t )
2016-01-07 08:33:49 +01:00
{
2017-08-01 21:17:40 +02:00
if ( gArgs . GetBoolArg ( " -disablewallet " , false ) )
2016-09-19 16:09:38 +02:00
return ;
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-01-07 08:33:49 +01:00
}