From 3dc2e6a7d08d061791c8b79b7fcb3e5cc442c85d Mon Sep 17 00:00:00 2001 From: monacoinproject Date: Sun, 20 Sep 2015 10:31:47 +0900 Subject: [PATCH] Fixed a bug: permit the old prefix --- src/base58.cpp | 16 +++++++++++----- src/base58.h | 6 +++--- src/rpcdump.cpp | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/base58.cpp b/src/base58.cpp index c594993ea09..6386275e016 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -293,19 +293,25 @@ CKey CBitcoinSecret::GetKey() return ret; } -bool CBitcoinSecret::IsValid() const +bool CBitcoinSecret::IsValid(bool bParmitOldPrefix) const { bool fExpectedFormat = vchData.size() == 32 || (vchData.size() == 33 && vchData[32] == 1); bool fCorrectVersion = vchVersion == Params().Base58Prefix(CChainParams::SECRET_KEY); + if(bParmitOldPrefix && !fCorrectVersion) + { + std::vector oldPrefix; + oldPrefix.push_back(0xb2); + fCorrectVersion = vchVersion == oldPrefix; + } return fExpectedFormat && fCorrectVersion; } -bool CBitcoinSecret::SetString(const char* pszSecret) +bool CBitcoinSecret::SetString(const char* pszSecret, bool bParmitOldPrefix) { - return CBase58Data::SetString(pszSecret) && IsValid(); + return CBase58Data::SetString(pszSecret) && IsValid(bParmitOldPrefix); } -bool CBitcoinSecret::SetString(const std::string& strSecret) +bool CBitcoinSecret::SetString(const std::string& strSecret, bool bParmitOldPrefix) { - return SetString(strSecret.c_str()); + return SetString(strSecret.c_str(), bParmitOldPrefix); } diff --git a/src/base58.h b/src/base58.h index c4cb96814cc..237aa1930e2 100644 --- a/src/base58.h +++ b/src/base58.h @@ -126,9 +126,9 @@ class CBitcoinSecret : public CBase58Data public: void SetKey(const CKey& vchSecret); CKey GetKey(); - bool IsValid() const; - bool SetString(const char* pszSecret); - bool SetString(const std::string& strSecret); + bool IsValid(bool bParmitOldPrefix = false) const; + bool SetString(const char* pszSecret, bool bParmitOldPrefix = false); + bool SetString(const std::string& strSecret, bool bParmitOldPrefix = false); CBitcoinSecret(const CKey& vchSecret) { SetKey(vchSecret); } CBitcoinSecret() {} diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp index 7fb51e7e517..eec586884e8 100644 --- a/src/rpcdump.cpp +++ b/src/rpcdump.cpp @@ -104,7 +104,7 @@ Value importprivkey(const Array& params, bool fHelp) fRescan = params[2].get_bool(); CBitcoinSecret vchSecret; - bool fGood = vchSecret.SetString(strSecret); + bool fGood = vchSecret.SetString(strSecret, true); if (!fGood) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key encoding");