From b855592d835bf4b3fb1263b88d4f96669a1722b1 Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Tue, 9 Jul 2019 20:07:39 -0400 Subject: [wallet] Move getHeight from Chain::Lock interface to simple Chain Instead of calling getHeight, we rely on CWallet::m_last_block processed_height where it's possible. --- src/interfaces/chain.cpp | 18 +++++++++--------- src/interfaces/chain.h | 10 +++++----- src/interfaces/wallet.cpp | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src/interfaces') diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp index 0e7641ae32..b891cf2ee5 100644 --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -55,15 +55,6 @@ bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock { - Optional getHeight() override - { - LockAssertion lock(::cs_main); - int height = ::ChainActive().Height(); - if (height >= 0) { - return height; - } - return nullopt; - } Optional getBlockHeight(const uint256& hash) override { LockAssertion lock(::cs_main); @@ -234,6 +225,15 @@ public: std::unique_ptr result = std::move(lock); // Temporary to avoid CWG 1579 return result; } + Optional getHeight() override + { + LOCK(::cs_main); + int height = ::ChainActive().Height(); + if (height >= 0) { + return height; + } + return nullopt; + } bool findBlock(const uint256& hash, const FoundBlock& block) override { WAIT_LOCK(cs_main, lock); diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index fb77c81cdc..03635fd74f 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -87,11 +87,6 @@ public: public: virtual ~Lock() {} - //! Get current chain height, not including genesis block (returns 0 if - //! chain only contains genesis block, nullopt if chain does not contain - //! any blocks). - virtual Optional getHeight() = 0; - //! Get block height above genesis block. Returns 0 for genesis block, //! 1 for following block, and so on. Returns nullopt for a block not //! included in the current chain. @@ -135,6 +130,11 @@ public: //! unlocked when the returned interface is freed. virtual std::unique_ptr lock(bool try_lock = false) = 0; + //! Get current chain height, not including genesis block (returns 0 if + //! chain only contains genesis block, nullopt if chain does not contain + //! any blocks) + virtual Optional getHeight() = 0; + //! Return whether node has the block and optionally return block metadata //! or contents. virtual bool findBlock(const uint256& hash, const FoundBlock& block={}) = 0; diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index 152917ac60..0c31ae0c81 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -228,7 +228,7 @@ public: auto locked_chain = m_wallet->chain().lock(); LOCK(m_wallet->cs_wallet); CTransactionRef tx; - if (!m_wallet->CreateTransaction(*locked_chain, recipients, tx, fee, change_pos, + if (!m_wallet->CreateTransaction(recipients, tx, fee, change_pos, fail_reason, coin_control, sign)) { return {}; } @@ -335,7 +335,7 @@ public: LOCK(m_wallet->cs_wallet); auto mi = m_wallet->mapWallet.find(txid); if (mi != m_wallet->mapWallet.end()) { - num_blocks = locked_chain->getHeight().get_value_or(-1); + num_blocks = m_wallet->GetLastBlockHeight(); in_mempool = mi->second.InMempool(); order_form = mi->second.vOrderForm; tx_status = MakeWalletTxStatus(*locked_chain, mi->second); -- cgit v1.2.3