mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
parent
da26b9bff8
commit
97709a2bfa
@ -1950,8 +1950,13 @@ static UniValue walletpassphrase(const JSONRPCRequest& request)
|
|||||||
throw JSONRPCError(RPC_WALLET_ALREADY_UNLOCKED, "Error: Wallet is already fully unlocked.");
|
throw JSONRPCError(RPC_WALLET_ALREADY_UNLOCKED, "Error: Wallet is already fully unlocked.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pwallet->Unlock(strWalletPass, fForMixingOnly))
|
if (strWalletPass.empty()) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "passphrase can not be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pwallet->Unlock(strWalletPass, fForMixingOnly)) {
|
||||||
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
|
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
|
||||||
|
}
|
||||||
|
|
||||||
pwallet->TopUpKeyPool();
|
pwallet->TopUpKeyPool();
|
||||||
|
|
||||||
@ -2011,10 +2016,9 @@ static UniValue walletpassphrasechange(const JSONRPCRequest& request)
|
|||||||
strNewWalletPass.reserve(100);
|
strNewWalletPass.reserve(100);
|
||||||
strNewWalletPass = request.params[1].get_str().c_str();
|
strNewWalletPass = request.params[1].get_str().c_str();
|
||||||
|
|
||||||
if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1)
|
if (strOldWalletPass.empty() || strNewWalletPass.empty()) {
|
||||||
throw std::runtime_error(
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "passphrase can not be empty");
|
||||||
"walletpassphrasechange <oldpassphrase> <newpassphrase>\n"
|
}
|
||||||
"Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.");
|
|
||||||
|
|
||||||
if (!pwallet->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) {
|
if (!pwallet->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) {
|
||||||
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
|
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
|
||||||
@ -2109,10 +2113,9 @@ static UniValue encryptwallet(const JSONRPCRequest& request)
|
|||||||
strWalletPass.reserve(100);
|
strWalletPass.reserve(100);
|
||||||
strWalletPass = request.params[0].get_str().c_str();
|
strWalletPass = request.params[0].get_str().c_str();
|
||||||
|
|
||||||
if (strWalletPass.length() < 1)
|
if (strWalletPass.empty()) {
|
||||||
throw std::runtime_error(
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "passphrase can not be empty");
|
||||||
"encryptwallet <passphrase>\n"
|
}
|
||||||
"Encrypts the wallet with <passphrase>.");
|
|
||||||
|
|
||||||
if (!pwallet->EncryptWallet(strWalletPass)) {
|
if (!pwallet->EncryptWallet(strWalletPass)) {
|
||||||
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet.");
|
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet.");
|
||||||
|
@ -31,12 +31,18 @@ class WalletEncryptionTest(BitcoinTestFramework):
|
|||||||
privkey = self.nodes[0].dumpprivkey(address)
|
privkey = self.nodes[0].dumpprivkey(address)
|
||||||
assert_equal(privkey[:1], "c")
|
assert_equal(privkey[:1], "c")
|
||||||
assert_equal(len(privkey), 52)
|
assert_equal(len(privkey), 52)
|
||||||
|
assert_raises_rpc_error(-15, "Error: running with an unencrypted wallet, but walletpassphrase was called", self.nodes[0].walletpassphrase, 'ff', 1)
|
||||||
|
assert_raises_rpc_error(-15, "Error: running with an unencrypted wallet, but walletpassphrasechange was called.", self.nodes[0].walletpassphrasechange, 'ff', 'ff')
|
||||||
|
|
||||||
# Encrypt the wallet
|
# Encrypt the wallet
|
||||||
|
assert_raises_rpc_error(-8, "passphrase can not be empty", self.nodes[0].encryptwallet, '')
|
||||||
self.nodes[0].encryptwallet(passphrase)
|
self.nodes[0].encryptwallet(passphrase)
|
||||||
|
|
||||||
# Test that the wallet is encrypted
|
# Test that the wallet is encrypted
|
||||||
assert_raises_rpc_error(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].dumpprivkey, address)
|
assert_raises_rpc_error(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].dumpprivkey, address)
|
||||||
|
assert_raises_rpc_error(-15, "Error: running with an encrypted wallet, but encryptwallet was called.", self.nodes[0].encryptwallet, 'ff')
|
||||||
|
assert_raises_rpc_error(-8, "passphrase can not be empty", self.nodes[0].walletpassphrase, '', 1)
|
||||||
|
assert_raises_rpc_error(-8, "passphrase can not be empty", self.nodes[0].walletpassphrasechange, '', 'ff')
|
||||||
|
|
||||||
# Check that walletpassphrase works
|
# Check that walletpassphrase works
|
||||||
self.nodes[0].walletpassphrase(passphrase, 2)
|
self.nodes[0].walletpassphrase(passphrase, 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user