@@ -724,9 +724,8 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
724724
725725UniValue dumpwallet (const JSONRPCRequest& request)
726726{
727- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
728- const CWallet* const pwallet = wallet.get ();
729- if (!EnsureWalletIsAvailable (pwallet, request.fHelp )) {
727+ std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (request);
728+ if (!EnsureWalletIsAvailable (pwallet.get (), request.fHelp )) {
730729 return NullUniValue;
731730 }
732731
@@ -750,12 +749,17 @@ UniValue dumpwallet(const JSONRPCRequest& request)
750749 },
751750 }.Check (request);
752751
753- LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan (*wallet);
752+ CWallet& wallet = *pwallet;
753+ LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan (wallet);
754+
755+ // Make sure the results are valid at least up to the most recent block
756+ // the user could have gotten from another RPC command prior to now
757+ wallet.BlockUntilSyncedToCurrentChain ();
754758
755759 auto locked_chain = pwallet->chain ().lock ();
756760 LOCK2 (pwallet->cs_wallet , spk_man.cs_KeyStore );
757761
758- EnsureWalletIsUnlocked (pwallet );
762+ EnsureWalletIsUnlocked (&wallet );
759763
760764 fs::path filepath = request.params [0 ].get_str ();
761765 filepath = fs::absolute (filepath);
@@ -791,9 +795,9 @@ UniValue dumpwallet(const JSONRPCRequest& request)
791795 // produce output
792796 file << strprintf (" # Wallet dump created by Bitcoin %s\n " , CLIENT_BUILD);
793797 file << strprintf (" # * Created on %s\n " , FormatISO8601DateTime (GetTime ()));
794- file << strprintf (" # * Best block at time of backup was %i (%s),\n " , pwallet-> GetLastBlockHeight (), pwallet-> GetLastBlockHash ().ToString ());
798+ file << strprintf (" # * Best block at time of backup was %i (%s),\n " , wallet. GetLastBlockHeight (), wallet. GetLastBlockHash ().ToString ());
795799 int64_t block_time = 0 ;
796- CHECK_NONFATAL (pwallet-> chain ().findBlock (pwallet-> GetLastBlockHash (), FoundBlock ().time (block_time)));
800+ CHECK_NONFATAL (wallet. chain ().findBlock (wallet. GetLastBlockHash (), FoundBlock ().time (block_time)));
797801 file << strprintf (" # mined on %s\n " , FormatISO8601DateTime (block_time));
798802 file << " \n " ;
799803
@@ -817,8 +821,8 @@ UniValue dumpwallet(const JSONRPCRequest& request)
817821 CKey key;
818822 if (spk_man.GetKey (keyid, key)) {
819823 file << strprintf (" %s %s " , EncodeSecret (key), strTime);
820- if (GetWalletAddressesForKey (&spk_man, pwallet , keyid, strAddr, strLabel)) {
821- file << strprintf (" label=%s" , strLabel);
824+ if (GetWalletAddressesForKey (&spk_man, &wallet , keyid, strAddr, strLabel)) {
825+ file << strprintf (" label=%s" , strLabel);
822826 } else if (keyid == seed_id) {
823827 file << " hdseed=1" ;
824828 } else if (mapKeyPool.count (keyid)) {
0 commit comments