PRCYCoin
2.0.0.7rc1
P2P Digital Currency
src
qt
bitcoinaddressvalidator.cpp
Go to the documentation of this file.
1
// Copyright (c) 2011-2014 The Bitcoin developers
2
// Copyright (c) 2014-2015 The Dash developers
3
// Copyright (c) 2015-2018 The PIVX developers
4
// Copyright (c) 2018-2020 The DAPS Project developers
5
// Distributed under the MIT/X11 software license, see the accompanying
6
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
7
8
#include "
bitcoinaddressvalidator.h
"
9
10
#include "
base58.h
"
11
12
/* Base58 characters are:
13
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
14
15
This is:
16
- All numbers except for '0'
17
- All upper-case letters except for 'I' and 'O'
18
- All lower-case letters except for 'l'
19
*/
20
21
BitcoinAddressEntryValidator::BitcoinAddressEntryValidator
(QObject* parent) : QValidator(parent)
22
{
23
}
24
25
QValidator::State
BitcoinAddressEntryValidator::validate
(QString& input,
int
& pos)
const
26
{
27
Q_UNUSED(pos);
28
29
// Empty address is "intermediate" input
30
if
(input.isEmpty())
31
return
QValidator::Intermediate;
32
33
// Correction
34
for
(
int
idx = 0; idx < input.size();) {
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
// Qt categorizes these as "Other_Format" not "Separator_Space"
42
case
0x200B:
// ZERO WIDTH SPACE
43
case
0xFEFF:
// ZERO WIDTH NO-BREAK SPACE
44
removeChar =
true
;
45
break
;
46
default
:
47
break
;
48
}
49
50
// Remove whitespace
51
if
(ch.isSpace())
52
removeChar =
true
;
53
54
// To next character
55
if
(removeChar)
56
input.remove(idx, 1);
57
else
58
++idx;
59
}
60
61
// Validation
62
QValidator::State state = QValidator::Acceptable;
63
for
(
int
idx = 0; idx < input.size(); ++idx) {
64
int
ch = input.at(idx).unicode();
65
66
if
(((ch >=
'0'
&& ch <=
'9'
) ||
67
(ch >=
'a'
&& ch <=
'z'
) ||
68
(ch >=
'A'
&& ch <=
'Z'
)) &&
69
ch !=
'l'
&& ch !=
'I'
&& ch !=
'0'
&& ch !=
'O'
) {
70
// Alphanumeric and not a 'forbidden' character
71
}
else
{
72
state = QValidator::Invalid;
73
}
74
}
75
76
return
state;
77
}
78
79
BitcoinAddressCheckValidator::BitcoinAddressCheckValidator
(QObject* parent) : QValidator(parent)
80
{
81
}
82
83
QValidator::State
BitcoinAddressCheckValidator::validate
(QString& input,
int
& pos)
const
84
{
85
Q_UNUSED(pos);
86
// Validate the passed PRCY address
87
CBitcoinAddress
addr(input.toStdString());
88
if
(addr.
IsValid
())
89
return
QValidator::Acceptable;
90
91
return
QValidator::Invalid;
92
}
BitcoinAddressCheckValidator::validate
State validate(QString &input, int &pos) const
Definition:
bitcoinaddressvalidator.cpp:83
CBitcoinAddress
base58-encoded PRCY addresses.
Definition:
base58.h:109
BitcoinAddressEntryValidator::validate
State validate(QString &input, int &pos) const
Definition:
bitcoinaddressvalidator.cpp:25
BitcoinAddressCheckValidator::BitcoinAddressCheckValidator
BitcoinAddressCheckValidator(QObject *parent)
Definition:
bitcoinaddressvalidator.cpp:79
BitcoinAddressEntryValidator::BitcoinAddressEntryValidator
BitcoinAddressEntryValidator(QObject *parent)
Definition:
bitcoinaddressvalidator.cpp:21
bitcoinaddressvalidator.h
base58.h
CBitcoinAddress::IsValid
bool IsValid() const
Definition:
base58.cpp:254
Generated on Tue Apr 28 2026 00:02:53 for PRCYCoin by
1.8.17