Dash Core
0.12.2.1
P2P Digital Currency
bitcoinaddressvalidator.cpp
Go to the documentation of this file.
1
// Copyright (c) 2011-2014 The Bitcoin Core developers
2
// Copyright (c) 2014-2017 The Dash Core developers
3
// Distributed under the MIT software license, see the accompanying
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6
#include "
bitcoinaddressvalidator.h
"
7
8
#include "
base58.h
"
9
10
/* Base58 characters are:
11
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
12
13
This is:
14
- All numbers except for '0'
15
- All upper-case letters except for 'I' and 'O'
16
- All lower-case letters except for 'l'
17
*/
18
19
BitcoinAddressEntryValidator::BitcoinAddressEntryValidator
(QObject *parent) :
20
QValidator(parent)
21
{
22
}
23
24
QValidator::State
BitcoinAddressEntryValidator::validate
(QString &input,
int
&pos)
const
25
{
26
Q_UNUSED(pos);
27
28
// Empty address is "intermediate" input
29
if
(input.isEmpty())
30
return
QValidator::Intermediate;
31
32
// Correction
33
for
(
int
idx = 0; idx < input.size();)
34
{
35
bool
removeChar =
false
;
36
QChar ch = input.at(idx);
37
// Corrections made are very conservative on purpose, to avoid
38
// users unexpectedly getting away with typos that would normally
39
// be detected, and thus sending to the wrong address.
40
switch
(ch.unicode())
41
{
42
// Qt categorizes these as "Other_Format" not "Separator_Space"
43
case
0x200B:
// ZERO WIDTH SPACE
44
case
0xFEFF:
// ZERO WIDTH NO-BREAK SPACE
45
removeChar =
true
;
46
break
;
47
default
:
48
break
;
49
}
50
51
// Remove whitespace
52
if
(ch.isSpace())
53
removeChar =
true
;
54
55
// To next character
56
if
(removeChar)
57
input.remove(idx, 1);
58
else
59
++idx;
60
}
61
62
// Validation
63
QValidator::State state = QValidator::Acceptable;
64
for
(
int
idx = 0; idx < input.size(); ++idx)
65
{
66
int
ch = input.at(idx).unicode();
67
68
if
(((ch >=
'0'
&& ch<=
'9'
) ||
69
(ch >=
'a'
&& ch<=
'z'
) ||
70
(ch >=
'A'
&& ch<=
'Z'
)) &&
71
ch !=
'l'
&& ch !=
'I'
&& ch !=
'0'
&& ch !=
'O'
)
72
{
73
// Alphanumeric and not a 'forbidden' character
74
}
75
else
76
{
77
state = QValidator::Invalid;
78
}
79
}
80
81
return
state;
82
}
83
84
BitcoinAddressCheckValidator::BitcoinAddressCheckValidator
(QObject *parent) :
85
QValidator(parent)
86
{
87
}
88
89
QValidator::State
BitcoinAddressCheckValidator::validate
(QString &input,
int
&pos)
const
90
{
91
Q_UNUSED(pos);
92
// Validate the passed Dash address
93
CBitcoinAddress
addr(input.toStdString());
94
if
(addr.IsValid())
95
return
QValidator::Acceptable;
96
97
return
QValidator::Invalid;
98
}
CBitcoinAddress
Definition:
base58.h:104
BitcoinAddressCheckValidator::BitcoinAddressCheckValidator
BitcoinAddressCheckValidator(QObject *parent)
Definition:
bitcoinaddressvalidator.cpp:84
base58.h
BitcoinAddressEntryValidator::validate
State validate(QString &input, int &pos) const
Definition:
bitcoinaddressvalidator.cpp:24
BitcoinAddressEntryValidator::BitcoinAddressEntryValidator
BitcoinAddressEntryValidator(QObject *parent)
Definition:
bitcoinaddressvalidator.cpp:19
bitcoinaddressvalidator.h
BitcoinAddressCheckValidator::validate
State validate(QString &input, int &pos) const
Definition:
bitcoinaddressvalidator.cpp:89
src
qt
bitcoinaddressvalidator.cpp
Generated on Thu Dec 14 2017 13:15:04 for Dash Core by
1.8.14