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
This commit is contained in:
parent
6410705211
commit
700b7ceb73
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user