diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -59,9 +60,9 @@ WalletTxStatus MakeWalletTxStatus(interfaces::Chain::Lock &locked_chain, const CWalletTx &wtx) { WalletTxStatus result; - result.block_height = - locked_chain.getBlockHeight(wtx.m_confirm.hashBlock) - .get_value_or(std::numeric_limits::max()); + result.block_height = wtx.m_confirm.block_height > 0 + ? wtx.m_confirm.block_height + : std::numeric_limits::max(); result.blocks_to_maturity = wtx.GetBlocksToMaturity(); result.depth_in_main_chain = wtx.GetDepthInMainChain(); result.time_received = wtx.nTimeReceived; @@ -303,13 +304,10 @@ if (mi == m_wallet->mapWallet.end()) { return false; } - if (Optional height = locked_chain->getHeight()) { - num_blocks = *height; - block_time = locked_chain->getBlockTime(*height); - } else { - num_blocks = -1; - block_time = -1; - } + num_blocks = m_wallet->GetLastBlockHeight(); + block_time = -1; + CHECK_NONFATAL(m_wallet->chain().findBlock( + m_wallet->GetLastBlockHash(), FoundBlock().time(block_time))); tx_status = MakeWalletTxStatus(*locked_chain, mi->second); return true; } @@ -362,8 +360,8 @@ if (!locked_wallet) { return false; } + num_blocks = m_wallet->GetLastBlockHeight(); balances = getBalances(); - num_blocks = locked_chain->getHeight().value_or(-1); return true; } Amount getBalance() override { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1452,6 +1452,11 @@ assert(m_last_block_processed_height >= 0); return m_last_block_processed_height; }; + BlockHash GetLastBlockHash() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { + AssertLockHeld(cs_wallet); + assert(m_last_block_processed_height >= 0); + return m_last_block_processed; + } /** Set last block processed height, currently only use in unit test */ void SetLastBlockProcessed(int block_height, BlockHash block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) {