Raven Core  3.0.0
P2P Digital Currency
ravenaddressvalidator.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven 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 
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 
20  QValidator(parent)
21 {
22 }
23 
24 QValidator::State RavenAddressEntryValidator::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 
85  QValidator(parent)
86 {
87 }
88 
89 QValidator::State RavenAddressCheckValidator::validate(QString &input, int &pos) const
90 {
91  Q_UNUSED(pos);
92  // Validate the passed Raven address
93  if (IsValidDestinationString(input.toStdString())) {
94  return QValidator::Acceptable;
95  }
96 
97  return QValidator::Invalid;
98 }
RavenAddressEntryValidator(QObject *parent)
State validate(QString &input, int &pos) const
bool IsValidDestinationString(const std::string &str, const CChainParams &params)
Definition: base58.cpp:338
RavenAddressCheckValidator(QObject *parent)
State validate(QString &input, int &pos) const