@ -346,21 +346,17 @@ Value getnewaddress(const Array& params, bool fHelp)
@@ -346,21 +346,17 @@ Value getnewaddress(const Array& params, bool fHelp)
CBitcoinAddress address ( pwalletMain - > GetOrReuseKeyFromPool ( ) ) ;
// This could be done in the same main CS as GetKeyFromKeyPool.
CRITICAL_BLOCK ( pwalletMain - > cs_mapAddressBook )
pwalletMain - > SetAddressBookName ( address , strAccount ) ;
return address . ToString ( ) ;
}
// requires cs_main, cs_mapWallet, cs_mapAddressBook locks
CBitcoinAddress GetAccountAddress ( string strAccount , bool bForceNew = false )
{
CWalletDB walletdb ( pwalletMain - > strWalletFile ) ;
CAccount account ;
CRITICAL_BLOCK ( pwalletMain - > cs_mapAddressBook )
{
walletdb . ReadAccount ( strAccount , account ) ;
bool bKeyUsed = false ;
@ -396,7 +392,6 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
@@ -396,7 +392,6 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
walletdb . WriteAccount ( strAccount , account ) ;
}
}
}
return CBitcoinAddress ( account . vchPubKey ) ;
}
@ -413,12 +408,7 @@ Value getaccountaddress(const Array& params, bool fHelp)
@@ -413,12 +408,7 @@ Value getaccountaddress(const Array& params, bool fHelp)
Value ret ;
CRITICAL_BLOCK ( cs_main )
CRITICAL_BLOCK ( pwalletMain - > cs_mapWallet )
CRITICAL_BLOCK ( pwalletMain - > cs_mapAddressBook )
{
ret = GetAccountAddress ( strAccount ) . ToString ( ) ;
}
return ret ;
}
@ -442,10 +432,6 @@ Value setaccount(const Array& params, bool fHelp)
@@ -442,10 +432,6 @@ Value setaccount(const Array& params, bool fHelp)
strAccount = AccountFromValue ( params [ 1 ] ) ;
// Detect when changing the account of an address that is the 'unused current key' of another account:
CRITICAL_BLOCK ( cs_main )
CRITICAL_BLOCK ( pwalletMain - > cs_mapWallet )
CRITICAL_BLOCK ( pwalletMain - > cs_mapAddressBook )
{
if ( pwalletMain - > mapAddressBook . count ( address ) )
{
string strOldAccount = pwalletMain - > mapAddressBook [ address ] ;
@ -454,7 +440,6 @@ Value setaccount(const Array& params, bool fHelp)
@@ -454,7 +440,6 @@ Value setaccount(const Array& params, bool fHelp)
}
pwalletMain - > SetAddressBookName ( address , strAccount ) ;
}
return Value : : null ;
}
@ -472,12 +457,9 @@ Value getaccount(const Array& params, bool fHelp)
@@ -472,12 +457,9 @@ Value getaccount(const Array& params, bool fHelp)
throw JSONRPCError ( - 5 , " Invalid bitcoin address " ) ;
string strAccount ;
CRITICAL_BLOCK ( pwalletMain - > cs_mapAddressBook )
{
map < CBitcoinAddress , string > : : iterator mi = pwalletMain - > mapAddressBook . find ( address ) ;
if ( mi ! = pwalletMain - > mapAddressBook . end ( ) & & ! ( * mi ) . second . empty ( ) )
strAccount = ( * mi ) . second ;
}
return strAccount ;
}
@ -493,8 +475,6 @@ Value getaddressesbyaccount(const Array& params, bool fHelp)
@@ -493,8 +475,6 @@ Value getaddressesbyaccount(const Array& params, bool fHelp)
// Find all addresses that have the given account
Array ret ;
CRITICAL_BLOCK ( pwalletMain - > cs_mapAddressBook )
{
BOOST_FOREACH ( const PAIRTYPE ( CBitcoinAddress , string ) & item , pwalletMain - > mapAddressBook )
{
const CBitcoinAddress & address = item . first ;
@ -502,7 +482,6 @@ Value getaddressesbyaccount(const Array& params, bool fHelp)
@@ -502,7 +482,6 @@ Value getaddressesbyaccount(const Array& params, bool fHelp)
if ( strName = = strAccount )
ret . push_back ( address . ToString ( ) ) ;
}
}
return ret ;
}
@ -548,16 +527,12 @@ Value sendtoaddress(const Array& params, bool fHelp)
@@ -548,16 +527,12 @@ Value sendtoaddress(const Array& params, bool fHelp)
if ( params . size ( ) > 3 & & params [ 3 ] . type ( ) ! = null_type & & ! params [ 3 ] . get_str ( ) . empty ( ) )
wtx . mapValue [ " to " ] = params [ 3 ] . get_str ( ) ;
CRITICAL_BLOCK ( cs_main )
CRITICAL_BLOCK ( pwalletMain - > cs_vMasterKey )
{
if ( pwalletMain - > IsLocked ( ) )
if ( pwalletMain - > IsLocked ( ) )
throw JSONRPCError ( - 13 , " Error: Please enter the wallet passphrase with walletpassphrase first. " ) ;
string strError = pwalletMain - > SendMoneyToBitcoinAddress ( address , nAmount , wtx ) ;
if ( strError ! = " " )
throw JSONRPCError ( - 4 , strError ) ;
}
return wtx . GetHash ( ) . GetHex ( ) ;
}
@ -586,8 +561,6 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
@@ -586,8 +561,6 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
// Tally
int64 nAmount = 0 ;
CRITICAL_BLOCK ( pwalletMain - > cs_mapWallet )
{
for ( map < uint256 , CWalletTx > : : iterator it = pwalletMain - > mapWallet . begin ( ) ; it ! = pwalletMain - > mapWallet . end ( ) ; + + it )
{
const CWalletTx & wtx = ( * it ) . second ;
@ -599,7 +572,6 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
@@ -599,7 +572,6 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
if ( wtx . GetDepthInMainChain ( ) > = nMinDepth )
nAmount + = txout . nValue ;
}
}
return ValueFromAmount ( nAmount ) ;
}
@ -607,8 +579,6 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
@@ -607,8 +579,6 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
void GetAccountAddresses ( string strAccount , set < CBitcoinAddress > & setAddress )
{
CRITICAL_BLOCK ( pwalletMain - > cs_mapAddressBook )
{
BOOST_FOREACH ( const PAIRTYPE ( CBitcoinAddress , string ) & item , pwalletMain - > mapAddressBook )
{
const CBitcoinAddress & address = item . first ;
@ -616,7 +586,6 @@ void GetAccountAddresses(string strAccount, set<CBitcoinAddress>& setAddress)
@@ -616,7 +586,6 @@ void GetAccountAddresses(string strAccount, set<CBitcoinAddress>& setAddress)
if ( strName = = strAccount )
setAddress . insert ( address ) ;
}
}
}
@ -639,8 +608,6 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
@@ -639,8 +608,6 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
// Tally
int64 nAmount = 0 ;
CRITICAL_BLOCK ( pwalletMain - > cs_mapWallet )
{
for ( map < uint256 , CWalletTx > : : iterator it = pwalletMain - > mapWallet . begin ( ) ; it ! = pwalletMain - > mapWallet . end ( ) ; + + it )
{
const CWalletTx & wtx = ( * it ) . second ;
@ -655,7 +622,6 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
@@ -655,7 +622,6 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
nAmount + = txout . nValue ;
}
}
}
return ( double ) nAmount / ( double ) COIN ;
}
@ -664,8 +630,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
@@ -664,8 +630,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
int64 GetAccountBalance ( CWalletDB & walletdb , const string & strAccount , int nMinDepth )
{
int64 nBalance = 0 ;
CRITICAL_BLOCK ( pwalletMain - > cs_mapWallet )
{
// Tally wallet transactions
for ( map < uint256 , CWalletTx > : : iterator it = pwalletMain - > mapWallet . begin ( ) ; it ! = pwalletMain - > mapWallet . end ( ) ; + + it )
{
@ -683,7 +648,6 @@ int64 GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinD
@@ -683,7 +648,6 @@ int64 GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinD
// Tally internal accounting entries
nBalance + = walletdb . GetAccountCreditDebit ( strAccount ) ;
}
return nBalance ;
}
@ -763,8 +727,6 @@ Value movecmd(const Array& params, bool fHelp)
@@ -763,8 +727,6 @@ Value movecmd(const Array& params, bool fHelp)
if ( params . size ( ) > 4 )
strComment = params [ 4 ] . get_str ( ) ;
CRITICAL_BLOCK ( pwalletMain - > cs_mapWallet )
{
CWalletDB walletdb ( pwalletMain - > strWalletFile ) ;
walletdb . TxnBegin ( ) ;
@ -789,7 +751,7 @@ Value movecmd(const Array& params, bool fHelp)
@@ -789,7 +751,7 @@ Value movecmd(const Array& params, bool fHelp)
walletdb . WriteAccountingEntry ( credit ) ;
walletdb . TxnCommit ( ) ;
}
return true ;
}
@ -822,11 +784,7 @@ Value sendfrom(const Array& params, bool fHelp)
@@ -822,11 +784,7 @@ Value sendfrom(const Array& params, bool fHelp)
if ( params . size ( ) > 5 & & params [ 5 ] . type ( ) ! = null_type & & ! params [ 5 ] . get_str ( ) . empty ( ) )
wtx . mapValue [ " to " ] = params [ 5 ] . get_str ( ) ;
CRITICAL_BLOCK ( cs_main )
CRITICAL_BLOCK ( pwalletMain - > cs_mapWallet )
CRITICAL_BLOCK ( pwalletMain - > cs_vMasterKey )
{
if ( pwalletMain - > IsLocked ( ) )
if ( pwalletMain - > IsLocked ( ) )
throw JSONRPCError ( - 13 , " Error: Please enter the wallet passphrase with walletpassphrase first. " ) ;
// Check funds
@ -838,7 +796,6 @@ Value sendfrom(const Array& params, bool fHelp)
@@ -838,7 +796,6 @@ Value sendfrom(const Array& params, bool fHelp)
string strError = pwalletMain - > SendMoneyToBitcoinAddress ( address , nAmount , wtx ) ;
if ( strError ! = " " )
throw JSONRPCError ( - 4 , strError ) ;
}
return wtx . GetHash ( ) . GetHex ( ) ;
}
@ -889,11 +846,7 @@ Value sendmany(const Array& params, bool fHelp)
@@ -889,11 +846,7 @@ Value sendmany(const Array& params, bool fHelp)
vecSend . push_back ( make_pair ( scriptPubKey , nAmount ) ) ;
}
CRITICAL_BLOCK ( cs_main )
CRITICAL_BLOCK ( pwalletMain - > cs_mapWallet )
CRITICAL_BLOCK ( pwalletMain - > cs_vMasterKey )
{
if ( pwalletMain - > IsLocked ( ) )
if ( pwalletMain - > IsLocked ( ) )
throw JSONRPCError ( - 13 , " Error: Please enter the wallet passphrase with walletpassphrase first. " ) ;
// Check funds
@ -913,7 +866,6 @@ Value sendmany(const Array& params, bool fHelp)
@@ -913,7 +866,6 @@ Value sendmany(const Array& params, bool fHelp)
}
if ( ! pwalletMain - > CommitTransaction ( wtx , keyChange ) )
throw JSONRPCError ( - 4 , " Transaction commit failed " ) ;
}
return wtx . GetHash ( ) . GetHex ( ) ;
}
@ -944,8 +896,6 @@ Value ListReceived(const Array& params, bool fByAccounts)
@@ -944,8 +896,6 @@ Value ListReceived(const Array& params, bool fByAccounts)
// Tally
map < CBitcoinAddress , tallyitem > mapTally ;
CRITICAL_BLOCK ( pwalletMain - > cs_mapWallet )
{
for ( map < uint256 , CWalletTx > : : iterator it = pwalletMain - > mapWallet . begin ( ) ; it ! = pwalletMain - > mapWallet . end ( ) ; + + it )
{
const CWalletTx & wtx = ( * it ) . second ;
@ -967,13 +917,10 @@ Value ListReceived(const Array& params, bool fByAccounts)
@@ -967,13 +917,10 @@ Value ListReceived(const Array& params, bool fByAccounts)
item . nConf = min ( item . nConf , nDepth ) ;
}
}
}
// Reply
Array ret ;
map < string , tallyitem > mapAccountTally ;
CRITICAL_BLOCK ( pwalletMain - > cs_mapAddressBook )
{
BOOST_FOREACH ( const PAIRTYPE ( CBitcoinAddress , string ) & item , pwalletMain - > mapAddressBook )
{
const CBitcoinAddress & address = item . first ;
@ -1007,7 +954,6 @@ Value ListReceived(const Array& params, bool fByAccounts)
@@ -1007,7 +954,6 @@ Value ListReceived(const Array& params, bool fByAccounts)
ret . push_back ( obj ) ;
}
}
}
if ( fByAccounts )
{
@ -1107,8 +1053,6 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
@@ -1107,8 +1053,6 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
// Received
if ( listReceived . size ( ) > 0 & & wtx . GetDepthInMainChain ( ) > = nMinDepth )
CRITICAL_BLOCK ( pwalletMain - > cs_mapAddressBook )
{
BOOST_FOREACH ( const PAIRTYPE ( CBitcoinAddress , int64 ) & r , listReceived )
{
string account ;
@ -1126,8 +1070,6 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
@@ -1126,8 +1070,6 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
ret . push_back ( entry ) ;
}
}
}
}
void AcentryToJSON ( const CAccountingEntry & acentry , const string & strAccount , Array & ret )
@ -1167,8 +1109,6 @@ Value listtransactions(const Array& params, bool fHelp)
@@ -1167,8 +1109,6 @@ Value listtransactions(const Array& params, bool fHelp)
Array ret ;
CWalletDB walletdb ( pwalletMain - > strWalletFile ) ;
CRITICAL_BLOCK ( pwalletMain - > cs_mapWallet )
{
// Firs: get all CWalletTx and CAccountingEntry into a sorted-by-time multimap:
typedef pair < CWalletTx * , CAccountingEntry * > TxPair ;
typedef multimap < int64 , TxPair > TxItems ;
@ -1201,7 +1141,6 @@ Value listtransactions(const Array& params, bool fHelp)
@@ -1201,7 +1141,6 @@ Value listtransactions(const Array& params, bool fHelp)
if ( ret . size ( ) > = nCount ) break ;
}
// ret is now newest to oldest
}
// Make sure we return only last nCount items (sends-to-self might give us an extra):
if ( ret . size ( ) > nCount )
@ -1227,9 +1166,6 @@ Value listaccounts(const Array& params, bool fHelp)
@@ -1227,9 +1166,6 @@ Value listaccounts(const Array& params, bool fHelp)
nMinDepth = params [ 0 ] . get_int ( ) ;
map < string , int64 > mapAccountBalances ;
CRITICAL_BLOCK ( pwalletMain - > cs_mapWallet )
CRITICAL_BLOCK ( pwalletMain - > cs_mapAddressBook )
{
BOOST_FOREACH ( const PAIRTYPE ( CBitcoinAddress , string ) & entry , pwalletMain - > mapAddressBook ) {
if ( pwalletMain - > HaveKey ( entry . first ) ) // This address belongs to me
mapAccountBalances [ entry . second ] = 0 ;
@ -1256,7 +1192,6 @@ Value listaccounts(const Array& params, bool fHelp)
@@ -1256,7 +1192,6 @@ Value listaccounts(const Array& params, bool fHelp)
mapAccountBalances [ " " ] + = r . second ;
}
}
}
list < CAccountingEntry > acentries ;
CWalletDB ( pwalletMain - > strWalletFile ) . ListAccountCreditDebit ( " * " , acentries ) ;
@ -1281,8 +1216,7 @@ Value gettransaction(const Array& params, bool fHelp)
@@ -1281,8 +1216,7 @@ Value gettransaction(const Array& params, bool fHelp)
hash . SetHex ( params [ 0 ] . get_str ( ) ) ;
Object entry ;
CRITICAL_BLOCK ( pwalletMain - > cs_mapWallet )
{
if ( ! pwalletMain - > mapWallet . count ( hash ) )
throw JSONRPCError ( - 5 , " Invalid or non-wallet transaction id " ) ;
const CWalletTx & wtx = pwalletMain - > mapWallet [ hash ] ;
@ -1301,7 +1235,6 @@ Value gettransaction(const Array& params, bool fHelp)
@@ -1301,7 +1235,6 @@ Value gettransaction(const Array& params, bool fHelp)
Array details ;
ListTransactions ( pwalletMain - > mapWallet [ hash ] , " * " , 0 , false , details ) ;
entry . push_back ( Pair ( " details " , details ) ) ;
}
return entry ;
}
@ -1332,13 +1265,10 @@ Value keypoolrefill(const Array& params, bool fHelp)
@@ -1332,13 +1265,10 @@ Value keypoolrefill(const Array& params, bool fHelp)
" keypoolrefill \n "
" Fills the keypool. " ) ;
CRITICAL_BLOCK ( pwalletMain - > cs_vMasterKey )
{
if ( pwalletMain - > IsLocked ( ) )
throw JSONRPCError ( - 13 , " Error: Please enter the wallet passphrase with walletpassphrase first. " ) ;
pwalletMain - > TopUpKeyPool ( ) ;
}
if ( pwalletMain - > GetKeyPoolSize ( ) < GetArg ( " -keypool " , 100 ) )
throw JSONRPCError ( - 4 , " Error refreshing keypool. " ) ;
@ -1407,8 +1337,6 @@ Value walletpassphrase(const Array& params, bool fHelp)
@@ -1407,8 +1337,6 @@ Value walletpassphrase(const Array& params, bool fHelp)
mlock ( & strWalletPass [ 0 ] , strWalletPass . capacity ( ) ) ;
strWalletPass = params [ 0 ] . get_str ( ) ;
CRITICAL_BLOCK ( pwalletMain - > cs_vMasterKey )
{
if ( strWalletPass . length ( ) > 0 )
{
if ( ! pwalletMain - > Unlock ( strWalletPass ) )
@ -1424,7 +1352,6 @@ Value walletpassphrase(const Array& params, bool fHelp)
@@ -1424,7 +1352,6 @@ Value walletpassphrase(const Array& params, bool fHelp)
throw runtime_error (
" walletpassphrase <passphrase> <timeout> \n "
" Stores the wallet decryption key in memory for <timeout> seconds. " ) ;
}
CreateThread ( ThreadTopUpKeyPool , NULL ) ;
int * pnSleepTime = new int ( params [ 1 ] . get_int ( ) ) ;
@ -1553,12 +1480,9 @@ Value validateaddress(const Array& params, bool fHelp)
@@ -1553,12 +1480,9 @@ Value validateaddress(const Array& params, bool fHelp)
string currentAddress = address . ToString ( ) ;
ret . push_back ( Pair ( " address " , currentAddress ) ) ;
ret . push_back ( Pair ( " ismine " , ( pwalletMain - > HaveKey ( address ) > 0 ) ) ) ;
CRITICAL_BLOCK ( pwalletMain - > cs_mapAddressBook )
{
if ( pwalletMain - > mapAddressBook . count ( address ) )
ret . push_back ( Pair ( " account " , pwalletMain - > mapAddressBook [ address ] ) ) ;
}
}
return ret ;
}
@ -2233,7 +2157,10 @@ void ThreadRPCServer2(void* parg)
@@ -2233,7 +2157,10 @@ void ThreadRPCServer2(void* parg)
try
{
// Execute
Value result = ( * ( * mi ) . second ) ( params , false ) ;
Value result ;
CRITICAL_BLOCK ( cs_main )
CRITICAL_BLOCK ( pwalletMain - > cs_wallet )
result = ( * ( * mi ) . second ) ( params , false ) ;
// Send reply
string strReply = JSONRPCReply ( result , Value : : null , id ) ;