diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -673,8 +673,8 @@ throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file"); } - Optional tip_height = locked_chain->getHeight(); - nTimeBegin = tip_height ? locked_chain->getBlockTime(*tip_height) : 0; + CHECK_NONFATAL(pwallet->chain().findBlock( + pwallet->GetLastBlockHash(), FoundBlock().time(nTimeBegin))); int64_t nFilesize = std::max(1, file.tellg()); file.seekg(0, file.beg); @@ -944,16 +944,13 @@ // produce output file << strprintf("# Wallet dump created by Bitcoin %s\n", CLIENT_BUILD); file << strprintf("# * Created on %s\n", FormatISO8601DateTime(GetTime())); - const Optional tip_height = locked_chain->getHeight(); file << strprintf("# * Best block at time of backup was %i (%s),\n", - tip_height.value_or(-1), - tip_height - ? locked_chain->getBlockHash(*tip_height).ToString() - : "(missing block hash)"); - file << strprintf("# mined on %s\n", - tip_height ? FormatISO8601DateTime( - locked_chain->getBlockTime(*tip_height)) - : "(missing block time)"); + pwallet->GetLastBlockHeight(), + pwallet->GetLastBlockHash().ToString()); + int64_t block_time = 0; + CHECK_NONFATAL(pwallet->chain().findBlock(pwallet->GetLastBlockHash(), + FoundBlock().time(block_time))); + file << strprintf("# mined on %s\n", FormatISO8601DateTime(block_time)); file << "\n"; // add the base58check encoded extended master if the wallet uses HD diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -257,6 +257,8 @@ request.params.setArray(); request.params.push_back(backup_file); AddWallet(wallet); + wallet->SetLastBlockProcessed(::ChainActive().Height(), + ::ChainActive().Tip()->GetBlockHash()); ::dumpwallet(GetConfig(), request); RemoveWallet(wallet); } @@ -267,16 +269,18 @@ std::shared_ptr wallet = std::make_shared(Params(), chain.get(), WalletLocation(), WalletDatabase::CreateDummy()); + LOCK(wallet->cs_wallet); wallet->SetupLegacyScriptPubKeyMan(); JSONRPCRequest request; request.params.setArray(); request.params.push_back(backup_file); AddWallet(wallet); + wallet->SetLastBlockProcessed(::ChainActive().Height(), + ::ChainActive().Tip()->GetBlockHash()); ::importwallet(GetConfig(), request); RemoveWallet(wallet); - LOCK(wallet->cs_wallet); BOOST_CHECK_EQUAL(wallet->mapWallet.size(), 3U); BOOST_CHECK_EQUAL(m_coinbase_txns.size(), 103U); for (size_t i = 0; i < m_coinbase_txns.size(); ++i) {