Skip to content

Commit

Permalink
validateaddress rpc for spark addresses (#1407)
Browse files Browse the repository at this point in the history
  • Loading branch information
levonpetrosyan93 authored Jan 28, 2024
1 parent 285a58e commit 53c0526
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,26 @@ UniValue validateaddress(const JSONRPCRequest& request)
CBitcoinAddress address(request.params[0].get_str());
bool isValid = address.IsValid();

bool isvalidSpark = false;
const spark::Params* params = spark::Params::get_default();
unsigned char network = spark::GetNetworkType();
spark::Address sAddress(params);

if (!isValid) {
try {
unsigned char coinNetwork = sAddress.decode(request.params[0].get_str());
isvalidSpark = coinNetwork == network;
} catch (const std::exception &) {
isvalidSpark = false;
}
}

UniValue ret(UniValue::VOBJ);
ret.push_back(Pair("isvalid", isValid));
if (isvalidSpark)
ret.push_back(Pair("isvalidSpark", isvalidSpark));
else
ret.push_back(Pair("isvalid", isValid));

if (isValid)
{
CTxDestination dest = address.Get();
Expand Down Expand Up @@ -245,6 +263,18 @@ UniValue validateaddress(const JSONRPCRequest& request)
}
}
}
#endif
} else if (isvalidSpark) {
std::string currentAddress = sAddress.encode(network);
ret.push_back(Pair("address", currentAddress));

#ifdef ENABLE_WALLET
bool ismine = false;
if (pwallet && pwallet->sparkWallet) {
ismine = pwallet->sparkWallet->isAddressMine(currentAddress);
}

ret.push_back(Pair("ismine", ismine));
#endif
}
return ret;
Expand Down

0 comments on commit 53c0526

Please sign in to comment.