X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fwallet.cpp;h=b740c8ac679e96b15b357b796e2174a20f059de7;hb=4ffa5951a45683c8609deca0f69fdabfc86697df;hp=c4e568c961615f329c35b7201509c4e755413f33;hpb=f70f613924ce2e572f40f0e4bb5112b880277f8d;p=novacoin.git diff --git a/src/wallet.cpp b/src/wallet.cpp index c4e568c..b740c8a 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -73,7 +73,7 @@ bool CWallet::AddCScript(const CScript& redeemScript) // 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) { @@ -1126,6 +1126,13 @@ bool CWallet::CreateTransaction(const vector >& vecSend, CW 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. @@ -1281,21 +1288,39 @@ bool CWallet::CreateCoinStake(unsigned int nBits, CTransaction& txNew) 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; @@ -1365,9 +1390,9 @@ string CWallet::SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, 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; } @@ -1586,7 +1611,8 @@ void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool) 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); } } @@ -1623,7 +1649,8 @@ void CWallet::ReturnKey(int64 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& result, bool fAllowReuse)