mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
Merge pull request #2679 from vhf/patch-1
Too many bitcoins allowed as amount. (Issue #2401)
This commit is contained in:
commit
2e01ec3207
3 changed files with 19 additions and 4 deletions
|
@ -60,7 +60,9 @@ bool BitcoinAmountField::validate()
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
if (amount->value() == 0.0)
|
if (amount->value() == 0.0)
|
||||||
valid = false;
|
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;
|
valid = false;
|
||||||
|
|
||||||
setValid(valid);
|
setValid(valid);
|
||||||
|
|
|
@ -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)
|
int BitcoinUnits::amountDigits(int unit)
|
||||||
{
|
{
|
||||||
switch(unit)
|
switch(unit)
|
||||||
|
|
|
@ -38,6 +38,8 @@ public:
|
||||||
static QString description(int unit);
|
static QString description(int unit);
|
||||||
//! Number of Satoshis (1e-8) per unit
|
//! Number of Satoshis (1e-8) per unit
|
||||||
static qint64 factor(int 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)
|
//! Number of amount digits (to represent max number of coins)
|
||||||
static int amountDigits(int unit);
|
static int amountDigits(int unit);
|
||||||
//! Number of decimals left
|
//! Number of decimals left
|
||||||
|
|
Loading…
Add table
Reference in a new issue