Browse Source

z_validateviewingkey has a dedicated branch, it needs more work

pull/135/head
Jonathan "Duke" Leto 6 years ago
parent
commit
fef0578e45
  1. 1
      src/rpcserver.cpp
  2. 1
      src/rpcserver.h
  3. 23
      src/test/rpc_wallet_tests.cpp
  4. 53
      src/wallet/rpcdump.cpp

1
src/rpcserver.cpp

@ -406,7 +406,6 @@ static const CRPCCommand vRPCCommands[] =
{ "wallet", "z_listaddresses", &z_listaddresses, true },
{ "wallet", "z_exportkey", &z_exportkey, true },
{ "wallet", "z_importkey", &z_importkey, true },
{ "wallet", "z_validateviewingkey", &z_validateviewingkey, true },
{ "wallet", "z_exportviewingkey", &z_exportviewingkey, true },
{ "wallet", "z_importviewingkey", &z_importviewingkey, true },
{ "wallet", "z_exportwallet", &z_exportwallet, true },

1
src/rpcserver.h

@ -291,7 +291,6 @@ extern UniValue getblocksubsidy(const UniValue& params, bool fHelp);
extern UniValue z_exportkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
extern UniValue z_importkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
extern UniValue z_validateviewingkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
extern UniValue z_exportviewingkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
extern UniValue z_importviewingkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
extern UniValue z_getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp

23
src/test/rpc_wallet_tests.cpp

@ -314,29 +314,6 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_getbalance)
BOOST_CHECK_THROW(CallRPC("z_listreceivedbyaddress tnRZ8bPq2pff3xBWhTJhNkVUkm2uhzksDeW5PvEa7aFKGT9Qi3YgTALZfjaY4jU3HLVKBtHdSXxoPoLA3naMPcHBcY88FcF 1"), runtime_error);
}
/**
* This test covers RPC command z_validateviewingkey
*/
BOOST_AUTO_TEST_CASE(rpc_wallet_z_validateviewingkey)
{
SelectParams(CBaseChainParams::MAIN);
LOCK2(cs_main, pwalletMain->cs_wallet);
UniValue retValue;
// Check number of args
BOOST_CHECK_THROW(CallRPC("z_validateviewingkey"), runtime_error);
BOOST_CHECK_THROW(CallRPC("z_validateviewingkey toomany args"), runtime_error);
BOOST_CHECK_NO_THROW(retValue = CallRPC("z_validateviewingkey VKstuff"));
UniValue resultObj = retValue.get_obj();
bool b = find_value(resultObj, "isvalid").get_bool();
BOOST_CHECK_EQUAL(b, false);
b = find_value(resultObj, "ismine").get_bool();
BOOST_CHECK_EQUAL(b, false);
}
/**
* This test covers RPC command z_validateaddress
*/

53
src/wallet/rpcdump.cpp

@ -649,59 +649,6 @@ UniValue z_importkey(const UniValue& params, bool fHelp)
return NullUniValue;
}
UniValue z_validateviewingkey(const UniValue& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() != 1)
throw runtime_error(
"z_validateviewingkey \"vkey\"\n"
"\nReturn information about the given Zcash viewing key.\n"
"\nArguments:\n"
"1. \"vkey\" (string, required) The viewing key (see z_exportviewingkey)\n"
"\nExamples:\n"
"\nValidate a viewing key\n"
+ HelpExampleCli("z_validateviewingkey", "\"vkey\"") +
"\nAs a JSON-RPC call\n"
+ HelpExampleRpc("z_validateviewingkey", "\"vkey\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
EnsureWalletIsUnlocked();
UniValue ret(UniValue::VOBJ);
string strVKey = params[0].get_str();
auto viewingkey = DecodeViewingKey(strVKey);
if (!IsValidViewingKey(viewingkey)) {
ret.push_back(Pair("isvalid", false));
return ret;
}
if( boost::get<libzcash::SproutViewingKey>(&viewingkey) != nullptr ) {
auto vkey = boost::get<libzcash::SproutViewingKey>(viewingkey);
auto addr = vkey.address();
bool isValid = IsValidViewingKey(viewingkey);
bool isMine = pwalletMain->HaveSpendingKey(addr);
bool isImported = pwalletMain->HaveViewingKey(addr) && !isMine;
ret.push_back(Pair("isvalid", isValid));
if (isValid) {
ret.push_back(Pair("address", EncodePaymentAddress(addr)));
ret.push_back(Pair("viewingkey", strVKey));
ret.push_back(Pair("ismine", isMine));
ret.push_back(Pair("isimported", isImported));
}
} else {
ret.push_back(Pair("isvalid", false));
}
return ret;
}
UniValue z_importviewingkey(const UniValue& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))

Loading…
Cancel
Save