Anoncoin
0.9.4
P2P Digital Currency
Main Page
Namespaces
Classes
Files
File List
File Members
src
qt
anoncoinaddressvalidator.cpp
Go to the documentation of this file.
1
// Copyright (c) 2011-2014 The Bitcoin developers
2
// Copyright (c) 2013-2014 The Anoncoin Core developers
3
// Distributed under the MIT/X11 software license, see the accompanying
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6
#include "
anoncoinaddressvalidator.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
AnoncoinAddressEntryValidator::AnoncoinAddressEntryValidator
(QObject *parent) :
20
QValidator(parent)
21
{
22
}
23
24
QValidator::State
AnoncoinAddressEntryValidator::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
AnoncoinAddressCheckValidator::AnoncoinAddressCheckValidator
(QObject *parent) :
85
QValidator(parent)
86
{
87
}
88
89
QValidator::State
AnoncoinAddressCheckValidator::validate
(QString &input,
int
&pos)
const
90
{
91
Q_UNUSED(pos);
92
// Validate the passed Anoncoin address
93
CAnoncoinAddress
addr(input.toStdString());
94
if
(addr.IsValid())
95
return
QValidator::Acceptable;
96
97
return
QValidator::Invalid;
98
}
AnoncoinAddressEntryValidator::AnoncoinAddressEntryValidator
AnoncoinAddressEntryValidator(QObject *parent)
Definition:
anoncoinaddressvalidator.cpp:19
AnoncoinAddressCheckValidator::validate
State validate(QString &input, int &pos) const
Definition:
anoncoinaddressvalidator.cpp:89
base58.h
anoncoinaddressvalidator.h
CAnoncoinAddress
base58-encoded Anoncoin addresses.
Definition:
base58.h:102
AnoncoinAddressCheckValidator::AnoncoinAddressCheckValidator
AnoncoinAddressCheckValidator(QObject *parent)
Definition:
anoncoinaddressvalidator.cpp:84
AnoncoinAddressEntryValidator::validate
State validate(QString &input, int &pos) const
Definition:
anoncoinaddressvalidator.cpp:24
Generated on Fri Feb 6 2015 10:48:06 for Anoncoin by
1.8.9.1