Merge pull request #2009 from sipa/fixmove

Prevent RPC 'move' from deadlocking
This commit is contained in:
Gavin Andresen 2012-11-16 08:09:41 -08:00
commit e45d39f9ee
3 changed files with 10 additions and 6 deletions

View File

@ -573,7 +573,7 @@ Value movecmd(const Array& params, bool fHelp)
// Debit // Debit
CAccountingEntry debit; CAccountingEntry debit;
debit.nOrderPos = pwalletMain->IncOrderPosNext(); debit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
debit.strAccount = strFrom; debit.strAccount = strFrom;
debit.nCreditDebit = -nAmount; debit.nCreditDebit = -nAmount;
debit.nTime = nNow; debit.nTime = nNow;
@ -583,7 +583,7 @@ Value movecmd(const Array& params, bool fHelp)
// Credit // Credit
CAccountingEntry credit; CAccountingEntry credit;
credit.nOrderPos = pwalletMain->IncOrderPosNext(); credit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
credit.strAccount = strTo; credit.strAccount = strTo;
credit.nCreditDebit = nAmount; credit.nCreditDebit = nAmount;
credit.nTime = nNow; credit.nTime = nNow;

View File

@ -291,10 +291,14 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
return true; return true;
} }
int64 CWallet::IncOrderPosNext() int64 CWallet::IncOrderPosNext(CWalletDB *pwalletdb)
{ {
int64 nRet = nOrderPosNext; int64 nRet = nOrderPosNext++;
CWalletDB(strWalletFile).WriteOrderPosNext(++nOrderPosNext); if (pwalletdb) {
pwalletdb->WriteOrderPosNext(nOrderPosNext);
} else {
CWalletDB(strWalletFile).WriteOrderPosNext(nOrderPosNext);
}
return nRet; return nRet;
} }

View File

@ -149,7 +149,7 @@ public:
/** Increment the next transaction order id /** Increment the next transaction order id
@return next transaction order id @return next transaction order id
*/ */
int64 IncOrderPosNext(); int64 IncOrderPosNext(CWalletDB *pwalletdb = NULL);
typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair; typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
typedef std::multimap<int64, TxPair > TxItems; typedef std::multimap<int64, TxPair > TxItems;