aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.cpp10
-rw-r--r--src/qt/bitcoinamountfield.cpp10
-rw-r--r--src/qt/bitcoinunits.cpp11
-rw-r--r--src/qt/bitcoinunits.h2
4 files changed, 29 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp
index cadefe6dee..5cde2a43ec 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3567,6 +3567,16 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
CInv inv(MSG_TX, tx.GetHash());
pfrom->AddInventoryKnown(inv);
+ // Truncate messages to the size of the tx in them
+ unsigned int nSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
+ unsigned int oldSize = vMsg.size();
+ if (nSize < oldSize) {
+ vMsg.resize(nSize);
+ printf("truncating oversized TX %s (%u -> %u)\n",
+ tx.GetHash().ToString().c_str(),
+ oldSize, nSize);
+ }
+
bool fMissingInputs = false;
CValidationState state;
if (mempool.accept(state, tx, true, &fMissingInputs))
diff --git a/src/qt/bitcoinamountfield.cpp b/src/qt/bitcoinamountfield.cpp
index b12e296f99..b502505f31 100644
--- a/src/qt/bitcoinamountfield.cpp
+++ b/src/qt/bitcoinamountfield.cpp
@@ -60,7 +60,9 @@ bool BitcoinAmountField::validate()
bool valid = true;
if (amount->value() == 0.0)
valid = false;
- if (valid && !BitcoinUnits::parse(currentUnit, text(), 0))
+ else if (!BitcoinUnits::parse(currentUnit, text(), 0))
+ valid = false;
+ else if (amount->value() > BitcoinUnits::maxAmount(currentUnit))
valid = false;
setValid(valid);
@@ -115,7 +117,7 @@ qint64 BitcoinAmountField::value(bool *valid_out) const
{
qint64 val_out = 0;
bool valid = BitcoinUnits::parse(currentUnit, text(), &val_out);
- if(valid_out)
+ if (valid_out)
{
*valid_out = valid;
}
@@ -145,12 +147,12 @@ void BitcoinAmountField::unitChanged(int idx)
amount->setDecimals(BitcoinUnits::decimals(currentUnit));
amount->setMaximum(qPow(10, BitcoinUnits::amountDigits(currentUnit)) - qPow(10, -amount->decimals()));
- if(currentUnit == BitcoinUnits::uBTC)
+ if (currentUnit == BitcoinUnits::uBTC)
amount->setSingleStep(0.01);
else
amount->setSingleStep(0.001);
- if(valid)
+ if (valid)
{
// If value was valid, re-place it in the widget with the new unit
setValue(currentValue);
diff --git a/src/qt/bitcoinunits.cpp b/src/qt/bitcoinunits.cpp
index d4715abaec..ae9791123d 100644
--- a/src/qt/bitcoinunits.cpp
+++ b/src/qt/bitcoinunits.cpp
@@ -63,6 +63,17 @@ qint64 BitcoinUnits::factor(int unit)
}
}
+qint64 BitcoinUnits::maxAmount(int unit)
+{
+ switch(unit)
+ {
+ case BTC: return Q_INT64_C(21000000);
+ case mBTC: return Q_INT64_C(21000000000);
+ case uBTC: return Q_INT64_C(21000000000000);
+ default: return 0;
+ }
+}
+
int BitcoinUnits::amountDigits(int unit)
{
switch(unit)
diff --git a/src/qt/bitcoinunits.h b/src/qt/bitcoinunits.h
index 6e96cef59d..f6fdf6c7be 100644
--- a/src/qt/bitcoinunits.h
+++ b/src/qt/bitcoinunits.h
@@ -38,6 +38,8 @@ public:
static QString description(int unit);
//! Number of Satoshis (1e-8) per unit
static qint64 factor(int unit);
+ //! Max amount per unit
+ static qint64 maxAmount(int unit);
//! Number of amount digits (to represent max number of coins)
static int amountDigits(int unit);
//! Number of decimals left