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();
|
EnsureWalletIsUnlocked();
|
||||||
|
|
||||||
// add the base58check encoded extended master if the wallet uses HD
|
|
||||||
CHDChain hdChainCurrent;
|
CHDChain hdChainCurrent;
|
||||||
if (pwalletMain->GetHDChain(hdChainCurrent))
|
if (!pwalletMain->GetHDChain(hdChainCurrent))
|
||||||
{
|
throw JSONRPCError(RPC_WALLET_ERROR, "This wallet is not a HD wallet.");
|
||||||
if (!pwalletMain->GetDecryptedHDChain(hdChainCurrent))
|
|
||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Cannot decrypt HD seed");
|
|
||||||
|
|
||||||
SecureString ssMnemonic;
|
if (!pwalletMain->GetDecryptedHDChain(hdChainCurrent))
|
||||||
SecureString ssMnemonicPassphrase;
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "Cannot decrypt HD seed");
|
||||||
hdChainCurrent.GetMnemonic(ssMnemonic, ssMnemonicPassphrase);
|
|
||||||
|
|
||||||
UniValue obj(UniValue::VOBJ);
|
SecureString ssMnemonic;
|
||||||
obj.push_back(Pair("hdseed", HexStr(hdChainCurrent.GetSeed())));
|
SecureString ssMnemonicPassphrase;
|
||||||
obj.push_back(Pair("mnemonic", ssMnemonic.c_str()));
|
hdChainCurrent.GetMnemonic(ssMnemonic, ssMnemonicPassphrase);
|
||||||
obj.push_back(Pair("mnemonicpassphrase", ssMnemonicPassphrase.c_str()));
|
|
||||||
|
|
||||||
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)
|
UniValue dumpwallet(const JSONRPCRequest& request)
|
||||||
|
Loading…
Reference in New Issue
Block a user