Transactions verification update
[novacoin.git] / src / wallet.cpp
index 2502f8f..b413dbc 100644 (file)
@@ -1466,15 +1466,15 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CW
                 // NOTE: this depends on the exact behaviour of GetMinFee
                 if (wtxNew.nTime < FEE_SWITCH_TIME && !fTestNet)
                 {
-                    if (nFeeRet < MIN_TX_FEE && nChange > 0 && nChange < CENT)
+                    if (nFeeRet < CENT && nChange > 0 && nChange < CENT)
                     {
-                        int64 nMoveToFee = min(nChange, MIN_TX_FEE - nFeeRet);
+                        int64 nMoveToFee = min(nChange, CENT - nFeeRet);
                         nChange -= nMoveToFee;
                         nFeeRet += nMoveToFee;
                     }
 
                     // sub-cent change is moved to fee
-                    if (nChange > 0 && nChange < MIN_TXOUT_AMOUNT)
+                    if (nChange > 0 && nChange < CENT)
                     {
                         nFeeRet += nChange;
                         nChange = 0;
@@ -1535,6 +1535,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CW
                 int64 nPayFee = nTransactionFee * (1 + (int64)nBytes / 1000);
                 bool fAllowFree = CTransaction::AllowFree(dPriority);
 
+                // Disable free transactions until 1 July 2014
                 if (!fTestNet && wtxNew.nTime < FEE_SWITCH_TIME)
                 {
                     fAllowFree = false;
@@ -1565,6 +1566,22 @@ bool CWallet::CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& w
     return CreateTransaction(vecSend, wtxNew, reservekey, nFeeRet, coinControl);
 }
 
+void CWallet::GetStakeWeightFromValue(const int64& nTime, const int64& nValue, uint64& nWeight)
+{
+    int64 nTimeWeight = GetWeight(nTime, (int64)GetTime());
+
+    // If time weight is lower or equal to zero then weight is zero.
+    if (nTimeWeight <= 0)
+    {
+        nWeight = 0;
+        return;
+    }
+
+    CBigNum bnCoinDayWeight = CBigNum(nValue) * nTimeWeight / COIN / (24 * 60 * 60);
+    nWeight = bnCoinDayWeight.getuint64();
+}
+
+
 // NovaCoin: get current stake weight
 bool CWallet::GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint64& nMaxWeight, uint64& nWeight)
 {
@@ -1851,9 +1868,9 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
             return error("CreateCoinStake : exceeded coinstake size limit");
 
         // Check enough fee is paid
-        if (nMinFee < txNew.GetMinFee() - MIN_TX_FEE)
+        if (nMinFee < txNew.GetMinFee(1, false, GMF_BLOCK, nBytes) - CENT)
         {
-            nMinFee = txNew.GetMinFee() - MIN_TX_FEE;
+            nMinFee = txNew.GetMinFee(1, false, GMF_BLOCK, nBytes) - CENT;
             continue; // try signing again
         }
         else