Skip to content

Commit

Permalink
Fixed a bug: permit the old prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
monacoinproject committed Sep 20, 2015
1 parent 4489db9 commit 3dc2e6a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/base58.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char> 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);
}
6 changes: 3 additions & 3 deletions src/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
2 changes: 1 addition & 1 deletion src/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit 3dc2e6a

Please sign in to comment.