@@ -724,9 +724,8 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
724
724
725
725
UniValue dumpwallet (const JSONRPCRequest& request)
726
726
{
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 )) {
730
729
return NullUniValue;
731
730
}
732
731
@@ -750,12 +749,17 @@ UniValue dumpwallet(const JSONRPCRequest& request)
750
749
},
751
750
}.Check (request);
752
751
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 ();
754
758
755
759
auto locked_chain = pwallet->chain ().lock ();
756
760
LOCK2 (pwallet->cs_wallet , spk_man.cs_KeyStore );
757
761
758
- EnsureWalletIsUnlocked (pwallet );
762
+ EnsureWalletIsUnlocked (&wallet );
759
763
760
764
fs::path filepath = request.params [0 ].get_str ();
761
765
filepath = fs::absolute (filepath);
@@ -791,9 +795,9 @@ UniValue dumpwallet(const JSONRPCRequest& request)
791
795
// produce output
792
796
file << strprintf (" # Wallet dump created by Bitcoin %s\n " , CLIENT_BUILD);
793
797
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 ());
795
799
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)));
797
801
file << strprintf (" # mined on %s\n " , FormatISO8601DateTime (block_time));
798
802
file << " \n " ;
799
803
@@ -817,8 +821,8 @@ UniValue dumpwallet(const JSONRPCRequest& request)
817
821
CKey key;
818
822
if (spk_man.GetKey (keyid, key)) {
819
823
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);
822
826
} else if (keyid == seed_id) {
823
827
file << " hdseed=1" ;
824
828
} else if (mapKeyPool.count (keyid)) {
0 commit comments