Commit 0831b47e authored by Ashot's avatar Ashot
Browse files

Added CLI converter for old Crown addresses

Showing with 51 additions and 17 deletions
+51 -17
......@@ -287,10 +287,20 @@ CTxDestination CBitcoinAddress::Get() const
return CNoDestination();
}
bool CBitcoinAddress::IsDeprecated() const
bool CBitcoinAddress::IsDeprecated(const std::string& address)
{
// If the old constructed address is valid then it's deprecated
return CBitcoinAddress(this->ToString(), CChainParams::DEPRECATED_ADDRESS_TYPE).IsValid();
return CBitcoinAddress(address, CChainParams::DEPRECATED_ADDRESS_TYPE).IsValid();
}
std::string CBitcoinAddress::ConvertToNew(const std::string& address)
{
if (IsDeprecated(address))
{
CTxDestination key = CBitcoinAddress(address, CChainParams::DEPRECATED_ADDRESS_TYPE).Get();
return CBitcoinAddress(key).ToString();
}
return address;
}
bool CBitcoinAddress::GetKeyID(CKeyID& keyID) const
......
......@@ -133,7 +133,8 @@ public:
CBitcoinAddress(const char* pszAddress) { SetString(pszAddress); }
CTxDestination Get() const;
bool IsDeprecated() const;
static bool IsDeprecated(const std::string& address);
static std::string ConvertToNew(const std::string& address);
bool GetKeyID(CKeyID &keyID) const;
bool IsScript() const;
};
......
......@@ -85,13 +85,8 @@ public:
if (ser_action.ForRead())
{
if (CBitcoinAddress(sAddress).IsDeprecated())
{
// If the address is deprecated then get the new address
// based on destination of old one
CTxDestination key = CBitcoinAddress(sAddress, CChainParams::DEPRECATED_ADDRESS_TYPE).Get();
sAddress = CBitcoinAddress(key).ToString();
}
// If the address is not depricated then the value won't be converted
sAddress = CBitcoinAddress::ConvertToNew(sAddress);
address = QString::fromStdString(sAddress);
label = QString::fromStdString(sLabel);
......
......@@ -353,6 +353,7 @@ static const CRPCCommand vRPCCommands[] =
{ "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true, false, true },
{ "wallet", "getbalance", &getbalance, false, false, true },
{ "wallet", "getnewaddress", &getnewaddress, true, false, true },
{ "wallet", "oldtonewaddress", &oldtonewaddress, true, false, true },
{ "wallet", "getrawchangeaddress", &getrawchangeaddress, true, false, true },
{ "wallet", "getreceivedbyaccount", &getreceivedbyaccount, false, false, true },
{ "wallet", "getreceivedbyaddress", &getreceivedbyaddress, false, false, true },
......
......@@ -165,6 +165,7 @@ extern json_spirit::Value estimatefee(const json_spirit::Array& params, bool fHe
extern json_spirit::Value estimatepriority(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getnewaddress(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
extern json_spirit::Value oldtonewaddress(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
extern json_spirit::Value getaccountaddress(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getrawchangeaddress(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value setaccount(const json_spirit::Array& params, bool fHelp);
......
......@@ -79,6 +79,37 @@ string AccountFromValue(const Value& value)
return strAccount;
}
Value oldtonewaddress(const json_spirit::Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"oldtonewaddress( \"oldaddress\" )\n"
"\nConverts given old Crown address to a new one.\n"
"\nArguments:\n"
"1. \"oldaddress\" (string, required) The old Crown address.\n"
"\nResult:\n"
"\"crownaddress\" (string) The new crown address\n"
"\nExamples:\n"
+ HelpExampleCli("oldtonewaddress", "15bj2HB2UbmjEZgXyEW4M8MhUL5TXGCN8L")
+ HelpExampleCli("oldtonewaddress", "\"15bj2HB2UbmjEZgXyEW4M8MhUL5TXGCN8L\"")
+ HelpExampleRpc("oldtonewaddress", "\"15bj2HB2UbmjEZgXyEW4M8MhUL5TXGCN8L\"")
);
std::string strAddress = params[0].get_str();
if (CBitcoinAddress(strAddress).IsValid())
{
throw runtime_error("Error: Given address is a valid new Crown address and cannot be converted.");
}
std::string newAddress = CBitcoinAddress::ConvertToNew(strAddress);
if (newAddress.compare(strAddress) == 0)
{
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to convert. Invalid Crown address.");
}
return newAddress;
}
Value getnewaddress(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
......
......@@ -586,13 +586,8 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
ssKey >> strKey;
ssValue >> strValue;
if (CBitcoinAddress(strAddress).IsDeprecated())
{
// If the address is deprecated then get the new address
// based on destination of old one
CTxDestination key = CBitcoinAddress(strAddress, CChainParams::DEPRECATED_ADDRESS_TYPE).Get();
strAddress = CBitcoinAddress(key).ToString();
}
// If the address is not depricated then the value won't be converted
strAddress = CBitcoinAddress::ConvertToNew(strAddress);
if (!pwallet->LoadDestData(CBitcoinAddress(strAddress).Get(), strKey, strValue))
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment