Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

bitcoinaddressvalidator.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin Core developers
2 // Copyright (c) 2014-2019 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 
7 #include <qt/guiutil.h>
8 
9 #include <base58.h>
10 
11 /* Base58 characters are:
12  "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
13 
14  This is:
15  - All numbers except for '0'
16  - All upper-case letters except for 'I' and 'O'
17  - All lower-case letters except for 'l'
18 */
19 
21  QValidator(parent), fAllowURI(fAllowURI)
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  if (fAllowURI && GUIUtil::validateBitcoinURI(input)) {
34  return QValidator::Acceptable;
35  }
36 
37  // Correction
38  for (int idx = 0; idx < input.size();)
39  {
40  bool removeChar = false;
41  QChar ch = input.at(idx);
42  // Corrections made are very conservative on purpose, to avoid
43  // users unexpectedly getting away with typos that would normally
44  // be detected, and thus sending to the wrong address.
45  switch(ch.unicode())
46  {
47  // Qt categorizes these as "Other_Format" not "Separator_Space"
48  case 0x200B: // ZERO WIDTH SPACE
49  case 0xFEFF: // ZERO WIDTH NO-BREAK SPACE
50  removeChar = true;
51  break;
52  default:
53  break;
54  }
55 
56  // Remove whitespace
57  if (ch.isSpace())
58  removeChar = true;
59 
60  // To next character
61  if (removeChar)
62  input.remove(idx, 1);
63  else
64  ++idx;
65  }
66 
67  // Validation
68  QValidator::State state = QValidator::Acceptable;
69  for (int idx = 0; idx < input.size(); ++idx)
70  {
71  int ch = input.at(idx).unicode();
72 
73  if (((ch >= '0' && ch<='9') ||
74  (ch >= 'a' && ch<='z') ||
75  (ch >= 'A' && ch<='Z')) &&
76  ch != 'l' && ch != 'I' && ch != '0' && ch != 'O')
77  {
78  // Alphanumeric and not a 'forbidden' character
79  }
80  else
81  {
82  state = QValidator::Invalid;
83  }
84  }
85 
86  return state;
87 }
88 
90  QValidator(parent)
91 {
92 }
93 
94 QValidator::State BitcoinAddressCheckValidator::validate(QString &input, int &pos) const
95 {
96  Q_UNUSED(pos);
97  // Validate the passed Dash address
98  if (IsValidDestinationString(input.toStdString())) {
99  return QValidator::Acceptable;
100  }
101 
102  return QValidator::Invalid;
103 }
bool IsValidDestinationString(const std::string &str, const CChainParams &params)
Definition: base58.cpp:341
State validate(QString &input, int &pos) const
bool validateBitcoinURI(const QString &uri)
Definition: guiutil.cpp:439
bool fAllowURI
BitcoinAddressEntryValidator(QObject *parent, bool fAllowURI=false)
State validate(QString &input, int &pos) const
Released under the MIT license