Rename methods to avoid using prefix of _ underscore which is reserved.

Added logging of explicit exception rather than a catch all.
Removed redundant spending key check.
Updated user facing help message.
This commit is contained in:
Simon 2016-08-24 11:55:26 -07:00
parent 4b2e557181
commit 3bff998b38
1 changed files with 13 additions and 14 deletions

View File

@ -27,8 +27,8 @@ using namespace std;
void EnsureWalletIsUnlocked(); void EnsureWalletIsUnlocked();
bool EnsureWalletIsAvailable(bool avoidException); bool EnsureWalletIsAvailable(bool avoidException);
Value _dumpwallet(const Array& params, bool fHelp, bool fDumpZKeys); Value dumpwallet_impl(const Array& params, bool fHelp, bool fDumpZKeys);
Value _importwallet(const Array& params, bool fHelp, bool fImportZKeys); Value importwallet_impl(const Array& params, bool fHelp, bool fImportZKeys);
std::string static EncodeDumpTime(int64_t nTime) { std::string static EncodeDumpTime(int64_t nTime) {
@ -241,7 +241,7 @@ Value z_importwallet(const Array& params, bool fHelp)
+ HelpExampleRpc("z_importwallet", "\"test\"") + HelpExampleRpc("z_importwallet", "\"test\"")
); );
return _importwallet(params, fHelp, true); return importwallet_impl(params, fHelp, true);
} }
Value importwallet(const Array& params, bool fHelp) Value importwallet(const Array& params, bool fHelp)
@ -252,7 +252,7 @@ Value importwallet(const Array& params, bool fHelp)
if (fHelp || params.size() != 1) if (fHelp || params.size() != 1)
throw runtime_error( throw runtime_error(
"importwallet \"filename\"\n" "importwallet \"filename\"\n"
"\nImports keys from a wallet dump file (see dumpwallet).\n" "\nImports taddr keys from a wallet dump file (see dumpwallet).\n"
"\nArguments:\n" "\nArguments:\n"
"1. \"filename\" (string, required) The wallet file\n" "1. \"filename\" (string, required) The wallet file\n"
"\nExamples:\n" "\nExamples:\n"
@ -264,10 +264,10 @@ Value importwallet(const Array& params, bool fHelp)
+ HelpExampleRpc("importwallet", "\"test\"") + HelpExampleRpc("importwallet", "\"test\"")
); );
return _importwallet(params, fHelp, false); return importwallet_impl(params, fHelp, false);
} }
Value _importwallet(const Array& params, bool fHelp, bool fImportZKeys) Value importwallet_impl(const Array& params, bool fHelp, bool fImportZKeys)
{ {
LOCK2(cs_main, pwalletMain->cs_wallet); LOCK2(cs_main, pwalletMain->cs_wallet);
@ -319,7 +319,8 @@ Value _importwallet(const Array& params, bool fHelp, bool fImportZKeys)
pwalletMain->mapZKeyMetadata[addr].nCreateTime = nTime; pwalletMain->mapZKeyMetadata[addr].nCreateTime = nTime;
continue; continue;
} }
catch (...) { catch (const std::runtime_error &e) {
LogPrintf("Importing detected an error: %s\n", e.what());
// Not a valid spending key, so carry on and see if it's a Bitcoin style address. // Not a valid spending key, so carry on and see if it's a Bitcoin style address.
} }
} }
@ -435,7 +436,7 @@ Value z_exportwallet(const Array& params, bool fHelp)
+ HelpExampleRpc("z_exportwallet", "\"test\"") + HelpExampleRpc("z_exportwallet", "\"test\"")
); );
return _dumpwallet(params, fHelp, true); return dumpwallet_impl(params, fHelp, true);
} }
Value dumpwallet(const Array& params, bool fHelp) Value dumpwallet(const Array& params, bool fHelp)
@ -446,7 +447,7 @@ Value dumpwallet(const Array& params, bool fHelp)
if (fHelp || params.size() != 1) if (fHelp || params.size() != 1)
throw runtime_error( throw runtime_error(
"dumpwallet \"filename\"\n" "dumpwallet \"filename\"\n"
"\nDumps all wallet keys in a human-readable format.\n" "\nDumps taddr wallet keys in a human-readable format.\n"
"\nArguments:\n" "\nArguments:\n"
"1. \"filename\" (string, required) The filename\n" "1. \"filename\" (string, required) The filename\n"
"\nExamples:\n" "\nExamples:\n"
@ -454,10 +455,10 @@ Value dumpwallet(const Array& params, bool fHelp)
+ HelpExampleRpc("dumpwallet", "\"test\"") + HelpExampleRpc("dumpwallet", "\"test\"")
); );
return _dumpwallet(params, fHelp, false); return dumpwallet_impl(params, fHelp, false);
} }
Value _dumpwallet(const Array& params, bool fHelp, bool fDumpZKeys) Value dumpwallet_impl(const Array& params, bool fHelp, bool fDumpZKeys)
{ {
LOCK2(cs_main, pwalletMain->cs_wallet); LOCK2(cs_main, pwalletMain->cs_wallet);
@ -482,7 +483,7 @@ Value _dumpwallet(const Array& params, bool fHelp, bool fDumpZKeys)
std::sort(vKeyBirth.begin(), vKeyBirth.end()); std::sort(vKeyBirth.begin(), vKeyBirth.end());
// produce output // produce output
file << strprintf("# Wallet dump created by Bitcoin %s (%s)\n", CLIENT_BUILD, CLIENT_DATE); file << strprintf("# Wallet dump created by Zcash %s (%s)\n", CLIENT_BUILD, CLIENT_DATE);
file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime())); file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime()));
file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString()); file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString());
file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime())); file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime()));
@ -614,8 +615,6 @@ Value z_exportkey(const Array& params, bool fHelp)
CZCPaymentAddress address(strAddress); CZCPaymentAddress address(strAddress);
auto addr = address.Get(); auto addr = address.Get();
if (!pwalletMain->HaveSpendingKey(addr))
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet does not hold private zkey for this zaddr");
libzcash::SpendingKey k; libzcash::SpendingKey k;
if (!pwalletMain->GetSpendingKey(addr, k)) if (!pwalletMain->GetSpendingKey(addr, k))