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.");
+ if (fWalletUnlockMintOnly)
+ throw JSONRPCError(-13, "Error: Wallet unlocked for block minting only.");
// Check funds
int64 nBalance = GetAccountBalance(strAccount, nMinDepth);
{
if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 3))
throw runtime_error(
- "walletpassphrase <passphrase> <timeout> [stakeonly]\n"
+ "walletpassphrase <passphrase> <timeout> [mintonly]\n"
"Stores the wallet decryption key in memory for <timeout> seconds.\n"
- "stakeonly is optional true/false allowing only stake creation.");
+ "mintonly is optional true/false allowing only block minting.");
if (fHelp)
return true;
if (!pwalletMain->IsCrypted())
// ppcoin: if user OS account compromised prevent trivial sendmoney commands
if (params.size() > 2)
- fWalletUnlockStakeOnly = params[2].get_bool();
+ fWalletUnlockMintOnly = params[2].get_bool();
else
- fWalletUnlockStakeOnly = false;
+ fWalletUnlockMintOnly = false;
return Value::null;
}
pblock->vtx[0].vin[0].scriptSig = mapNewBlock[pdata->hashMerkleRoot].second;
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
if (!pblock->SignBlock(*pwalletMain))
- throw JSONRPCError(-100, "Unable to sign block");
+ throw JSONRPCError(-100, "Unable to sign block, wallet locked?");
return CheckWork(pblock, *pwalletMain, reservekey);
}
map<uint256, CAlert> mapAlerts;
CCriticalSection cs_mapAlerts;
+static string strMintMessage = _("Info: Minting suspended due to locked wallet.");
+static string strMintWarning;
+
string GetWarnings(string strFor)
{
int nPriority = 0;
if (GetBoolArg("-testsafemode"))
strRPC = "test";
+ // ppcoin: wallet lock warning for minting
+ if (strMintWarning != "")
+ {
+ nPriority = 0;
+ strStatusBar = strMintWarning;
+ }
+
// Misc warnings like out of disk space and clock is wrong
if (strMiscWarning != "")
{
uint64 nLastBlockTx = 0;
uint64 nLastBlockSize = 0;
+// CreateNewBlock:
+// fProofOfStake: try (best effort) to make a proof-of-stake block
CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake)
{
CReserveKey reservekey(pwallet);
static unsigned int nLastCoinStakeCheckTime = GetAdjustedTime() - nMaxClockDrift / 2; // only initialized at startup
CBlockIndex* pindexPrev = pindexBest;
- if (fProofOfStake)
+ if (fProofOfStake) // attemp to find a coinstake
{
while (nLastCoinStakeCheckTime < GetAdjustedTime())
{
// Fill in header
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
- pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
- pblock->nTime = max(pblock->GetBlockTime(), pblock->GetMaxTransactionTime());
+ pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, pblock->GetMaxTransactionTime());
pblock->nTime = max(pblock->GetBlockTime(), pindexPrev->GetBlockTime() - nMaxClockDrift);
pblock->UpdateTime(pindexPrev);
pblock->nNonce = 0;
CReserveKey reservekey(pwallet);
unsigned int nExtraNonce = 0;
- while (fGenerateBitcoins)
+ while (fGenerateBitcoins || fProofOfStake)
{
if (fShutdown)
return;
Sleep(1000);
if (fShutdown)
return;
- if (!fGenerateBitcoins)
+ if ((!fGenerateBitcoins) && !fProofOfStake)
return;
}
+ while (pwallet->IsLocked())
+ {
+ strMintWarning = strMintMessage;
+ Sleep(1000);
+ }
+ strMintWarning = "";
//
// Create new block
IncrementExtraNonce(pblock.get(), pindexPrev, nExtraNonce);
// ppcoin: if proof-of-stake block found then process block
- if (pblock->IsProofOfStake())
+ if (fProofOfStake)
{
- if (!pblock->SignBlock(*pwalletMain))
+ if (pblock->IsProofOfStake())
{
- error("CPUMiner: Unable to sign new proof-of-stake block");
- return;
+ if (!pblock->SignBlock(*pwalletMain))
+ {
+ strMintWarning = strMintMessage;
+ continue;
+ }
+ strMintWarning = "";
+ printf("CPUMiner : proof-of-stake block found %s\n", pblock->GetHash().ToString().c_str());
+ SetThreadPriority(THREAD_PRIORITY_NORMAL);
+ CheckWork(pblock.get(), *pwalletMain, reservekey);
+ SetThreadPriority(THREAD_PRIORITY_LOWEST);
}
- printf("CPUMiner : proof-of-stake block found %s\n", pblock->GetHash().ToString().c_str());
- SetThreadPriority(THREAD_PRIORITY_NORMAL);
- CheckWork(pblock.get(), *pwalletMain, reservekey);
- SetThreadPriority(THREAD_PRIORITY_LOWEST);
Sleep(500);
continue;
}
assert(hash == pblock->GetHash());
if (!pblock->SignBlock(*pwalletMain))
{
- error("BitcoinMiner: Unable to sign new proof-of-work block");
- return;
+ strMintWarning = strMintMessage;
+ break;
}
-
+ strMintWarning = "";
SetThreadPriority(THREAD_PRIORITY_NORMAL);
CheckWork(pblock.get(), *pwalletMain, reservekey);
SetThreadPriority(THREAD_PRIORITY_LOWEST);
break;
// Update nTime every few seconds
- pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
- pblock->nTime = max(pblock->GetBlockTime(), pblock->GetMaxTransactionTime());
+ pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, pblock->GetMaxTransactionTime());
pblock->nTime = max(pblock->GetBlockTime(), pindexPrev->GetBlockTime() - nMaxClockDrift);
pblock->UpdateTime(pindexPrev);
nBlockTime = ByteReverse(pblock->nTime);