Skip to content

Commit

Permalink
protect from accidental forks
Browse files Browse the repository at this point in the history
  • Loading branch information
backpacker69 committed Jan 3, 2019
1 parent 78714a0 commit 515bb79
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main.cpp
Expand Up @@ -609,7 +609,7 @@ bool CTransaction::CheckTransaction(CValidationState &state) const
return state.DoS(100, error("CTransaction::CheckTransaction() : txout empty for user transaction"));
// ppcoin: enforce minimum output amount
// v0.5 protocol: zero amount allowed
if ((!txout.IsEmpty()) && txout.nValue < MIN_TXOUT_AMOUNT &&
if ((!txout.IsEmpty()) && txout.nValue < (IsProtocolV07(nTime) ? MIN_TXOUT_AMOUNT_V7 : MIN_TXOUT_AMOUNT) &&
!(IsProtocolV05(nTime) && (txout.nValue == 0)))
return state.DoS(100, error("CTransaction::CheckTransaction() : txout.nValue below minimum"));
if (txout.nValue > MAX_MONEY)
Expand Down
3 changes: 2 additions & 1 deletion src/main.h
Expand Up @@ -65,7 +65,8 @@ static const int64 MIN_TX_FEE = CENT / 10;
static const int64 MIN_RELAY_TX_FEE = CENT / 10;
static const int64 PERKB_TX_FEE = CENT;
static const int64 MAX_MINT_PROOF_OF_WORK = 9999 * COIN;
static const int64 MIN_TXOUT_AMOUNT = MIN_TX_FEE;
static const int64 MIN_TXOUT_AMOUNT = CENT;
static const int64 MIN_TXOUT_AMOUNT_V7 = MIN_TX_FEE;
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
static const int COINBASE_MATURITY_PPC = 500;
/** Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp. */
Expand Down
4 changes: 2 additions & 2 deletions src/qt/coincontroldialog.cpp
Expand Up @@ -462,7 +462,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
coinControl->ListSelected(vCoinControl);
model->getOutputs(vCoinControl, vOutputs);

nPayFee = MIN_TX_FEE;
nPayFee = (fNewFees ? MIN_TX_FEE : PERKB_TX_FEE);
ploop
{
txDummy.vin.clear();
Expand Down Expand Up @@ -538,7 +538,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
}

// ppcoin: sub-cent change is moved to fee
if (nChange > 0 && nChange < MIN_TXOUT_AMOUNT)
if (nChange > 0 && nChange < (fNewFees ? MIN_TXOUT_AMOUNT_V7 : MIN_TXOUT_AMOUNT))
{
nPayFee += nChange;
nChange = 0;
Expand Down
4 changes: 3 additions & 1 deletion src/qt/walletmodel.cpp
Expand Up @@ -9,6 +9,7 @@
#include "wallet.h"
#include "walletdb.h" // for BackupWallet
#include "base58.h"
#include "kernel.h"

#include <QSet>
#include <QTimer>
Expand Down Expand Up @@ -142,6 +143,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList<SendCoinsRecipie
qint64 total = 0;
QSet<QString> setAddress;
QString hex;
bool fNewFees = IsProtocolV07(GetAdjustedTime());

if(recipients.empty())
{
Expand All @@ -157,7 +159,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList<SendCoinsRecipie
}
setAddress.insert(rcp.address);

if(rcp.amount < MIN_TXOUT_AMOUNT)
if(rcp.amount < (fNewFees ? MIN_TXOUT_AMOUNT_V7 : MIN_TXOUT_AMOUNT))
{
return InvalidAmount;
}
Expand Down
7 changes: 4 additions & 3 deletions src/rpcwallet.cpp
Expand Up @@ -15,6 +15,7 @@
#include "init.h"
#include "base58.h"
#include "checkpointsync.h"
#include "kernel.h"

#include <boost/assign/list_of.hpp>

Expand Down Expand Up @@ -278,7 +279,7 @@ Value sendtoaddress(const Array& params, bool fHelp)

// Amount
int64 nAmount = AmountFromValue(params[1]);
if (nAmount < MIN_TXOUT_AMOUNT)
if (nAmount < (IsProtocolV07(GetAdjustedTime()) ? MIN_TXOUT_AMOUNT_V7 : MIN_TXOUT_AMOUNT))
throw JSONRPCError(-101, "Send amount too small");

// Wallet comments
Expand Down Expand Up @@ -634,7 +635,7 @@ Value sendfrom(const Array& params, bool fHelp)
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Peercoin address");
int64 nAmount = AmountFromValue(params[2]);
if (nAmount < MIN_TXOUT_AMOUNT)
if (nAmount < (IsProtocolV07(GetAdjustedTime()) ? MIN_TXOUT_AMOUNT_V7 : MIN_TXOUT_AMOUNT))
throw JSONRPCError(-101, "Send amount too small");
int nMinDepth = 1;
if (params.size() > 3)
Expand Down Expand Up @@ -699,7 +700,7 @@ Value sendmany(const Array& params, bool fHelp)
CScript scriptPubKey;
scriptPubKey.SetDestination(address.Get());
int64 nAmount = AmountFromValue(s.value_);
if (nAmount < MIN_TXOUT_AMOUNT)
if (nAmount < (IsProtocolV07(GetAdjustedTime()) ? MIN_TXOUT_AMOUNT_V7 : MIN_TXOUT_AMOUNT))
throw JSONRPCError(-101, "Send amount too small");
totalAmount += nAmount;

Expand Down
9 changes: 5 additions & 4 deletions src/wallet.cpp
Expand Up @@ -1230,7 +1230,8 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend,
{
LOCK2(cs_main, cs_wallet);
{
nFeeRet = MIN_TX_FEE;
bool fNewFees = IsProtocolV07(wtxNew.nTime);
nFeeRet = fNewFees ? MIN_TX_FEE : PERKB_TX_FEE;
ploop
{
wtxNew.vin.clear();
Expand Down Expand Up @@ -1271,7 +1272,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend,
}

int64 nChange = nValueIn - nValue - nFeeRet;
int64 nMinFeeBase = IsProtocolV07(wtxNew.nTime) ? MIN_TX_FEE : MIN_TX_FEE*10;
int64 nMinFeeBase = fNewFees ? MIN_TX_FEE : PERKB_TX_FEE;
// The following if statement should be removed once enough miners
// have upgraded to the 0.9 GetMinFee() rules. Until then, this avoids
// creating free transactions that have change outputs less than
Expand All @@ -1284,7 +1285,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend,
}

// ppcoin: sub-cent change is moved to fee
if (nChange > 0 && nChange < MIN_TXOUT_AMOUNT)
if (nChange > 0 && nChange < (fNewFees ? MIN_TXOUT_AMOUNT_V7 : MIN_TXOUT_AMOUNT))
{
nFeeRet += nChange;
nChange = 0;
Expand Down Expand Up @@ -1357,7 +1358,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend,

// Check that enough fee is included
int64 nPayFee;
if (IsProtocolV07(wtxNew.nTime))
if (fNewFees)
nPayFee = (nBytes < 100) ? MIN_TX_FEE : (int64)(nBytes * (nTransactionFee / 1000));
else
nPayFee = nTransactionFee * (1 + (int64)nBytes / 1000);
Expand Down

0 comments on commit 515bb79

Please sign in to comment.