From 700b7ceb73c0d41e2c411a62af13d2247d89183b Mon Sep 17 00:00:00 2001 From: PaulieD Date: Tue, 19 Jun 2018 00:52:32 -0500 Subject: [PATCH] RPC: dumphdinfo should throw an error when wallet isn't HD (#2134) * Throws an RPCError `RPC_WALLET_ERROR` when the command `dumphdinfo` is called and the wallet is not HD * Refactor based on @Udjin's post --- src/wallet/rpcdump.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 0eebe5c9a7..70dd72c07f 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -705,26 +705,23 @@ UniValue dumphdinfo(const JSONRPCRequest& request) EnsureWalletIsUnlocked(); - // add the base58check encoded extended master if the wallet uses HD CHDChain hdChainCurrent; - if (pwalletMain->GetHDChain(hdChainCurrent)) - { - if (!pwalletMain->GetDecryptedHDChain(hdChainCurrent)) - throw JSONRPCError(RPC_INTERNAL_ERROR, "Cannot decrypt HD seed"); + if (!pwalletMain->GetHDChain(hdChainCurrent)) + throw JSONRPCError(RPC_WALLET_ERROR, "This wallet is not a HD wallet."); - SecureString ssMnemonic; - SecureString ssMnemonicPassphrase; - hdChainCurrent.GetMnemonic(ssMnemonic, ssMnemonicPassphrase); + if (!pwalletMain->GetDecryptedHDChain(hdChainCurrent)) + throw JSONRPCError(RPC_INTERNAL_ERROR, "Cannot decrypt HD seed"); - UniValue obj(UniValue::VOBJ); - obj.push_back(Pair("hdseed", HexStr(hdChainCurrent.GetSeed()))); - obj.push_back(Pair("mnemonic", ssMnemonic.c_str())); - obj.push_back(Pair("mnemonicpassphrase", ssMnemonicPassphrase.c_str())); + SecureString ssMnemonic; + SecureString ssMnemonicPassphrase; + hdChainCurrent.GetMnemonic(ssMnemonic, ssMnemonicPassphrase); - return obj; - } + UniValue obj(UniValue::VOBJ); + obj.push_back(Pair("hdseed", HexStr(hdChainCurrent.GetSeed()))); + obj.push_back(Pair("mnemonic", ssMnemonic.c_str())); + obj.push_back(Pair("mnemonicpassphrase", ssMnemonicPassphrase.c_str())); - return NullUniValue; + return obj; } UniValue dumpwallet(const JSONRPCRequest& request)