From c7bf973604a7cfca15dc70d647ce1016881d624b Mon Sep 17 00:00:00 2001 From: Sunny King Date: Sat, 3 Mar 2012 18:57:18 +0000 Subject: [PATCH] PPCoin: stakeonly mode for RPC command 'walletpassphrase' --- src/bitcoinrpc.cpp | 18 ++++++++++++++---- src/wallet.cpp | 10 ++++++++++ src/wallet.h | 2 ++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index fd753eb..2678d28 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -909,6 +909,8 @@ Value sendmany(const Array& params, bool fHelp) if (pwalletMain->IsLocked()) throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first."); + if (fWalletUnlockStakeOnly) + throw JSONRPCError(-13, "Error: Wallet unlocked for coinstake only."); // Check funds int64 nBalance = GetAccountBalance(strAccount, nMinDepth); @@ -1442,17 +1444,18 @@ void ThreadCleanWalletPassphrase(void* parg) Value walletpassphrase(const Array& params, bool fHelp) { - if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2)) + if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 3)) throw runtime_error( - "walletpassphrase \n" - "Stores the wallet decryption key in memory for seconds."); + "walletpassphrase [stakeonly]\n" + "Stores the wallet decryption key in memory for seconds." + "stakeonly is an optional true/false allowing only stake creation."); if (fHelp) return true; if (!pwalletMain->IsCrypted()) throw JSONRPCError(-15, "Error: running with an unencrypted wallet, but walletpassphrase was called."); if (!pwalletMain->IsLocked()) - throw JSONRPCError(-17, "Error: Wallet is already unlocked."); + throw JSONRPCError(-17, "Error: Wallet is already unlocked, use walletlock first if need to change unlock settings."); // Note that the walletpassphrase is stored in params[0] which is not mlock()ed SecureString strWalletPass; @@ -1475,6 +1478,12 @@ Value walletpassphrase(const Array& params, bool fHelp) int* pnSleepTime = new int(params[1].get_int()); CreateThread(ThreadCleanWalletPassphrase, pnSleepTime); + // ppcoin: if user OS account compromised prevent trivial sendmoney commands + if (params.size() > 2) + fWalletUnlockStakeOnly = params[2].get_bool(); + else + fWalletUnlockStakeOnly = false; + return Value::null; } @@ -2552,6 +2561,7 @@ int CommandLineRPC(int argc, char *argv[]) if (strMethod == "listtransactions" && n > 2) ConvertTo(params[2]); if (strMethod == "listaccounts" && n > 0) ConvertTo(params[0]); if (strMethod == "walletpassphrase" && n > 1) ConvertTo(params[1]); + if (strMethod == "walletpassphrase" && n > 2) ConvertTo(params[2]); if (strMethod == "listsinceblock" && n > 1) ConvertTo(params[1]); if (strMethod == "sendmany" && n > 1) { diff --git a/src/wallet.cpp b/src/wallet.cpp index 0ef2167..564362b 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -43,6 +43,10 @@ bool CWallet::AddCryptedKey(const vector &vchPubKey, const vector return false; } +// ppcoin: optional setting to create coinstake only when unlocked; +// serves to disable the trivial sendmoney when OS account compromised +bool fWalletUnlockStakeOnly = false; + bool CWallet::Unlock(const SecureString& strWalletPassphrase) { if (!IsLocked()) @@ -1184,6 +1188,12 @@ string CWallet::SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, printf("SendMoney() : %s", strError.c_str()); return strError; } + if (fWalletUnlockStakeOnly) + { + string strError = _("Error: Wallet unlocked for coinstake only, unable to create transaction."); + printf("SendMoney() : %s", strError.c_str()); + return strError; + } if (!CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired)) { string strError; diff --git a/src/wallet.h b/src/wallet.h index eec8a06..8769588 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -10,6 +10,8 @@ #include "key.h" #include "script.h" +extern bool fWalletUnlockStakeOnly; + class CWalletTx; class CReserveKey; class CWalletDB; -- 1.7.1