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"
2014-06-24 05:10:24 +02:00
# include "core_io.h"
2012-08-21 16:38:57 +02:00
# include "init.h"
2015-02-05 01:21:11 +01:00
# include "main.h"
2013-04-13 07:13:08 +02:00
# include "net.h"
2015-12-16 20:57:54 +01:00
# include "policy/rbf.h"
2016-01-15 01:55:17 +01:00
# include "rpc/server.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"
2013-04-13 07:13:08 +02:00
# include "wallet.h"
# include "walletdb.h"
# include <stdint.h>
# include <boost/assign/list_of.hpp>
2014-12-09 14:50:01 +01:00
2015-09-04 16:11:34 +02:00
# include <univalue.h>
2012-08-21 16:38:57 +02:00
using namespace std ;
2013-04-13 07:13:08 +02:00
int64_t nWalletUnlockTime ;
2012-08-21 16:38:57 +02:00
static CCriticalSection cs_nWalletUnlockTime ;
2012-08-24 08:44:51 +02:00
std : : string HelpRequiringPassphrase ( )
2012-08-21 16:38:57 +02:00
{
2013-08-25 06:00:02 +02:00
return pwalletMain & & pwalletMain - > 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
: " " ;
}
2015-04-12 17:56:44 +02:00
bool EnsureWalletIsAvailable ( bool avoidException )
{
if ( ! pwalletMain )
{
if ( ! avoidException )
throw JSONRPCError ( RPC_METHOD_NOT_FOUND , " Method not found (disabled) " ) ;
else
return false ;
}
return true ;
}
2012-08-24 08:44:51 +02:00
void EnsureWalletIsUnlocked ( )
2012-08-21 16:38:57 +02:00
{
if ( pwalletMain - > IsLocked ( ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_UNLOCK_NEEDED , " Error: Please enter the wallet passphrase with walletpassphrase first. " ) ;
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 ) ;
2014-02-14 02:12:51 +01:00
BOOST_FOREACH ( const uint256 & conflict , wtx . GetConflicts ( ) )
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 ) ) ;
2012-08-21 16:38:57 +02:00
BOOST_FOREACH ( const PAIRTYPE ( string , string ) & item , wtx . mapValue )
entry . push_back ( Pair ( item . first , item . second ) ) ;
}
2015-05-18 14:02:18 +02:00
string AccountFromValue ( const UniValue & value )
2012-08-21 16:38:57 +02:00
{
string strAccount = value . get_str ( ) ;
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 ;
}
2015-05-18 14:02:18 +02:00
UniValue getnewaddress ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( fHelp | | params . size ( ) > 1 )
throw 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 "
" \" bitcoinaddress \" (string) The new bitcoin address \n "
" \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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
// Parse the account first so we don't generate a key if there's an error
string strAccount ;
if ( params . size ( ) > 0 )
strAccount = AccountFromValue ( params [ 0 ] ) ;
if ( ! pwalletMain - > IsLocked ( ) )
pwalletMain - > TopUpKeyPool ( ) ;
// Generate a new key that is added to wallet
CPubKey newKey ;
2013-08-23 21:54:50 +02:00
if ( ! pwalletMain - > 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 " ) ;
2012-08-21 16:38:57 +02:00
CKeyID keyID = newKey . GetID ( ) ;
2013-07-22 08:50:39 +02:00
pwalletMain - > SetAddressBook ( keyID , strAccount , " receive " ) ;
2012-08-21 16:38:57 +02:00
return CBitcoinAddress ( keyID ) . ToString ( ) ;
}
CBitcoinAddress GetAccountAddress ( string strAccount , bool bForceNew = false )
{
2016-06-03 08:16:42 +02:00
CPubKey pubKey ;
if ( ! pwalletMain - > GetAccountPubkey ( pubKey , strAccount , bForceNew ) ) {
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
}
2015-05-18 14:02:18 +02:00
UniValue getaccountaddress ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( fHelp | | params . size ( ) ! = 1 )
throw 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 "
" \" bitcoinaddress \" (string) The account bitcoin address \n "
" \n Examples: \n "
+ HelpExampleCli ( " getaccountaddress " , " " )
+ HelpExampleCli ( " getaccountaddress " , " \" \" " )
+ HelpExampleCli ( " getaccountaddress " , " \" myaccount \" " )
+ HelpExampleRpc ( " getaccountaddress " , " \" myaccount \" " )
) ;
2012-08-21 16:38:57 +02:00
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
// Parse the account first so we don't generate a key if there's an error
string strAccount = AccountFromValue ( params [ 0 ] ) ;
2015-05-18 14:02:18 +02:00
UniValue ret ( UniValue : : VSTR ) ;
2012-08-21 16:38:57 +02:00
ret = GetAccountAddress ( strAccount ) . ToString ( ) ;
return ret ;
}
2015-05-18 14:02:18 +02:00
UniValue getrawchangeaddress ( const UniValue & params , bool fHelp )
2013-08-28 22:29:52 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2013-08-28 22:29:52 +02:00
if ( fHelp | | params . size ( ) > 1 )
throw runtime_error (
" 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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2013-08-28 22:29:52 +02:00
if ( ! pwalletMain - > IsLocked ( ) )
pwalletMain - > TopUpKeyPool ( ) ;
CReserveKey reservekey ( pwalletMain ) ;
CPubKey vchPubKey ;
if ( ! reservekey . GetReservedKey ( vchPubKey ) )
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
2015-05-18 14:02:18 +02:00
UniValue setaccount ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( fHelp | | params . size ( ) < 1 | | params . size ( ) > 2 )
throw runtime_error (
2013-10-29 12:29:44 +01:00
" setaccount \" bitcoinaddress \" \" 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 "
" 1. \" bitcoinaddress \" (string, required) The bitcoin address to be associated with an account. \n "
" 2. \" account \" (string, required) The account to assign the address to. \n "
" \n Examples: \n "
+ HelpExampleCli ( " setaccount " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \" \" tabby \" " )
+ HelpExampleRpc ( " setaccount " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \" , \" tabby \" " )
) ;
2012-08-21 16:38:57 +02:00
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
CBitcoinAddress address ( params [ 0 ] . get_str ( ) ) ;
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
string strAccount ;
if ( params . size ( ) > 1 )
strAccount = AccountFromValue ( params [ 1 ] ) ;
2014-09-26 00:39:28 +02:00
// Only add the account if the address is yours.
if ( IsMine ( * pwalletMain , address . Get ( ) ) )
2012-08-21 16:38:57 +02:00
{
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:
if ( pwalletMain - > mapAddressBook . count ( address . Get ( ) ) )
{
string strOldAccount = pwalletMain - > mapAddressBook [ address . Get ( ) ] . name ;
if ( address = = GetAccountAddress ( strOldAccount ) )
GetAccountAddress ( strOldAccount , true ) ;
}
pwalletMain - > 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
}
2015-05-18 14:02:18 +02:00
UniValue getaccount ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( fHelp | | params . size ( ) ! = 1 )
throw runtime_error (
2013-10-29 12:29:44 +01:00
" getaccount \" bitcoinaddress \" \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 "
" 1. \" bitcoinaddress \" (string, required) The bitcoin address for account lookup. \n "
" \n Result: \n "
" \" accountname \" (string) the account address \n "
" \n Examples: \n "
+ HelpExampleCli ( " getaccount " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \" " )
+ HelpExampleRpc ( " getaccount " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \" " )
) ;
2012-08-21 16:38:57 +02:00
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
CBitcoinAddress address ( params [ 0 ] . get_str ( ) ) ;
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
string strAccount ;
2013-07-15 07:20:50 +02:00
map < CTxDestination , CAddressBookData > : : iterator mi = pwalletMain - > mapAddressBook . find ( address . Get ( ) ) ;
if ( mi ! = pwalletMain - > mapAddressBook . end ( ) & & ! ( * mi ) . second . name . empty ( ) )
strAccount = ( * mi ) . second . name ;
2012-08-21 16:38:57 +02:00
return strAccount ;
}
2015-05-18 14:02:18 +02:00
UniValue getaddressesbyaccount ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( fHelp | | params . size ( ) ! = 1 )
throw 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 "
" 1. \" account \" (string, required) The account name. \n "
" \n Result: \n "
" [ (json array of string) \n "
" \" bitcoinaddress \" (string) a bitcoin address associated with the given account \n "
" ,... \n "
" ] \n "
" \n Examples: \n "
+ HelpExampleCli ( " getaddressesbyaccount " , " \" tabby \" " )
+ HelpExampleRpc ( " getaddressesbyaccount " , " \" tabby \" " )
) ;
2012-08-21 16:38:57 +02:00
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
string strAccount = AccountFromValue ( params [ 0 ] ) ;
// Find all addresses that have the given account
2015-05-10 14:48:35 +02:00
UniValue ret ( UniValue : : VARR ) ;
2013-07-15 07:20:50 +02:00
BOOST_FOREACH ( const PAIRTYPE ( CBitcoinAddress , CAddressBookData ) & item , pwalletMain - > mapAddressBook )
2012-08-21 16:38:57 +02:00
{
const CBitcoinAddress & address = item . first ;
2013-07-15 07:20:50 +02:00
const string & strName = item . second . name ;
2012-08-21 16:38:57 +02:00
if ( strName = = strAccount )
ret . push_back ( address . ToString ( ) ) ;
}
return ret ;
}
2014-07-23 14:34:36 +02:00
static void SendMoney ( const CTxDestination & address , CAmount nValue , bool fSubtractFeeFromAmount , CWalletTx & wtxNew )
2014-12-01 20:06:45 +01:00
{
2014-12-09 14:50:01 +01:00
CAmount curBalance = pwalletMain - > GetBalance ( ) ;
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-05-25 02:56:17 +02:00
if ( pwalletMain - > GetBroadcastTransactions ( ) & & ! g_connman )
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
2014-12-01 20:06:45 +01:00
// Parse Bitcoin address
CScript scriptPubKey = GetScriptForDestination ( address ) ;
// Create and send the transaction
CReserveKey reservekey ( pwalletMain ) ;
CAmount nFeeRequired ;
2014-12-09 14:50:01 +01:00
std : : string strError ;
2014-07-23 14:34:36 +02:00
vector < CRecipient > vecSend ;
int nChangePosRet = - 1 ;
CRecipient recipient = { scriptPubKey , nValue , fSubtractFeeFromAmount } ;
vecSend . push_back ( recipient ) ;
if ( ! pwalletMain - > CreateTransaction ( vecSend , wtxNew , reservekey , nFeeRequired , nChangePosRet , strError ) ) {
if ( ! fSubtractFeeFromAmount & & nValue + nFeeRequired > pwalletMain - > GetBalance ( ) )
strError = strprintf ( " Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds! " , FormatMoney ( nFeeRequired ) ) ;
throw JSONRPCError ( RPC_WALLET_ERROR , strError ) ;
2014-12-01 20:06:45 +01:00
}
2016-05-25 02:56:17 +02:00
if ( ! pwalletMain - > CommitTransaction ( wtxNew , reservekey , g_connman . get ( ) ) )
2016-02-26 12:48:53 +01:00
throw JSONRPCError ( RPC_WALLET_ERROR , " Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of the wallet and coins were spent in the copy but not marked as spent here. " ) ;
2014-12-01 20:06:45 +01:00
}
2015-05-18 14:02:18 +02:00
UniValue sendtoaddress ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2014-07-23 14:34:36 +02:00
if ( fHelp | | params . size ( ) < 2 | | params . size ( ) > 5 )
2012-08-21 16:38:57 +02:00
throw runtime_error (
2014-07-23 14:34:36 +02:00
" sendtoaddress \" bitcoinaddress \" amount ( \" comment \" \" comment-to \" subtractfeefromamount ) \n "
2016-01-13 11:43:07 +01:00
" \n Send an amount to a given address. \n "
2013-10-29 12:29:44 +01:00
+ HelpRequiringPassphrase ( ) +
" \n Arguments: \n "
" 1. \" bitcoinaddress \" (string, required) The bitcoin address to send to. \n "
2016-01-13 11:43:07 +01:00
" 2. \" amount \" (numeric or string, required) The amount in " + CURRENCY_UNIT + " to send. eg 0.1 \n "
2013-10-29 12:29:44 +01:00
" 3. \" 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 "
" 4. \" comment-to \" (string, optional) A comment to store the name of the person or organization \n "
" 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 "
2013-10-29 12:29:44 +01:00
" \n Result: \n "
2014-05-29 18:17:34 +02:00
" \" transactionid \" (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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
CBitcoinAddress address ( params [ 0 ] . get_str ( ) ) ;
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
2014-04-23 00:46:19 +02:00
CAmount nAmount = AmountFromValue ( 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 ;
2014-08-20 21:15:16 +02:00
if ( params . size ( ) > 2 & & ! params [ 2 ] . isNull ( ) & & ! params [ 2 ] . get_str ( ) . empty ( ) )
2012-08-21 16:38:57 +02:00
wtx . mapValue [ " comment " ] = params [ 2 ] . get_str ( ) ;
2014-08-20 21:15:16 +02:00
if ( params . size ( ) > 3 & & ! params [ 3 ] . isNull ( ) & & ! params [ 3 ] . get_str ( ) . empty ( ) )
2012-08-21 16:38:57 +02:00
wtx . mapValue [ " to " ] = params [ 3 ] . get_str ( ) ;
2014-07-23 14:34:36 +02:00
bool fSubtractFeeFromAmount = false ;
if ( params . size ( ) > 4 )
fSubtractFeeFromAmount = params [ 4 ] . get_bool ( ) ;
2013-10-28 11:58:39 +01:00
EnsureWalletIsUnlocked ( ) ;
2012-08-21 16:38:57 +02:00
2014-07-23 14:34:36 +02:00
SendMoney ( address . Get ( ) , nAmount , fSubtractFeeFromAmount , wtx ) ;
2012-08-21 16:38:57 +02:00
return wtx . GetHash ( ) . GetHex ( ) ;
}
2015-05-18 14:02:18 +02:00
UniValue listaddressgroupings ( const UniValue & params , bool fHelp )
2012-08-01 18:48:42 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-01 18:48:42 +02:00
if ( fHelp )
2012-08-20 19:43:33 +02:00
throw runtime_error (
" 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 "
" \" bitcoinaddress \" , (string) The bitcoin address \n "
2015-08-01 21:15:23 +02:00
" amount, (numeric) The amount in " + CURRENCY_UNIT + " \n "
2014-12-30 15:32:07 +01:00
" \" account \" (string, optional) The account (DEPRECATED) \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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2015-05-10 14:48:35 +02:00
UniValue jsonGroupings ( UniValue : : VARR ) ;
2014-04-23 00:46:19 +02:00
map < CTxDestination , CAmount > balances = pwalletMain - > GetAddressBalances ( ) ;
2012-08-20 19:43:33 +02:00
BOOST_FOREACH ( set < CTxDestination > grouping , pwalletMain - > GetAddressGroupings ( ) )
2012-08-01 18:48:42 +02:00
{
2015-05-10 14:48:35 +02:00
UniValue jsonGrouping ( UniValue : : VARR ) ;
2012-08-20 19:43:33 +02:00
BOOST_FOREACH ( 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 ] ) ) ;
{
if ( pwalletMain - > mapAddressBook . find ( CBitcoinAddress ( address ) . Get ( ) ) ! = pwalletMain - > mapAddressBook . end ( ) )
2013-07-15 07:20:50 +02:00
addressInfo . push_back ( pwalletMain - > mapAddressBook . find ( CBitcoinAddress ( address ) . Get ( ) ) - > second . name ) ;
2012-08-01 18:48:42 +02:00
}
jsonGrouping . push_back ( addressInfo ) ;
}
jsonGroupings . push_back ( jsonGrouping ) ;
}
return jsonGroupings ;
}
2015-05-18 14:02:18 +02:00
UniValue signmessage ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( fHelp | | params . size ( ) ! = 2 )
throw runtime_error (
2013-10-29 12:29:44 +01:00
" signmessage \" bitcoinaddress \" \" message \" \n "
" \n Sign a message with the private key of an address "
+ HelpRequiringPassphrase ( ) + " \n "
" \n Arguments: \n "
" 1. \" bitcoinaddress \" (string, required) The bitcoin address to use for the private key. \n "
" 2. \" message \" (string, required) The message to create a signature of. \n "
" \n Result: \n "
" \" signature \" (string) The signature of the message encoded in base 64 \n "
" \n Examples: \n "
" \n Unlock the wallet for 30 seconds \n "
+ HelpExampleCli ( " walletpassphrase " , " \" mypassphrase \" 30 " ) +
" \n Create the signature \n "
+ HelpExampleCli ( " signmessage " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \" \" my message \" " ) +
" \n Verify the signature \n "
+ HelpExampleCli ( " verifymessage " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \" \" signature \" \" my message \" " ) +
" \n As json rpc \n "
+ HelpExampleRpc ( " signmessage " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \" , \" my message \" " )
) ;
2012-08-21 16:38:57 +02:00
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
EnsureWalletIsUnlocked ( ) ;
string strAddress = params [ 0 ] . get_str ( ) ;
string strMessage = params [ 1 ] . get_str ( ) ;
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 ;
if ( ! pwalletMain - > GetKey ( keyID , key ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_ERROR , " Private key not available " ) ;
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 ;
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 ( ) ) ;
}
2015-05-18 14:02:18 +02:00
UniValue getreceivedbyaddress ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( fHelp | | params . size ( ) < 1 | | params . size ( ) > 2 )
throw runtime_error (
2013-10-29 12:29:44 +01:00
" getreceivedbyaddress \" bitcoinaddress \" ( minconf ) \n "
" \n Returns the total amount received by the given bitcoinaddress in transactions with at least minconf confirmations. \n "
" \n Arguments: \n "
" 1. \" bitcoinaddress \" (string, required) The bitcoin address for transactions. \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 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 "
+ HelpExampleCli ( " getreceivedbyaddress " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \" " ) +
" \n The amount including unconfirmed transactions, zero confirmations \n "
+ HelpExampleCli ( " getreceivedbyaddress " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \" 0 " ) +
" \n The amount with at least 6 confirmation, very safe \n "
+ HelpExampleCli ( " getreceivedbyaddress " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \" 6 " ) +
" \n As a json rpc call \n "
+ HelpExampleRpc ( " getreceivedbyaddress " , " \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \" , 6 " )
) ;
2012-08-21 16:38:57 +02:00
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
// Bitcoin address
CBitcoinAddress address = CBitcoinAddress ( params [ 0 ] . get_str ( ) ) ;
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-07-08 12:01:39 +02:00
if ( ! IsMine ( * pwalletMain , scriptPubKey ) )
return ValueFromAmount ( 0 ) ;
2012-08-21 16:38:57 +02:00
// Minimum confirmations
int nMinDepth = 1 ;
if ( params . size ( ) > 1 )
nMinDepth = params [ 1 ] . get_int ( ) ;
// Tally
2014-04-23 00:46:19 +02:00
CAmount nAmount = 0 ;
2012-08-21 16:38:57 +02:00
for ( map < uint256 , CWalletTx > : : iterator it = pwalletMain - > mapWallet . begin ( ) ; it ! = pwalletMain - > mapWallet . end ( ) ; + + it )
{
const CWalletTx & wtx = ( * it ) . second ;
2015-05-25 06:48:33 +02:00
if ( wtx . IsCoinBase ( ) | | ! CheckFinalTx ( wtx ) )
2012-08-21 16:38:57 +02:00
continue ;
BOOST_FOREACH ( const CTxOut & txout , wtx . vout )
if ( txout . scriptPubKey = = scriptPubKey )
if ( wtx . GetDepthInMainChain ( ) > = nMinDepth )
nAmount + = txout . nValue ;
}
return ValueFromAmount ( nAmount ) ;
}
2015-05-18 14:02:18 +02:00
UniValue getreceivedbyaccount ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( fHelp | | params . size ( ) < 1 | | params . size ( ) > 2 )
throw 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 " ) +
" \n The amount with at least 6 confirmation, very safe \n "
+ HelpExampleCli ( " getreceivedbyaccount " , " \" tabby \" 6 " ) +
" \n As a json rpc call \n "
+ HelpExampleRpc ( " getreceivedbyaccount " , " \" tabby \" , 6 " )
) ;
2012-08-21 16:38:57 +02:00
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
// Minimum confirmations
int nMinDepth = 1 ;
if ( params . size ( ) > 1 )
nMinDepth = params [ 1 ] . get_int ( ) ;
// Get the set of pub keys assigned to account
string strAccount = AccountFromValue ( params [ 0 ] ) ;
2013-07-16 01:01:09 +02:00
set < CTxDestination > setAddress = pwalletMain - > GetAccountAddresses ( strAccount ) ;
2012-08-21 16:38:57 +02:00
// Tally
2014-04-23 00:46:19 +02:00
CAmount nAmount = 0 ;
2012-08-21 16:38:57 +02:00
for ( map < uint256 , CWalletTx > : : iterator it = pwalletMain - > mapWallet . begin ( ) ; it ! = pwalletMain - > mapWallet . end ( ) ; + + it )
{
const CWalletTx & wtx = ( * it ) . second ;
2015-05-25 06:48:33 +02:00
if ( wtx . IsCoinBase ( ) | | ! CheckFinalTx ( wtx ) )
2012-08-21 16:38:57 +02:00
continue ;
BOOST_FOREACH ( const CTxOut & txout , wtx . vout )
{
CTxDestination address ;
if ( ExtractDestination ( txout . scriptPubKey , address ) & & IsMine ( * pwalletMain , address ) & & setAddress . count ( address ) )
if ( wtx . GetDepthInMainChain ( ) > = nMinDepth )
nAmount + = txout . nValue ;
}
}
2016-07-08 12:01:39 +02:00
return ValueFromAmount ( nAmount ) ;
2012-08-21 16:38:57 +02:00
}
2015-05-18 14:02:18 +02:00
UniValue getbalance ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2014-04-08 15:23:50 +02:00
if ( fHelp | | params . size ( ) > 3 )
2012-08-21 16:38:57 +02:00
throw runtime_error (
2014-04-08 15:23:50 +02:00
" getbalance ( \" account \" minconf includeWatchonly ) \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 "
2014-12-30 15:32:07 +01:00
" 1. \" account \" (string, optional) DEPRECATED. The selected account, or \" * \" for entire wallet. It may be the default account using \" \" . \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 "
2014-04-08 15:23:50 +02:00
" 3. includeWatchonly (bool, optional, default=false) Also include balance in watchonly 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 "
2014-12-30 15:32:07 +01:00
" \n The total amount in the wallet \n "
2013-10-29 12:29:44 +01:00
+ HelpExampleCli ( " getbalance " , " " ) +
2014-12-30 15:32:07 +01:00
" \n The total amount in the wallet at least 5 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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
if ( params . size ( ) = = 0 )
return ValueFromAmount ( pwalletMain - > GetBalance ( ) ) ;
int nMinDepth = 1 ;
if ( params . size ( ) > 1 )
nMinDepth = params [ 1 ] . get_int ( ) ;
2014-07-01 11:00:22 +02:00
isminefilter filter = ISMINE_SPENDABLE ;
2014-04-29 19:39:01 +02:00
if ( params . size ( ) > 2 )
if ( 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
if ( params [ 0 ] . get_str ( ) = = " * " ) {
// Calculate total balance a different way from GetBalance()
// (GetBalance() sums up all unspent TxOuts)
2015-06-12 23:07:43 +02:00
// getbalance and "getbalance * 1 true" should return the same number
2014-04-23 00:46:19 +02:00
CAmount nBalance = 0 ;
2012-08-21 16:38:57 +02:00
for ( map < uint256 , CWalletTx > : : iterator it = pwalletMain - > mapWallet . begin ( ) ; it ! = pwalletMain - > mapWallet . end ( ) ; + + it )
{
const CWalletTx & wtx = ( * it ) . second ;
2015-06-12 23:07:43 +02:00
if ( ! CheckFinalTx ( wtx ) | | wtx . GetBlocksToMaturity ( ) > 0 | | wtx . GetDepthInMainChain ( ) < 0 )
2012-08-21 16:38:57 +02:00
continue ;
2014-04-23 00:46:19 +02:00
CAmount allFee ;
2012-08-21 16:38:57 +02:00
string strSentAccount ;
2014-05-30 00:54:00 +02:00
list < COutputEntry > listReceived ;
list < COutputEntry > listSent ;
2014-04-08 15:23:50 +02:00
wtx . GetAmounts ( listReceived , listSent , allFee , strSentAccount , filter ) ;
2012-08-21 16:38:57 +02:00
if ( wtx . GetDepthInMainChain ( ) > = nMinDepth )
{
2014-05-30 00:54:00 +02:00
BOOST_FOREACH ( const COutputEntry & r , listReceived )
nBalance + = r . amount ;
2012-08-21 16:38:57 +02:00
}
2014-05-30 00:54:00 +02:00
BOOST_FOREACH ( const COutputEntry & s , listSent )
nBalance - = s . amount ;
2012-08-21 16:38:57 +02:00
nBalance - = allFee ;
}
return ValueFromAmount ( nBalance ) ;
}
string strAccount = AccountFromValue ( params [ 0 ] ) ;
2016-05-17 02:11:24 +02:00
CAmount nBalance = pwalletMain - > GetAccountBalance ( strAccount , nMinDepth , filter ) ;
2012-08-21 16:38:57 +02:00
return ValueFromAmount ( nBalance ) ;
}
2015-05-18 14:02:18 +02:00
UniValue getunconfirmedbalance ( const UniValue & params , bool fHelp )
2013-11-24 12:48:52 +01:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2013-11-24 12:48:52 +01:00
if ( fHelp | | params . size ( ) > 0 )
throw runtime_error (
" getunconfirmedbalance \n "
" Returns the server's total unconfirmed balance \n " ) ;
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2013-11-24 12:48:52 +01:00
return ValueFromAmount ( pwalletMain - > GetUnconfirmedBalance ( ) ) ;
}
2012-08-21 16:38:57 +02:00
2015-05-18 14:02:18 +02:00
UniValue movecmd ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( fHelp | | params . size ( ) < 3 | | params . size ( ) > 5 )
throw 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 "
" 4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations. \n "
" 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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
string strFrom = AccountFromValue ( params [ 0 ] ) ;
string strTo = AccountFromValue ( params [ 1 ] ) ;
2014-04-23 00:46:19 +02:00
CAmount nAmount = AmountFromValue ( 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
if ( params . size ( ) > 3 )
// unused parameter, used to be nMinDepth, keep type-checking it though
( void ) params [ 3 ] . get_int ( ) ;
string strComment ;
if ( params . size ( ) > 4 )
strComment = params [ 4 ] . get_str ( ) ;
2016-06-02 15:00:59 +02:00
if ( ! pwalletMain - > AccountMove ( strFrom , strTo , nAmount , strComment ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_DATABASE_ERROR , " database error " ) ;
2012-08-21 16:38:57 +02:00
return true ;
}
2015-05-18 14:02:18 +02:00
UniValue sendfrom ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( fHelp | | params . size ( ) < 3 | | params . size ( ) > 6 )
throw runtime_error (
2013-10-29 12:29:44 +01:00
" sendfrom \" fromaccount \" \" tobitcoinaddress \" 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. "
2013-10-29 12:29:44 +01:00
+ HelpRequiringPassphrase ( ) + " \n "
" \n Arguments: \n "
" 1. \" fromaccount \" (string, required) The name of the account to send funds from. May be the default account using \" \" . \n "
" 2. \" tobitcoinaddress \" (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 "
" 6. \" comment-to \" (string, optional) An optional comment to store the name of the person or organization \n "
" 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 "
2014-05-29 18:17:34 +02:00
" \" transactionid \" (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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
string strAccount = AccountFromValue ( params [ 0 ] ) ;
CBitcoinAddress address ( params [ 1 ] . get_str ( ) ) ;
if ( ! address . IsValid ( ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Invalid Bitcoin address " ) ;
2014-04-23 00:46:19 +02:00
CAmount nAmount = AmountFromValue ( 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 ;
if ( params . size ( ) > 3 )
nMinDepth = params [ 3 ] . get_int ( ) ;
CWalletTx wtx ;
wtx . strFromAccount = strAccount ;
2014-08-20 21:15:16 +02:00
if ( params . size ( ) > 4 & & ! params [ 4 ] . isNull ( ) & & ! params [ 4 ] . get_str ( ) . empty ( ) )
2012-08-21 16:38:57 +02:00
wtx . mapValue [ " comment " ] = params [ 4 ] . get_str ( ) ;
2014-08-20 21:15:16 +02:00
if ( params . size ( ) > 5 & & ! params [ 5 ] . isNull ( ) & & ! params [ 5 ] . get_str ( ) . empty ( ) )
2012-08-21 16:38:57 +02:00
wtx . mapValue [ " to " ] = params [ 5 ] . get_str ( ) ;
EnsureWalletIsUnlocked ( ) ;
// Check funds
2016-05-17 02:11:24 +02:00
CAmount nBalance = pwalletMain - > GetAccountBalance ( strAccount , nMinDepth , ISMINE_SPENDABLE ) ;
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
2014-07-23 14:34:36 +02:00
SendMoney ( address . Get ( ) , nAmount , false , wtx ) ;
2012-08-21 16:38:57 +02:00
return wtx . GetHash ( ) . GetHex ( ) ;
}
2015-05-18 14:02:18 +02:00
UniValue sendmany ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2014-07-23 14:34:36 +02:00
if ( fHelp | | params . size ( ) < 2 | | params . size ( ) > 5 )
2012-08-21 16:38:57 +02:00
throw runtime_error (
2015-03-05 14:30:15 +01:00
" sendmany \" fromaccount \" { \" address \" :amount,...} ( minconf \" comment \" [ \" address \" ,...] ) \n "
2013-10-29 12:29:44 +01:00
" \n Send multiple times. Amounts are double-precision floating point numbers. "
+ HelpRequiringPassphrase ( ) + " \n "
" \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 "
2015-03-05 14:30:15 +01:00
" 5. subtractfeefromamount (string, 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 "
" \" 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 "
2013-10-29 12:29:44 +01:00
" \n Result: \n "
" \" transactionid \" (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 "
2014-12-30 15:32:07 +01:00
+ HelpExampleCli ( " sendmany " , " \" \" \" { \\ \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \\ \" :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 "
2014-12-30 15:32:07 +01:00
+ HelpExampleCli ( " sendmany " , " \" \" \" { \\ \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \\ \" :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 "
2015-03-05 14:30:15 +01:00
+ HelpExampleCli ( " sendmany " , " \" \" \" { \\ \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \\ \" :0.01, \\ \" 1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz \\ \" :0.02} \" 1 \" \" \" [ \\ \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \\ \" , \\ \" 1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz \\ \" ] \" " ) +
2013-10-29 12:29:44 +01:00
" \n As a json rpc call \n "
2014-12-30 15:32:07 +01:00
+ HelpExampleRpc ( " sendmany " , " \" \" , \" { \\ \" 1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ \\ \" :0.01, \\ \" 1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz \\ \" :0.02} \" , 6, \" testing \" " )
2013-10-29 12:29:44 +01:00
) ;
2012-08-21 16:38:57 +02:00
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2016-05-25 02:56:17 +02:00
if ( pwalletMain - > GetBroadcastTransactions ( ) & & ! g_connman )
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
2012-08-21 16:38:57 +02:00
string strAccount = AccountFromValue ( params [ 0 ] ) ;
2015-05-13 21:29:19 +02:00
UniValue sendTo = params [ 1 ] . get_obj ( ) ;
2012-08-21 16:38:57 +02:00
int nMinDepth = 1 ;
if ( params . size ( ) > 2 )
nMinDepth = params [ 2 ] . get_int ( ) ;
CWalletTx wtx ;
wtx . strFromAccount = strAccount ;
2014-08-20 21:15:16 +02:00
if ( params . size ( ) > 3 & & ! params [ 3 ] . isNull ( ) & & ! params [ 3 ] . get_str ( ) . empty ( ) )
2012-08-21 16:38:57 +02:00
wtx . mapValue [ " comment " ] = params [ 3 ] . get_str ( ) ;
2015-05-10 14:48:35 +02:00
UniValue subtractFeeFromAmount ( UniValue : : VARR ) ;
2014-07-23 14:34:36 +02:00
if ( params . size ( ) > 4 )
2015-03-05 14:30:15 +01:00
subtractFeeFromAmount = params [ 4 ] . get_array ( ) ;
2014-07-23 14:34:36 +02:00
2012-08-21 16:38:57 +02:00
set < CBitcoinAddress > setAddress ;
2014-07-23 14:34:36 +02:00
vector < CRecipient > vecSend ;
2012-08-21 16:38:57 +02:00
2014-04-23 00:46:19 +02:00
CAmount totalAmount = 0 ;
2014-08-20 21:15:16 +02:00
vector < string > keys = sendTo . getKeys ( ) ;
BOOST_FOREACH ( const 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 ( ) )
2014-08-20 21:15:16 +02:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , string ( " Invalid Bitcoin address: " ) + name_ ) ;
2012-08-21 16:38:57 +02:00
if ( setAddress . count ( address ) )
2014-08-20 21:15:16 +02:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , 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
}
EnsureWalletIsUnlocked ( ) ;
// Check funds
2016-05-17 02:11:24 +02:00
CAmount nBalance = pwalletMain - > GetAccountBalance ( strAccount , nMinDepth , ISMINE_SPENDABLE ) ;
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
CReserveKey keyChange ( pwalletMain ) ;
2014-04-23 00:46:19 +02:00
CAmount nFeeRequired = 0 ;
2014-07-23 14:34:36 +02:00
int nChangePosRet = - 1 ;
2013-04-25 23:31:22 +02:00
string strFailReason ;
2014-07-23 14:34:36 +02:00
bool fCreated = pwalletMain - > CreateTransaction ( vecSend , wtx , keyChange , nFeeRequired , nChangePosRet , strFailReason ) ;
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-05-25 02:56:17 +02:00
if ( ! pwalletMain - > CommitTransaction ( wtx , keyChange , g_connman . get ( ) ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_ERROR , " Transaction commit failed " ) ;
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
2015-05-18 14:02:18 +02:00
extern CScript _createmultisig_redeemScript ( const UniValue & params ) ;
2012-09-10 15:32:40 +02:00
2015-05-18 14:02:18 +02:00
UniValue addmultisigaddress ( const UniValue & params , bool fHelp )
2012-09-10 15:32:40 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-09-10 15:32:40 +02:00
if ( fHelp | | params . size ( ) < 2 | | params . size ( ) > 3 )
{
2013-10-29 12:29:44 +01:00
string msg = " addmultisigaddress nrequired [ \" key \" ,...] ( \" account \" ) \n "
" \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 "
" 2. \" keysobject \" (string, required) A json array of bitcoin addresses or hex-encoded public keys \n "
" [ \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 "
" \" bitcoinaddress \" (string) A bitcoin address associated with the keys. \n "
" \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 \\ \" ] \" " )
;
2012-09-10 15:32:40 +02:00
throw runtime_error ( msg ) ;
}
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-09-10 15:32:40 +02:00
string strAccount ;
if ( params . size ( ) > 2 )
strAccount = AccountFromValue ( params [ 2 ] ) ;
2012-08-21 16:38:57 +02:00
// Construct using pay-to-script-hash:
2014-03-11 03:43:15 +01:00
CScript inner = _createmultisig_redeemScript ( params ) ;
2014-09-25 04:24:46 +02:00
CScriptID innerID ( inner ) ;
2012-08-21 16:38:57 +02:00
pwalletMain - > AddCScript ( inner ) ;
2013-07-22 08:50:39 +02:00
pwalletMain - > 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 :
CScriptID result ;
bool operator ( ) ( const CNoDestination & dest ) const { return false ; }
bool operator ( ) ( const CKeyID & keyID ) {
CPubKey pubkey ;
2016-10-16 18:32:36 +02:00
if ( pwalletMain ) {
CScript basescript = GetScriptForDestination ( keyID ) ;
isminetype typ ;
typ = IsMine ( * pwalletMain , basescript , SIGVERSION_WITNESS_V0 ) ;
if ( typ ! = ISMINE_SPENDABLE & & typ ! = ISMINE_WATCH_SOLVABLE )
return false ;
2015-12-30 01:13:08 +01:00
CScript witscript = GetScriptForWitness ( basescript ) ;
pwalletMain - > AddCScript ( witscript ) ;
result = CScriptID ( witscript ) ;
return true ;
}
return false ;
}
bool operator ( ) ( const CScriptID & scriptID ) {
CScript subscript ;
if ( pwalletMain & & pwalletMain - > GetCScript ( scriptID , subscript ) ) {
int witnessversion ;
std : : vector < unsigned char > witprog ;
if ( subscript . IsWitnessProgram ( witnessversion , witprog ) ) {
result = scriptID ;
return true ;
}
2016-10-16 18:32:36 +02:00
isminetype typ ;
typ = IsMine ( * pwalletMain , subscript , SIGVERSION_WITNESS_V0 ) ;
if ( typ ! = ISMINE_SPENDABLE & & typ ! = ISMINE_WATCH_SOLVABLE )
return false ;
2015-12-30 01:13:08 +01:00
CScript witscript = GetScriptForWitness ( subscript ) ;
pwalletMain - > AddCScript ( witscript ) ;
result = CScriptID ( witscript ) ;
return true ;
}
return false ;
}
} ;
UniValue addwitnessaddress ( const UniValue & params , bool fHelp )
{
if ( ! EnsureWalletIsAvailable ( fHelp ) )
return NullUniValue ;
if ( fHelp | | params . size ( ) < 1 | | params . size ( ) > 1 )
{
string msg = " addwitnessaddress \" address \" \n "
" \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 "
;
throw runtime_error ( msg ) ;
}
{
LOCK ( cs_main ) ;
2016-01-02 06:18:34 +01:00
if ( ! IsWitnessEnabled ( chainActive . Tip ( ) , Params ( ) . GetConsensus ( ) ) & & ! GetBoolArg ( " -walletprematurewitness " , false ) ) {
2015-12-30 01:13:08 +01:00
throw JSONRPCError ( RPC_WALLET_ERROR , " Segregated witness not enabled on network " ) ;
}
}
CBitcoinAddress address ( params [ 0 ] . get_str ( ) ) ;
if ( ! address . IsValid ( ) )
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Invalid Bitcoin address " ) ;
Witnessifier w ;
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-09-09 18:13:18 +02:00
pwalletMain - > SetAddressBook ( w . result , " " , " receive " ) ;
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 ;
2012-12-13 15:59:10 +01:00
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
}
} ;
2015-05-18 14:02:18 +02:00
UniValue ListReceived ( const UniValue & params , bool fByAccounts )
2012-08-21 16:38:57 +02:00
{
// Minimum confirmations
int nMinDepth = 1 ;
if ( params . size ( ) > 0 )
nMinDepth = params [ 0 ] . get_int ( ) ;
// Whether to include empty accounts
bool fIncludeEmpty = false ;
if ( params . size ( ) > 1 )
fIncludeEmpty = params [ 1 ] . get_bool ( ) ;
2014-07-01 11:00:22 +02:00
isminefilter filter = ISMINE_SPENDABLE ;
2014-05-31 16:57:26 +02:00
if ( params . size ( ) > 2 )
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
map < CBitcoinAddress , tallyitem > mapTally ;
for ( map < uint256 , CWalletTx > : : iterator it = pwalletMain - > mapWallet . begin ( ) ; it ! = pwalletMain - > mapWallet . end ( ) ; + + it )
{
const CWalletTx & wtx = ( * it ) . second ;
2015-05-25 06:48:33 +02:00
if ( wtx . IsCoinBase ( ) | | ! CheckFinalTx ( wtx ) )
2012-08-21 16:38:57 +02:00
continue ;
int nDepth = wtx . GetDepthInMainChain ( ) ;
if ( nDepth < nMinDepth )
continue ;
BOOST_FOREACH ( const CTxOut & txout , wtx . vout )
{
CTxDestination address ;
2014-05-31 16:57:26 +02:00
if ( ! ExtractDestination ( txout . scriptPubKey , address ) )
continue ;
isminefilter mine = IsMine ( * pwalletMain , 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 ;
item . nConf = 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 ) ;
2012-08-21 16:38:57 +02:00
map < string , tallyitem > mapAccountTally ;
2013-07-15 07:20:50 +02:00
BOOST_FOREACH ( const PAIRTYPE ( CBitcoinAddress , CAddressBookData ) & item , pwalletMain - > mapAddressBook )
2012-08-21 16:38:57 +02:00
{
const CBitcoinAddress & address = item . first ;
2013-07-15 07:20:50 +02:00
const string & strAccount = item . second . name ;
2012-08-21 16:38:57 +02:00
map < CBitcoinAddress , tallyitem > : : iterator it = mapTally . find ( address ) ;
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 ;
_item . nConf = min ( _item . nConf , nConf ) ;
_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
{
2016-06-11 16:35:19 +02:00
BOOST_FOREACH ( 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 )
{
for ( map < string , tallyitem > : : iterator it = mapAccountTally . begin ( ) ; it ! = mapAccountTally . end ( ) ; + + it )
{
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 ;
}
2015-05-18 14:02:18 +02:00
UniValue listreceivedbyaddress ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2014-05-31 16:57:26 +02:00
if ( fHelp | | params . size ( ) > 3 )
2012-08-21 16:38:57 +02:00
throw runtime_error (
2014-05-31 16:57:26 +02:00
" listreceivedbyaddress ( minconf includeempty includeWatchonly) \n "
2013-10-29 12:29:44 +01:00
" \n List balances by receiving address. \n "
" \n Arguments: \n "
" 1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included. \n "
2016-02-12 19:55:32 +01:00
" 2. includeempty (bool, optional, default=false) Whether to include addresses that haven't received any payments. \n "
2014-05-31 16:57:26 +02:00
" 3. includeWatchonly (bool, optional, default=false) Whether to include watchonly 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 "
" \" 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 ( " 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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
return ListReceived ( params , false ) ;
}
2015-05-18 14:02:18 +02:00
UniValue listreceivedbyaccount ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2014-05-31 16:57:26 +02:00
if ( fHelp | | params . size ( ) > 3 )
2012-08-21 16:38:57 +02:00
throw runtime_error (
2014-05-31 16:57:26 +02:00
" listreceivedbyaccount ( minconf includeempty includeWatchonly) \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 "
" 1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included. \n "
2016-02-12 19:55:32 +01:00
" 2. includeempty (bool, optional, default=false) Whether to include accounts that haven't received any payments. \n "
2014-05-31 16:57:26 +02:00
" 3. includeWatchonly (bool, optional, default=false) Whether to include watchonly 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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
return ListReceived ( params , true ) ;
}
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 ( ) ) ) ;
}
2015-05-18 14:02:18 +02:00
void ListTransactions ( const CWalletTx & wtx , const 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 ;
2012-08-21 16:38:57 +02:00
string strSentAccount ;
2014-05-30 00:54:00 +02:00
list < COutputEntry > listReceived ;
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
bool fAllAccounts = ( strAccount = = 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 ) )
{
2014-05-30 00:54:00 +02:00
BOOST_FOREACH ( const COutputEntry & s , listSent )
2012-08-21 16:38:57 +02:00
{
2015-05-10 14:48:35 +02:00
UniValue entry ( UniValue : : VOBJ ) ;
2014-05-30 00:54:00 +02:00
if ( involvesWatchonly | | ( : : IsMine ( * pwalletMain , s . destination ) & ISMINE_WATCH_ONLY ) )
2014-04-09 17:20:07 +02:00
entry . push_back ( Pair ( " involvesWatchonly " , true ) ) ;
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 ) ) ) ;
2014-12-30 15:12:37 +01:00
if ( pwalletMain - > mapAddressBook . count ( s . destination ) )
entry . push_back ( Pair ( " label " , pwalletMain - > mapAddressBook [ s . destination ] . name ) ) ;
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 )
{
2014-05-30 00:54:00 +02:00
BOOST_FOREACH ( const COutputEntry & r , listReceived )
2012-08-21 16:38:57 +02:00
{
string account ;
2014-05-30 00:54:00 +02:00
if ( pwalletMain - > mapAddressBook . count ( r . destination ) )
account = pwalletMain - > mapAddressBook [ r . destination ] . name ;
2012-08-21 16:38:57 +02:00
if ( fAllAccounts | | ( account = = strAccount ) )
{
2015-05-10 14:48:35 +02:00
UniValue entry ( UniValue : : VOBJ ) ;
2014-05-30 00:54:00 +02:00
if ( involvesWatchonly | | ( : : IsMine ( * pwalletMain , r . destination ) & ISMINE_WATCH_ONLY ) )
2014-04-09 17:20:07 +02:00
entry . push_back ( Pair ( " involvesWatchonly " , true ) ) ;
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 ) ) ) ;
2014-12-30 15:12:37 +01:00
if ( pwalletMain - > mapAddressBook . count ( r . destination ) )
entry . push_back ( Pair ( " label " , account ) ) ;
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 ) ;
}
}
}
}
2015-05-18 14:02:18 +02:00
void AcentryToJSON ( const CAccountingEntry & acentry , const string & strAccount , UniValue & ret )
2012-08-21 16:38:57 +02:00
{
bool fAllAccounts = ( strAccount = = string ( " * " ) ) ;
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 ) ;
}
}
2015-05-18 14:02:18 +02:00
UniValue listtransactions ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2014-04-08 17:51:04 +02:00
if ( fHelp | | params . size ( ) > 4 )
2012-08-21 16:38:57 +02:00
throw runtime_error (
2014-04-08 17:51:04 +02:00
" listtransactions ( \" account \" count from includeWatchonly) \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 "
" 3. from (numeric, optional, default=0) The number of transactions to skip \n "
2014-04-08 17:51:04 +02:00
" 4. includeWatchonly (bool, optional, default=false) Include transactions to watchonly 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 "
" \" address \" : \" bitcoinaddress \" , (string) The bitcoin address of the transaction. Not present for \n "
" 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 "
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 "
2016-03-24 21:43:14 +01:00
" \" abandoned \" : xxx (bool) 'true' if the transaction has been abandoned (inputs are respendable). \n "
2013-10-29 12:29:44 +01:00
" \" 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 "
2015-11-26 18:42:07 +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 "
2015-11-20 12:51:36 +01:00
" \" label \" : \" label \" (string) A comment for the address/transaction, if any \n "
2013-10-29 12:29:44 +01:00
" \" otheraccount \" : \" accountname \" , (string) For the 'move' category of transactions, the account the funds came \n "
" from (for receiving funds, positive amounts), or went to (for sending funds, \n "
" negative amounts). \n "
2015-12-16 20:57:54 +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 "
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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
string strAccount = " * " ;
if ( params . size ( ) > 0 )
strAccount = params [ 0 ] . get_str ( ) ;
int nCount = 10 ;
if ( params . size ( ) > 1 )
nCount = params [ 1 ] . get_int ( ) ;
int nFrom = 0 ;
if ( params . size ( ) > 2 )
nFrom = params [ 2 ] . get_int ( ) ;
2014-07-01 11:00:22 +02:00
isminefilter filter = ISMINE_SPENDABLE ;
2014-04-29 19:39:01 +02:00
if ( params . size ( ) > 3 )
if ( 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
2015-10-19 11:19:38 +02:00
const CWallet : : TxItems & txOrdered = pwalletMain - > 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 )
2014-04-08 17:51:04 +02:00
ListTransactions ( * 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
vector < UniValue > arrTmp = ret . getValues ( ) ;
vector < UniValue > : : iterator first = arrTmp . begin ( ) ;
2012-08-21 16:38:57 +02:00
std : : advance ( first , nFrom ) ;
2014-08-20 21:15:16 +02:00
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 ;
}
2015-05-18 14:02:18 +02:00
UniValue listaccounts ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2014-04-08 16:13:15 +02:00
if ( fHelp | | params . size ( ) > 2 )
2012-08-21 16:38:57 +02:00
throw runtime_error (
2014-04-08 16:13:15 +02:00
" listaccounts ( minconf includeWatchonly) \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 "
2014-11-16 15:02:21 +01:00
" 1. minconf (numeric, optional, default=1) Only include transactions with at least this many confirmations \n "
2014-04-08 16:13:15 +02:00
" 2. includeWatchonly (bool, optional, default=false) Include balances in watchonly 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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
int nMinDepth = 1 ;
if ( params . size ( ) > 0 )
nMinDepth = params [ 0 ] . get_int ( ) ;
2014-07-01 11:00:22 +02:00
isminefilter includeWatchonly = ISMINE_SPENDABLE ;
2014-04-29 19:39:01 +02:00
if ( params . size ( ) > 1 )
if ( 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
2014-04-23 00:46:19 +02:00
map < string , CAmount > mapAccountBalances ;
2013-07-15 07:20:50 +02:00
BOOST_FOREACH ( const PAIRTYPE ( CTxDestination , CAddressBookData ) & entry , pwalletMain - > mapAddressBook ) {
2014-04-08 16:13:15 +02:00
if ( IsMine ( * pwalletMain , entry . first ) & includeWatchonly ) // This address belongs to me
2013-07-15 07:20:50 +02:00
mapAccountBalances [ entry . second . name ] = 0 ;
2012-08-21 16:38:57 +02:00
}
for ( map < uint256 , CWalletTx > : : iterator it = pwalletMain - > mapWallet . begin ( ) ; it ! = pwalletMain - > mapWallet . end ( ) ; + + it )
{
const CWalletTx & wtx = ( * it ) . second ;
2014-04-23 00:46:19 +02:00
CAmount nFee ;
2012-08-21 16:38:57 +02:00
string strSentAccount ;
2014-05-30 00:54:00 +02:00
list < COutputEntry > listReceived ;
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 ;
2014-05-30 00:54:00 +02:00
BOOST_FOREACH ( const COutputEntry & s , listSent )
mapAccountBalances [ strSentAccount ] - = s . amount ;
2014-02-15 22:38:28 +01:00
if ( nDepth > = nMinDepth )
2012-08-21 16:38:57 +02:00
{
2014-05-30 00:54:00 +02:00
BOOST_FOREACH ( const COutputEntry & r , listReceived )
if ( pwalletMain - > mapAddressBook . count ( r . destination ) )
mapAccountBalances [ pwalletMain - > mapAddressBook [ r . destination ] . name ] + = r . amount ;
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
}
}
2015-10-19 11:19:38 +02:00
const list < CAccountingEntry > & acentries = pwalletMain - > laccentries ;
2012-08-21 16:38:57 +02:00
BOOST_FOREACH ( const CAccountingEntry & entry , acentries )
mapAccountBalances [ entry . strAccount ] + = entry . nCreditDebit ;
2015-05-10 14:48:35 +02:00
UniValue ret ( UniValue : : VOBJ ) ;
2014-04-23 00:46:19 +02:00
BOOST_FOREACH ( const PAIRTYPE ( string , CAmount ) & accountBalance , mapAccountBalances ) {
2012-08-21 16:38:57 +02:00
ret . push_back ( Pair ( accountBalance . first , ValueFromAmount ( accountBalance . second ) ) ) ;
}
return ret ;
}
2015-05-18 14:02:18 +02:00
UniValue listsinceblock ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( fHelp )
throw runtime_error (
2014-04-08 17:51:04 +02:00
" listsinceblock ( \" blockhash \" target-confirmations includeWatchonly) \n "
2013-10-29 12:29:44 +01:00
" \n Get all transactions in blocks since block [blockhash], or all transactions if omitted \n "
" \n Arguments: \n "
" 1. \" blockhash \" (string, optional) The block hash to list transactions since \n "
" 2. target-confirmations: (numeric, optional) The confirmations required, must be 1 or more \n "
2014-04-08 17:51:04 +02:00
" 3. includeWatchonly: (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress') "
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 "
2013-10-29 12:29:44 +01:00
" \" address \" : \" bitcoinaddress \" , (string) The bitcoin address of the transaction. Not present for move transactions (category = move). \n "
" \" 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 "
" \" 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 "
" \" 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 "
" ], \n "
" \" lastblock \" : \" lastblockhash \" (string) The hash of the last block \n "
" } \n "
" \n Examples: \n "
+ HelpExampleCli ( " listsinceblock " , " " )
+ HelpExampleCli ( " listsinceblock " , " \" 000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad \" 6 " )
+ HelpExampleRpc ( " listsinceblock " , " \" 000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad \" , 6 " )
) ;
2012-08-21 16:38:57 +02:00
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
CBlockIndex * pindex = NULL ;
int target_confirms = 1 ;
2014-07-01 11:00:22 +02:00
isminefilter filter = ISMINE_SPENDABLE ;
2012-08-21 16:38:57 +02:00
if ( params . size ( ) > 0 )
{
2014-12-15 09:11:16 +01:00
uint256 blockId ;
2012-08-21 16:38:57 +02:00
blockId . SetHex ( params [ 0 ] . get_str ( ) ) ;
2014-09-04 02:02:44 +02:00
BlockMap : : iterator it = mapBlockIndex . find ( blockId ) ;
2013-10-12 15:18:08 +02:00
if ( it ! = mapBlockIndex . end ( ) )
pindex = it - > second ;
2012-08-21 16:38:57 +02:00
}
if ( params . size ( ) > 1 )
{
target_confirms = params [ 1 ] . get_int ( ) ;
if ( target_confirms < 1 )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Invalid parameter " ) ;
2012-08-21 16:38:57 +02:00
}
2014-04-29 19:39:01 +02:00
if ( params . size ( ) > 2 )
if ( params [ 2 ] . get_bool ( ) )
2014-07-01 11:00:22 +02:00
filter = filter | ISMINE_WATCH_ONLY ;
2014-04-29 19:39:01 +02:00
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
for ( map < uint256 , CWalletTx > : : iterator it = pwalletMain - > mapWallet . begin ( ) ; it ! = pwalletMain - > mapWallet . end ( ) ; it + + )
{
CWalletTx tx = ( * it ) . second ;
if ( depth = = - 1 | | tx . GetDepthInMainChain ( ) < depth )
2014-04-08 17:51:04 +02:00
ListTransactions ( tx , " * " , 0 , true , transactions , filter ) ;
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 ) ) ;
ret . push_back ( Pair ( " lastblock " , lastblock . GetHex ( ) ) ) ;
return ret ;
}
2015-05-18 14:02:18 +02:00
UniValue gettransaction ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2014-05-23 00:58:15 +02:00
if ( fHelp | | params . size ( ) < 1 | | params . size ( ) > 2 )
2012-08-21 16:38:57 +02:00
throw runtime_error (
2014-09-07 14:37:13 +02:00
" gettransaction \" txid \" ( includeWatchonly ) \n "
2013-10-29 12:29:44 +01:00
" \n Get detailed information about in-wallet transaction <txid> \n "
" \n Arguments: \n "
" 1. \" txid \" (string, required) The transaction id \n "
2014-05-23 00:58:15 +02:00
" 2. \" includeWatchonly \" (bool, optional, default=false) Whether to include watchonly 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 "
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 "
2015-12-16 20:57:54 +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 "
2013-10-29 12:29:44 +01:00
" \" details \" : [ \n "
" { \n "
2014-12-30 15:32:07 +01:00
" \" account \" : \" accountname \" , (string) DEPRECATED. The account name involved in the transaction, can be \" \" for the default account. \n "
2013-10-29 12:29:44 +01:00
" \" address \" : \" bitcoinaddress \" , (string) The bitcoin address involved in the transaction \n "
" \" 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 "
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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
uint256 hash ;
hash . SetHex ( params [ 0 ] . get_str ( ) ) ;
2014-07-01 11:00:22 +02:00
isminefilter filter = ISMINE_SPENDABLE ;
2014-05-23 00:58:15 +02:00
if ( params . size ( ) > 1 )
if ( 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 ) ;
2012-08-21 16:38:57 +02:00
if ( ! pwalletMain - > mapWallet . count ( hash ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Invalid or non-wallet transaction id " ) ;
2012-08-21 16:38:57 +02:00
const CWalletTx & wtx = pwalletMain - > mapWallet [ hash ] ;
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 ;
CAmount nFee = ( wtx . IsFromMe ( filter ) ? wtx . 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 ) ;
2014-05-23 00:58:15 +02:00
ListTransactions ( wtx , " * " , 0 , false , details , filter ) ;
2012-08-21 16:38:57 +02:00
entry . push_back ( Pair ( " details " , details ) ) ;
2014-06-24 05:10:24 +02:00
string strHex = EncodeHexTx ( static_cast < CTransaction > ( wtx ) ) ;
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-01-07 22:31:27 +01:00
UniValue abandontransaction ( const UniValue & params , bool fHelp )
{
if ( ! EnsureWalletIsAvailable ( fHelp ) )
return NullUniValue ;
if ( fHelp | | params . size ( ) ! = 1 )
throw runtime_error (
" 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 \" " )
) ;
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
uint256 hash ;
hash . SetHex ( params [ 0 ] . get_str ( ) ) ;
if ( ! pwalletMain - > mapWallet . count ( hash ) )
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Invalid or non-wallet transaction id " ) ;
if ( ! pwalletMain - > AbandonTransaction ( hash ) )
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , " Transaction not eligible for abandonment " ) ;
return NullUniValue ;
}
2012-08-21 16:38:57 +02:00
2015-05-18 14:02:18 +02:00
UniValue backupwallet ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( fHelp | | params . size ( ) ! = 1 )
throw 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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
string strDest = params [ 0 ] . get_str ( ) ;
2016-05-17 02:31:16 +02:00
if ( ! pwalletMain - > BackupWallet ( strDest ) )
2012-11-27 16:27:54 +01:00
throw JSONRPCError ( RPC_WALLET_ERROR , " Error: Wallet backup failed! " ) ;
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
}
2015-05-18 14:02:18 +02:00
UniValue keypoolrefill ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2013-06-25 22:21:42 +02:00
if ( fHelp | | params . size ( ) > 1 )
2012-08-21 16:38:57 +02:00
throw runtime_error (
2013-10-29 12:29:44 +01:00
" keypoolrefill ( newsize ) \n "
" \n Fills the keypool. "
+ HelpRequiringPassphrase ( ) + " \n "
" \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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
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 ;
2013-06-25 22:21:42 +02:00
if ( params . size ( ) > 0 ) {
if ( params [ 0 ] . get_int ( ) < 0 )
2013-10-28 11:58:39 +01:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " Invalid parameter, expected valid size. " ) ;
kpSize = ( unsigned int ) params [ 0 ] . get_int ( ) ;
2013-06-25 22:21:42 +02:00
}
2012-08-21 16:38:57 +02:00
EnsureWalletIsUnlocked ( ) ;
2013-06-25 22:21:42 +02:00
pwalletMain - > TopUpKeyPool ( kpSize ) ;
2012-08-21 16:38:57 +02:00
2013-06-25 22:21:42 +02:00
if ( pwalletMain - > GetKeyPoolSize ( ) < kpSize )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_ERROR , " Error refreshing keypool. " ) ;
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
{
2013-05-07 16:47:00 +02:00
LOCK ( cs_nWalletUnlockTime ) ;
nWalletUnlockTime = 0 ;
pWallet - > Lock ( ) ;
2012-08-21 16:38:57 +02:00
}
2015-05-18 14:02:18 +02:00
UniValue walletpassphrase ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( pwalletMain - > IsCrypted ( ) & & ( fHelp | | params . size ( ) ! = 2 ) )
throw 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 "
" \n unlock the wallet for 60 seconds \n "
+ 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 " )
) ;
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
if ( fHelp )
return true ;
if ( ! pwalletMain - > 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. " ) ;
2012-08-21 16:38:57 +02:00
// Note that the walletpassphrase is stored in params[0] which is not mlock()ed
SecureString strWalletPass ;
strWalletPass . reserve ( 100 ) ;
// TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
// Alternately, find a way to make params[0] mlock()'d to begin with.
strWalletPass = params [ 0 ] . get_str ( ) . c_str ( ) ;
if ( strWalletPass . length ( ) > 0 )
{
if ( ! pwalletMain - > Unlock ( strWalletPass ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_PASSPHRASE_INCORRECT , " Error: The wallet passphrase entered was incorrect. " ) ;
2012-08-21 16:38:57 +02:00
}
else
throw runtime_error (
" walletpassphrase <passphrase> <timeout> \n "
" Stores the wallet decryption key in memory for <timeout> seconds. " ) ;
2013-05-07 16:47:00 +02:00
pwalletMain - > TopUpKeyPool ( ) ;
2013-04-13 07:13:08 +02:00
int64_t nSleepTime = params [ 1 ] . get_int64 ( ) ;
2013-05-07 16:47:00 +02:00
LOCK ( cs_nWalletUnlockTime ) ;
nWalletUnlockTime = GetTime ( ) + nSleepTime ;
RPCRunLater ( " lockwallet " , boost : : bind ( LockWallet , pwalletMain ) , 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
}
2015-05-18 14:02:18 +02:00
UniValue walletpassphrasechange ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( pwalletMain - > IsCrypted ( ) & & ( fHelp | | params . size ( ) ! = 2 ) )
throw 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 \" " )
) ;
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
if ( fHelp )
return true ;
if ( ! pwalletMain - > 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. " ) ;
2012-08-21 16:38:57 +02:00
// TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string)
// Alternately, find a way to make params[0] mlock()'d to begin with.
SecureString strOldWalletPass ;
strOldWalletPass . reserve ( 100 ) ;
strOldWalletPass = params [ 0 ] . get_str ( ) . c_str ( ) ;
SecureString strNewWalletPass ;
strNewWalletPass . reserve ( 100 ) ;
strNewWalletPass = params [ 1 ] . get_str ( ) . c_str ( ) ;
if ( strOldWalletPass . length ( ) < 1 | | strNewWalletPass . length ( ) < 1 )
throw runtime_error (
" walletpassphrasechange <oldpassphrase> <newpassphrase> \n "
" Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>. " ) ;
if ( ! pwalletMain - > ChangeWalletPassphrase ( strOldWalletPass , strNewWalletPass ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_PASSPHRASE_INCORRECT , " Error: The wallet passphrase entered was incorrect. " ) ;
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
}
2015-05-18 14:02:18 +02:00
UniValue walletlock ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( pwalletMain - > IsCrypted ( ) & & ( fHelp | | params . size ( ) ! = 0 ) )
throw runtime_error (
" 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 " , " " )
) ;
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
if ( fHelp )
return true ;
if ( ! pwalletMain - > 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
{
LOCK ( cs_nWalletUnlockTime ) ;
pwalletMain - > Lock ( ) ;
nWalletUnlockTime = 0 ;
}
2014-08-20 21:15:16 +02:00
return NullUniValue ;
2012-08-21 16:38:57 +02:00
}
2015-05-18 14:02:18 +02:00
UniValue encryptwallet ( const UniValue & params , bool fHelp )
2012-08-21 16:38:57 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-08-21 16:38:57 +02:00
if ( ! pwalletMain - > IsCrypted ( ) & & ( fHelp | | params . size ( ) ! = 1 ) )
throw 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 "
" \n Encrypt you wallet \n "
+ 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 \" " ) +
" \n Now we can so something like sign \n "
+ HelpExampleCli ( " signmessage " , " \" bitcoinaddress \" \" test message \" " ) +
" \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 \" " )
) ;
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-08-21 16:38:57 +02:00
if ( fHelp )
return true ;
if ( pwalletMain - > 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. " ) ;
2012-08-21 16:38:57 +02:00
// TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
// Alternately, find a way to make params[0] mlock()'d to begin with.
SecureString strWalletPass ;
strWalletPass . reserve ( 100 ) ;
strWalletPass = params [ 0 ] . get_str ( ) . c_str ( ) ;
if ( strWalletPass . length ( ) < 1 )
throw runtime_error (
" encryptwallet <passphrase> \n "
" Encrypts the wallet with <passphrase>. " ) ;
if ( ! pwalletMain - > EncryptWallet ( strWalletPass ) )
2012-10-04 09:34:44 +02:00
throw JSONRPCError ( RPC_WALLET_ENCRYPTION_FAILED , " Error: Failed to encrypt the wallet. " ) ;
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
}
2015-05-18 14:02:18 +02:00
UniValue lockunspent ( const UniValue & params , bool fHelp )
2012-09-27 19:52:09 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-09-27 19:52:09 +02:00
if ( fHelp | | params . size ( ) < 1 | | params . size ( ) > 2 )
throw 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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-09-27 19:52:09 +02:00
if ( params . size ( ) = = 1 )
2014-08-20 21:15:16 +02:00
RPCTypeCheck ( params , boost : : assign : : list_of ( UniValue : : VBOOL ) ) ;
2012-09-27 19:52:09 +02:00
else
2014-08-20 21:15:16 +02:00
RPCTypeCheck ( params , boost : : assign : : list_of ( UniValue : : VBOOL ) ( UniValue : : VARR ) ) ;
2012-09-27 19:52:09 +02:00
bool fUnlock = params [ 0 ] . get_bool ( ) ;
if ( params . size ( ) = = 1 ) {
if ( fUnlock )
pwalletMain - > UnlockAllCoins ( ) ;
return true ;
}
2015-05-13 21:29:19 +02:00
UniValue outputs = 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
string txid = find_value ( o , " txid " ) . get_str ( ) ;
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 )
pwalletMain - > UnlockCoin ( outpt ) ;
else
pwalletMain - > LockCoin ( outpt ) ;
}
return true ;
}
2015-05-18 14:02:18 +02:00
UniValue listlockunspent ( const UniValue & params , bool fHelp )
2012-09-27 19:52:09 +02:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2012-09-27 19:52:09 +02:00
if ( fHelp | | params . size ( ) > 0 )
throw runtime_error (
" 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
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2012-09-27 19:52:09 +02:00
vector < COutPoint > vOutpts ;
pwalletMain - > ListLockedCoins ( vOutpts ) ;
2015-05-10 14:48:35 +02:00
UniValue ret ( UniValue : : VARR ) ;
2012-09-27 19:52:09 +02:00
BOOST_FOREACH ( 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 ;
}
2015-05-18 14:02:18 +02:00
UniValue settxfee ( const UniValue & params , bool fHelp )
2013-12-13 16:06:32 +01:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2013-12-13 16:06:32 +01:00
if ( fHelp | | params . size ( ) < 1 | | params . size ( ) > 1 )
throw runtime_error (
" 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 " )
) ;
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2013-12-13 16:06:32 +01:00
// Amount
2015-06-06 09:41:12 +02:00
CAmount nAmount = AmountFromValue ( 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 ;
}
2015-05-18 14:02:18 +02:00
UniValue getwalletinfo ( const UniValue & params , bool fHelp )
2014-02-21 05:56:04 +01:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2014-02-21 05:56:04 +01:00
if ( fHelp | | params . size ( ) ! = 0 )
throw runtime_error (
" getwalletinfo \n "
" Returns an object containing various wallet state info. \n "
" \n Result: \n "
" { \n "
2016-07-21 21:52:30 +02: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 GMT epoch) of the oldest pre-generated key in the key pool \n "
" \" keypoolsize \" : xxxx, (numeric) how many new keys are pre-generated \n "
" \" unlocked_until \" : ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked \n "
" \" 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 " , " " )
) ;
2014-10-19 10:46:17 +02:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2015-05-10 14:48:35 +02:00
UniValue obj ( UniValue : : VOBJ ) ;
2014-02-21 05:56:04 +01:00
obj . push_back ( Pair ( " walletversion " , pwalletMain - > GetVersion ( ) ) ) ;
obj . push_back ( Pair ( " balance " , ValueFromAmount ( pwalletMain - > GetBalance ( ) ) ) ) ;
2014-12-25 06:10:59 +01:00
obj . push_back ( Pair ( " unconfirmed_balance " , ValueFromAmount ( pwalletMain - > GetUnconfirmedBalance ( ) ) ) ) ;
obj . push_back ( Pair ( " immature_balance " , ValueFromAmount ( pwalletMain - > GetImmatureBalance ( ) ) ) ) ;
2014-02-21 05:56:04 +01:00
obj . push_back ( Pair ( " txcount " , ( int ) pwalletMain - > mapWallet . size ( ) ) ) ;
2014-05-06 14:58:43 +02:00
obj . push_back ( Pair ( " keypoololdest " , pwalletMain - > GetOldestKeyPoolTime ( ) ) ) ;
2014-02-21 05:56:04 +01:00
obj . push_back ( Pair ( " keypoolsize " , ( int ) pwalletMain - > GetKeyPoolSize ( ) ) ) ;
if ( pwalletMain - > IsCrypted ( ) )
2014-05-06 14:58:43 +02:00
obj . push_back ( Pair ( " unlocked_until " , nWalletUnlockTime ) ) ;
2015-06-11 22:12:34 +02:00
obj . push_back ( Pair ( " paytxfee " , ValueFromAmount ( payTxFee . GetFeePerK ( ) ) ) ) ;
2016-07-09 11:25:02 +02:00
CKeyID masterKeyID = pwalletMain - > GetHDChain ( ) . masterKeyID ;
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
2015-05-18 14:02:18 +02:00
UniValue resendwallettransactions ( const UniValue & params , bool fHelp )
2015-03-23 18:47:18 +01:00
{
2015-04-12 17:56:44 +02:00
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2015-03-23 18:47:18 +01:00
if ( fHelp | | params . size ( ) ! = 0 )
throw runtime_error (
" 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 "
" 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 " ) ;
2015-03-23 18:47:18 +01:00
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2016-05-25 02:56:17 +02:00
std : : vector < uint256 > txids = pwalletMain - > ResendWalletTransactionsBefore ( GetTime ( ) , g_connman . get ( ) ) ;
2015-05-10 14:48:35 +02:00
UniValue result ( UniValue : : VARR ) ;
2015-03-23 18:47:18 +01:00
BOOST_FOREACH ( const uint256 & txid , txids )
{
result . push_back ( txid . ToString ( ) ) ;
}
return result ;
}
2015-04-12 17:56:32 +02:00
2015-05-18 14:02:18 +02:00
UniValue listunspent ( const UniValue & params , bool fHelp )
2015-04-12 17:56:32 +02:00
{
if ( ! EnsureWalletIsAvailable ( fHelp ) )
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2016-01-15 01:55:17 +01:00
2015-04-12 17:56:32 +02:00
if ( fHelp | | params . size ( ) > 3 )
2015-04-13 15:04:08 +02:00
throw runtime_error (
" listunspent ( minconf maxconf [ \" address \" ,...] ) \n "
" \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 "
" 3. \" addresses \" (string) A json array of bitcoin addresses to filter \n "
" [ \n "
" \" address \" (string) bitcoin address \n "
" ,... \n "
" ] \n "
" \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 "
2015-08-01 21:15:23 +02:00
" \" amount \" : x.xxx, (numeric) the transaction 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 "
" \" solvable \" : xxx (bool) Whether we know how to spend this output, ignoring the lack of keys \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 \\ \" ] \" " )
) ;
2015-05-10 13:35:44 +02:00
RPCTypeCheck ( params , boost : : assign : : list_of ( UniValue : : VNUM ) ( UniValue : : VNUM ) ( UniValue : : VARR ) ) ;
2015-04-13 15:04:08 +02:00
2015-04-12 17:56:32 +02:00
int nMinDepth = 1 ;
if ( params . size ( ) > 0 )
2015-04-13 15:04:08 +02:00
nMinDepth = params [ 0 ] . get_int ( ) ;
2015-04-12 17:56:32 +02:00
int nMaxDepth = 9999999 ;
if ( params . size ( ) > 1 )
2015-04-13 15:04:08 +02:00
nMaxDepth = params [ 1 ] . get_int ( ) ;
2015-04-12 17:56:32 +02:00
set < CBitcoinAddress > setAddress ;
if ( params . size ( ) > 2 ) {
2015-05-13 21:29:19 +02:00
UniValue inputs = 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 ( ) )
2015-04-13 15:04:08 +02:00
throw JSONRPCError ( RPC_INVALID_ADDRESS_OR_KEY , string ( " Invalid Bitcoin address: " ) + input . get_str ( ) ) ;
2015-04-12 17:56:32 +02:00
if ( setAddress . count ( address ) )
2015-04-13 15:04:08 +02:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , string ( " Invalid parameter, duplicated address: " ) + input . get_str ( ) ) ;
setAddress . insert ( address ) ;
2015-04-12 17:56:32 +02:00
}
}
2015-04-13 15:04:08 +02:00
2015-05-10 14:48:35 +02:00
UniValue results ( UniValue : : VARR ) ;
2015-04-12 17:56:32 +02:00
vector < COutput > vecOutputs ;
assert ( pwalletMain ! = NULL ) ;
LOCK2 ( cs_main , pwalletMain - > cs_wallet ) ;
2015-04-20 19:13:18 +02:00
pwalletMain - > AvailableCoins ( vecOutputs , false , NULL , true ) ;
2015-04-12 17:56:32 +02:00
BOOST_FOREACH ( const COutput & out , vecOutputs ) {
if ( out . nDepth < nMinDepth | | out . nDepth > nMaxDepth )
2015-04-13 15:04:08 +02:00
continue ;
2016-03-08 11:37:18 +01:00
CTxDestination address ;
const CScript & scriptPubKey = out . tx - > vout [ out . i ] . scriptPubKey ;
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
2015-04-12 17:56:32 +02:00
if ( pwalletMain - > mapAddressBook . count ( address ) )
2015-04-13 15:04:08 +02:00
entry . push_back ( Pair ( " account " , pwalletMain - > mapAddressBook [ address ] . name ) ) ;
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 ;
if ( pwalletMain - > GetCScript ( hash , redeemScript ) )
2015-04-13 15:04:08 +02:00
entry . push_back ( Pair ( " redeemScript " , HexStr ( redeemScript . begin ( ) , redeemScript . end ( ) ) ) ) ;
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 ( ) ) ) ) ;
entry . push_back ( Pair ( " amount " , ValueFromAmount ( out . tx - > vout [ out . i ] . nValue ) ) ) ;
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 ) ) ;
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
UniValue fundrawtransaction ( const UniValue & params , bool fHelp )
{
if ( ! EnsureWalletIsAvailable ( fHelp ) )
return NullUniValue ;
2015-04-24 06:42:49 +02:00
if ( fHelp | | params . size ( ) < 1 | | params . size ( ) > 2 )
2015-04-25 03:27:30 +02:00
throw 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 "
" This will not modify existing inputs, and will add one change output to the outputs. \n "
" 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 "
" 2. options (object, optional) \n "
" { \n "
" \" 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 "
2016-04-06 16:56:14 +02:00
" \" lockUnspents \" (boolean, optional, default false) Lock selected unspent outputs \n "
2016-06-06 17:50:50 +02:00
" \" feeRate \" (numeric, optional, default not set: makes wallet determine the fee) Set a specific feerate ( " + CURRENCY_UNIT + " per KB) \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 "
" \" hex \" \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 \" " )
) ;
2016-03-30 03:04:22 +02:00
RPCTypeCheck ( params , boost : : assign : : list_of ( UniValue : : VSTR ) ) ;
CTxDestination changeAddress = CNoDestination ( ) ;
int changePosition = - 1 ;
bool includeWatching = false ;
2016-04-06 16:56:14 +02:00
bool lockUnspents = false ;
2016-04-28 22:04:07 +02:00
CFeeRate feeRate = CFeeRate ( 0 ) ;
2016-05-06 11:01:50 +02:00
bool overrideEstimatedFeerate = false ;
2016-03-30 03:04:22 +02:00
if ( params . size ( ) > 1 ) {
if ( params [ 1 ] . type ( ) = = UniValue : : VBOOL ) {
// backward compatibility bool only fallback
includeWatching = params [ 1 ] . get_bool ( ) ;
}
else {
RPCTypeCheck ( params , boost : : assign : : list_of ( UniValue : : VSTR ) ( UniValue : : VOBJ ) ) ;
UniValue options = params [ 1 ] ;
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 ) } ,
{ " feeRate " , UniValueType ( ) } , // will be checked below
} ,
true , true ) ;
2016-03-30 03:04:22 +02:00
if ( options . exists ( " changeAddress " ) ) {
CBitcoinAddress address ( options [ " changeAddress " ] . get_str ( ) ) ;
if ( ! address . IsValid ( ) )
throw JSONRPCError ( RPC_INVALID_PARAMETER , " changeAddress must be a valid bitcoin address " ) ;
changeAddress = address . Get ( ) ;
}
if ( options . exists ( " changePosition " ) )
changePosition = options [ " changePosition " ] . get_int ( ) ;
if ( options . exists ( " includeWatching " ) )
includeWatching = 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
{
2016-06-06 17:50:50 +02:00
feeRate = CFeeRate ( AmountFromValue ( options [ " feeRate " ] ) ) ;
2016-05-06 11:01:50 +02:00
overrideEstimatedFeerate = true ;
}
2016-03-30 03:04:22 +02:00
}
}
2015-04-25 03:27:30 +02:00
// parse hex string from parameter
CTransaction origTx ;
2015-11-06 01:32:04 +01:00
if ( ! DecodeHexTx ( origTx , params [ 0 ] . get_str ( ) , true ) )
2015-04-25 03:27:30 +02:00
throw JSONRPCError ( RPC_DESERIALIZATION_ERROR , " TX decode failed " ) ;
2015-11-13 21:52:07 +01:00
if ( origTx . vout . size ( ) = = 0 )
throw JSONRPCError ( RPC_INVALID_PARAMETER , " TX must have at least one output " ) ;
2016-06-08 15:34:18 +02:00
if ( changePosition ! = - 1 & & ( changePosition < 0 | | ( unsigned int ) changePosition > origTx . 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
2015-04-25 03:27:30 +02:00
CMutableTransaction tx ( origTx ) ;
2016-04-28 22:04:07 +02:00
CAmount nFeeOut ;
2015-04-25 03:27:30 +02:00
string strFailReason ;
2016-03-30 03:04:22 +02:00
2016-05-06 11:01:50 +02:00
if ( ! pwalletMain - > FundTransaction ( tx , nFeeOut , overrideEstimatedFeerate , feeRate , changePosition , strFailReason , includeWatching , lockUnspents , changeAddress ) )
2015-04-25 03:27:30 +02:00
throw JSONRPCError ( RPC_INTERNAL_ERROR , strFailReason ) ;
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
extern UniValue dumpprivkey ( const UniValue & params , bool fHelp ) ; // in rpcdump.cpp
extern UniValue importprivkey ( const UniValue & params , bool fHelp ) ;
extern UniValue importaddress ( const UniValue & params , bool fHelp ) ;
extern UniValue importpubkey ( const UniValue & params , bool fHelp ) ;
extern UniValue dumpwallet ( const UniValue & params , bool fHelp ) ;
extern UniValue importwallet ( const UniValue & params , bool fHelp ) ;
2016-02-19 01:31:12 +01:00
extern UniValue importprunedfunds ( const UniValue & params , bool fHelp ) ;
2016-03-07 14:51:06 +01:00
extern UniValue removeprunedfunds ( const UniValue & params , bool fHelp ) ;
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
// --------------------- ------------------------ ----------------------- ----------
{ " rawtransactions " , " fundrawtransaction " , & fundrawtransaction , false } ,
{ " hidden " , " resendwallettransactions " , & resendwallettransactions , true } ,
{ " wallet " , " abandontransaction " , & abandontransaction , false } ,
{ " wallet " , " addmultisigaddress " , & addmultisigaddress , true } ,
2015-12-30 01:13:08 +01:00
{ " wallet " , " addwitnessaddress " , & addwitnessaddress , true } ,
2016-01-07 08:33:49 +01:00
{ " wallet " , " backupwallet " , & backupwallet , true } ,
{ " wallet " , " dumpprivkey " , & dumpprivkey , true } ,
{ " wallet " , " dumpwallet " , & dumpwallet , true } ,
{ " wallet " , " encryptwallet " , & encryptwallet , true } ,
{ " wallet " , " getaccountaddress " , & getaccountaddress , true } ,
{ " wallet " , " getaccount " , & getaccount , true } ,
{ " wallet " , " getaddressesbyaccount " , & getaddressesbyaccount , true } ,
{ " wallet " , " getbalance " , & getbalance , false } ,
{ " wallet " , " getnewaddress " , & getnewaddress , true } ,
{ " wallet " , " getrawchangeaddress " , & getrawchangeaddress , true } ,
{ " wallet " , " getreceivedbyaccount " , & getreceivedbyaccount , false } ,
{ " wallet " , " getreceivedbyaddress " , & getreceivedbyaddress , false } ,
{ " wallet " , " gettransaction " , & gettransaction , false } ,
{ " wallet " , " getunconfirmedbalance " , & getunconfirmedbalance , false } ,
{ " wallet " , " getwalletinfo " , & getwalletinfo , false } ,
{ " wallet " , " importprivkey " , & importprivkey , true } ,
{ " wallet " , " importwallet " , & importwallet , true } ,
{ " wallet " , " importaddress " , & importaddress , true } ,
2016-02-19 01:31:12 +01:00
{ " wallet " , " importprunedfunds " , & importprunedfunds , true } ,
2016-01-07 08:33:49 +01:00
{ " wallet " , " importpubkey " , & importpubkey , true } ,
{ " wallet " , " keypoolrefill " , & keypoolrefill , true } ,
{ " wallet " , " listaccounts " , & listaccounts , false } ,
{ " wallet " , " listaddressgroupings " , & listaddressgroupings , false } ,
{ " wallet " , " listlockunspent " , & listlockunspent , false } ,
{ " wallet " , " listreceivedbyaccount " , & listreceivedbyaccount , false } ,
{ " wallet " , " listreceivedbyaddress " , & listreceivedbyaddress , false } ,
{ " wallet " , " listsinceblock " , & listsinceblock , false } ,
{ " wallet " , " listtransactions " , & listtransactions , false } ,
{ " wallet " , " listunspent " , & listunspent , false } ,
{ " wallet " , " lockunspent " , & lockunspent , true } ,
{ " wallet " , " move " , & movecmd , false } ,
{ " wallet " , " sendfrom " , & sendfrom , false } ,
{ " wallet " , " sendmany " , & sendmany , false } ,
{ " wallet " , " sendtoaddress " , & sendtoaddress , false } ,
{ " wallet " , " setaccount " , & setaccount , true } ,
{ " wallet " , " settxfee " , & settxfee , true } ,
{ " wallet " , " signmessage " , & signmessage , true } ,
{ " wallet " , " walletlock " , & walletlock , true } ,
{ " wallet " , " walletpassphrasechange " , & walletpassphrasechange , true } ,
{ " wallet " , " walletpassphrase " , & walletpassphrase , true } ,
2016-03-07 14:51:06 +01:00
{ " wallet " , " removeprunedfunds " , & removeprunedfunds , true } ,
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
{
2016-09-19 16:09:38 +02:00
if ( GetBoolArg ( " -disablewallet " , false ) )
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
}