Browse Source

Merge #9740: Add friendly output to dumpwallet

164019d Add dumpwallet output test (aideca)
9f82134 Add friendly output to dumpwallet refs #9564 (aideca)

Tree-SHA512: 913fcf18d42eebe34173f1f2519973494b1ad2d86d125ff4bf566d6c64aa501c02f8831e6f44812cd87a46916f61c6f510146af406865b31856d8336c173569f
0.15
Wladimir J. van der Laan 8 years ago
parent
commit
9fec4da0be
No known key found for this signature in database
GPG Key ID: 1E4AED62986CD25D
  1. 16
      src/wallet/rpcdump.cpp
  2. 5
      test/functional/wallet-dump.py

16
src/wallet/rpcdump.cpp

@ -603,7 +603,11 @@ UniValue dumpwallet(const JSONRPCRequest& request)
"dumpwallet \"filename\"\n" "dumpwallet \"filename\"\n"
"\nDumps all wallet keys in a human-readable format.\n" "\nDumps all wallet keys in a human-readable format.\n"
"\nArguments:\n" "\nArguments:\n"
"1. \"filename\" (string, required) The filename\n" "1. \"filename\" (string, required) The filename with path (either absolute or relative to bitcoind)\n"
"\nResult:\n"
"{ (json object)\n"
" \"filename\" : { (string) The filename with full absolute path\n"
"}\n"
"\nExamples:\n" "\nExamples:\n"
+ HelpExampleCli("dumpwallet", "\"test\"") + HelpExampleCli("dumpwallet", "\"test\"")
+ HelpExampleRpc("dumpwallet", "\"test\"") + HelpExampleRpc("dumpwallet", "\"test\"")
@ -614,7 +618,9 @@ UniValue dumpwallet(const JSONRPCRequest& request)
EnsureWalletIsUnlocked(pwallet); EnsureWalletIsUnlocked(pwallet);
std::ofstream file; std::ofstream file;
file.open(request.params[0].get_str().c_str()); boost::filesystem::path filepath = request.params[0].get_str();
filepath = boost::filesystem::absolute(filepath);
file.open(filepath.string().c_str());
if (!file.is_open()) if (!file.is_open())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file");
@ -679,7 +685,11 @@ UniValue dumpwallet(const JSONRPCRequest& request)
file << "\n"; file << "\n";
file << "# End of dump\n"; file << "# End of dump\n";
file.close(); file.close();
return NullUniValue;
UniValue reply(UniValue::VOBJ);
reply.push_back(Pair("filename", filepath.string()));
return reply;
} }

5
test/functional/wallet-dump.py

@ -4,6 +4,8 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test the dumpwallet RPC.""" """Test the dumpwallet RPC."""
import os
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (assert_equal, bitcoind_processes) from test_framework.util import (assert_equal, bitcoind_processes)
@ -82,7 +84,8 @@ class WalletDumpTest(BitcoinTestFramework):
self.nodes[0].keypoolrefill() self.nodes[0].keypoolrefill()
# dump unencrypted wallet # dump unencrypted wallet
self.nodes[0].dumpwallet(tmpdir + "/node0/wallet.unencrypted.dump") result = self.nodes[0].dumpwallet(tmpdir + "/node0/wallet.unencrypted.dump")
assert_equal(result['filename'], os.path.abspath(tmpdir + "/node0/wallet.unencrypted.dump"))
found_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc = \ found_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc = \
read_dump(tmpdir + "/node0/wallet.unencrypted.dump", addrs, None) read_dump(tmpdir + "/node0/wallet.unencrypted.dump", addrs, None)

Loading…
Cancel
Save