From 53c05264ca4e959e312b6a3274e12a4ab15c4e36 Mon Sep 17 00:00:00 2001 From: levonpetrosyan93 <45027856+levonpetrosyan93@users.noreply.github.com> Date: Sun, 28 Jan 2024 23:25:26 +0400 Subject: [PATCH] validateaddress rpc for spark addresses (#1407) --- src/rpc/misc.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index c7142df306..d1b0eeef45 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -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(); @@ -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;