- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.2k
 
RPC: dumphdinfo should throw an error when wallet isn't HD #2134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RPC: dumphdinfo should throw an error when wallet isn't HD #2134
Conversation
…s called and the wallet is not HD
| 
           @paulied Thanks for the PR! Not sure if we want to throw an error here, hence the  Nonetheless, can you please ensure the syntax is clean by properly aligning the closing brace for your   | 
    
…s called and the wallet is not HD
| 
           IMO throwing an error is perfectly fine here and fixes #2069 , though  This whole thing needs refactoring actually, smth like: diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp
index 0eebe5c9a..70dd72c07 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) | 
    
| 
           I agree that some feedback would be better than none. Personally I would prefer if we could move to JSONRPC 2.0, avoiding   | 
    
| 
           Based on @UdjinM6's comment, the code has been refactored.  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
btw, diff without spaces https://github.com/dashpay/dash/pull/2134/files?w=1
) * Throws an RPCError `RPC_WALLET_ERROR` when the command `dumphdinfo` is called and the wallet is not HD * Refactor based on @Udjin's post
) * Throws an RPCError `RPC_WALLET_ERROR` when the command `dumphdinfo` is called and the wallet is not HD * Refactor based on @Udjin's post
Throws an RPCError
RPC_WALLET_ERROR(text = "This wallet is not a HD (Hierarchical Deterministic) wallet.") when the commanddumphdinfois called and the wallet is not HD.This is in response to #2069