// ppcoin: optional setting to create coinstake only when unlocked;
// serves to disable the trivial sendmoney when OS account compromised
-bool fWalletUnlockStakeOnly = false;
+bool fWalletUnlockMintOnly = false;
bool CWallet::Unlock(const SecureString& strWalletPassphrase)
{
nFeeRet += nMoveToFee;
}
+ // ppcoin: sub-cent change is moved to fee
+ if (nChange > 0 && nChange < MIN_TXOUT_AMOUNT)
+ {
+ nFeeRet += nChange;
+ nChange = 0;
+ }
+
if (nChange > 0)
{
// Note: We use a new key here to keep it from being obvious which side is the change.
return error("CreateCoinStake : failed to calculate coin age");
nCredit += GetProofOfStakeReward(nCoinAge);
}
- // Set output amount
- txNew.vout[1].nValue = nCredit;
- // Sign
- int nIn = 0;
- BOOST_FOREACH(const CWalletTx* pcoin, vwtxPrev)
+ int64 nMinFee = 0;
+ loop
{
- if (!SignSignature(*this, *pcoin, txNew, nIn++))
- return error("CreateCoinStake : failed to sign coinstake");
- }
+ // Set output amount
+ txNew.vout[1].nValue = nCredit - nMinFee;
- // Limit size
- unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION);
- if (nBytes >= MAX_BLOCK_SIZE_GEN/5)
- return false;
+ // Sign
+ int nIn = 0;
+ BOOST_FOREACH(const CWalletTx* pcoin, vwtxPrev)
+ {
+ if (!SignSignature(*this, *pcoin, txNew, nIn++))
+ return error("CreateCoinStake : failed to sign coinstake");
+ }
+
+ // Limit size
+ unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION);
+ if (nBytes >= MAX_BLOCK_SIZE_GEN/5)
+ return false;
+
+ // Check enough fee is paid
+ if (nMinFee < txNew.GetMinFee() - MIN_TX_FEE)
+ {
+ nMinFee = txNew.GetMinFee() - MIN_TX_FEE;
+ continue; // try signing again
+ }
+ else
+ {
+ if (fDebug && GetBoolArg("-printfee"))
+ printf("CreateCoinStake : fee for coinstake %s\n", FormatMoney(nMinFee).c_str());
+ break;
+ }
+ }
// Successfully generated coinstake
return true;
printf("SendMoney() : %s", strError.c_str());
return strError;
}
- if (fWalletUnlockStakeOnly)
+ if (fWalletUnlockMintOnly)
{
- string strError = _("Error: Wallet unlocked for coinstake only, unable to create transaction.");
+ string strError = _("Error: Wallet unlocked for block minting only, unable to create transaction.");
printf("SendMoney() : %s", strError.c_str());
return strError;
}
if (!HaveKey(Hash160(keypool.vchPubKey)))
throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool");
assert(!keypool.vchPubKey.empty());
- printf("keypool reserve %"PRI64d"\n", nIndex);
+ if (fDebug && GetBoolArg("-printkeypool"))
+ printf("keypool reserve %"PRI64d"\n", nIndex);
}
}
LOCK(cs_wallet);
setKeyPool.insert(nIndex);
}
- printf("keypool return %"PRI64d"\n", nIndex);
+ if (fDebug && GetBoolArg("-printkeypool"))
+ printf("keypool return %"PRI64d"\n", nIndex);
}
bool CWallet::GetKeyFromPool(vector<unsigned char>& result, bool fAllowReuse)