aboutsummaryrefslogtreecommitdiffstats
path: root/libdevcore/CommonData.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-02-01 01:29:51 +0800
committerGitHub <noreply@github.com>2017-02-01 01:29:51 +0800
commit364da425d3116a4b85863df39a1864340861d71e (patch)
tree521a52c3f8182cd6a054f148bd649c8b6b0e2af9 /libdevcore/CommonData.cpp
parent60cc1668517f56ce6ca8225555472e7a27eab8b0 (diff)
parent7b18c9df1dfa0076566bfa1e4a3bc5e5ba9c8594 (diff)
downloaddexon-solidity-364da425d3116a4b85863df39a1864340861d71e.tar
dexon-solidity-364da425d3116a4b85863df39a1864340861d71e.tar.gz
dexon-solidity-364da425d3116a4b85863df39a1864340861d71e.tar.bz2
dexon-solidity-364da425d3116a4b85863df39a1864340861d71e.tar.lz
dexon-solidity-364da425d3116a4b85863df39a1864340861d71e.tar.xz
dexon-solidity-364da425d3116a4b85863df39a1864340861d71e.tar.zst
dexon-solidity-364da425d3116a4b85863df39a1864340861d71e.zip
Merge pull request #1622 from ethereum/develop
Solidity version 0.4.9
Diffstat (limited to 'libdevcore/CommonData.cpp')
-rw-r--r--libdevcore/CommonData.cpp40
1 files changed, 38 insertions, 2 deletions
diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp
index 062d1b29..a53d9628 100644
--- a/libdevcore/CommonData.cpp
+++ b/libdevcore/CommonData.cpp
@@ -19,8 +19,12 @@
* @date 2014
*/
-#include "CommonData.h"
-#include "Exceptions.h"
+#include <libdevcore/CommonData.h>
+#include <libdevcore/Exceptions.h>
+#include <libdevcore/SHA3.h>
+
+#include <boost/algorithm/string.hpp>
+
using namespace std;
using namespace dev;
@@ -95,3 +99,35 @@ bytes dev::fromHex(std::string const& _s, WhenError _throw)
}
return ret;
}
+
+
+bool dev::passesAddressChecksum(string const& _str, bool _strict)
+{
+ string s = _str.substr(0, 2) == "0x" ? _str.substr(2) : _str;
+
+ if (s.length() != 40)
+ return false;
+
+ if (!_strict && (
+ _str.find_first_of("abcdef") == string::npos ||
+ _str.find_first_of("ABCDEF") == string::npos
+ ))
+ return true;
+
+ h256 hash = keccak256(boost::algorithm::to_lower_copy(s, std::locale::classic()));
+ for (size_t i = 0; i < 40; ++i)
+ {
+ char addressCharacter = s[i];
+ bool lowerCase;
+ if ('a' <= addressCharacter && addressCharacter <= 'f')
+ lowerCase = true;
+ else if ('A' <= addressCharacter && addressCharacter <= 'F')
+ lowerCase = false;
+ else
+ continue;
+ unsigned nibble = (unsigned(hash[i / 2]) >> (4 * (1 - (i % 2)))) & 0xf;
+ if ((nibble >= 8) == lowerCase)
+ return false;
+ }
+ return true;
+}