From 12349122e5fcebf5cc4a4526ea32672cda147ef6 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Fri, 13 Apr 2012 20:43:29 -0700 Subject: [PATCH] Improve error reporting and add clearing to NewcoinAddress. --- src/NewcoinAddress.cpp | 44 ++++++++++++++++++++++++------------------ src/NewcoinAddress.h | 3 ++- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/NewcoinAddress.cpp b/src/NewcoinAddress.cpp index a22b7d763b..0ea477e6fd 100644 --- a/src/NewcoinAddress.cpp +++ b/src/NewcoinAddress.cpp @@ -9,17 +9,23 @@ #include #include #include +#include NewcoinAddress::NewcoinAddress() { nVersion = VER_NONE; } -bool NewcoinAddress::IsValid() +bool NewcoinAddress::IsValid() const { return !vchData.empty(); } +void NewcoinAddress::clear() +{ + nVersion = VER_NONE; +} + // // Hanko // @@ -38,7 +44,7 @@ uint160 NewcoinAddress::getHanko() const return Hash160(vchData); default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -61,7 +67,7 @@ std::string NewcoinAddress::humanHanko() const } default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -96,7 +102,7 @@ const std::vector& NewcoinAddress::getNodePublic() const return vchData; default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -113,7 +119,7 @@ std::string NewcoinAddress::humanNodePublic() const return ToString(); default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -141,7 +147,7 @@ uint256 NewcoinAddress::getNodePrivate() const return uint256(vchData); default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -155,7 +161,7 @@ std::string NewcoinAddress::humanNodePrivate() const return ToString(); default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -191,7 +197,7 @@ uint160 NewcoinAddress::getAccountID() const return Hash160(vchData); default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -214,7 +220,7 @@ std::string NewcoinAddress::humanAccountID() const } default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -246,7 +252,7 @@ const std::vector& NewcoinAddress::getAccountPublic() const return vchData; default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -263,7 +269,7 @@ std::string NewcoinAddress::humanAccountPublic() const return ToString(); default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -298,7 +304,7 @@ uint256 NewcoinAddress::getAccountPrivate() const return uint256(vchData); default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -312,7 +318,7 @@ std::string NewcoinAddress::humanAccountPrivate() const return ToString(); default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -346,7 +352,7 @@ BIGNUM* NewcoinAddress::getFamilyGeneratorBN() const break; default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } BIGNUM* ret = BN_bin2bn(&vchData[0], vchData.size(), NULL); @@ -366,7 +372,7 @@ const std::vector& NewcoinAddress::getFamilyGenerator() const return vchData; default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -380,7 +386,7 @@ std::string NewcoinAddress::humanFamilyGenerator() const return ToString(); default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -426,7 +432,7 @@ uint128 NewcoinAddress::getFamilySeed() const return uint128(vchData); default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -462,7 +468,7 @@ std::string NewcoinAddress::humanFamilySeed1751() const } default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } @@ -476,7 +482,7 @@ std::string NewcoinAddress::humanFamilySeed() const return ToString(); default: - throw std::runtime_error("bad source"); + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); } } diff --git a/src/NewcoinAddress.h b/src/NewcoinAddress.h index c98568c6e9..b4bc8c2481 100644 --- a/src/NewcoinAddress.h +++ b/src/NewcoinAddress.h @@ -27,7 +27,8 @@ private: public: NewcoinAddress(); - bool IsValid(); + bool IsValid() const; + void clear(); // // hanko