From 6f35e487414f38b65e7b3f8dffd013f4234f9125 Mon Sep 17 00:00:00 2001 From: JimmyShi22 <417711026@qq.com> Date: Mon, 11 Sep 2023 14:30:06 +0800 Subject: [PATCH] put const cast into transaction bucket --- .../bcos-txpool/txpool/utilities/TransactionBucket.h | 12 +++++++++--- bcos-utilities/bcos-utilities/BucketMap.h | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bcos-txpool/bcos-txpool/txpool/utilities/TransactionBucket.h b/bcos-txpool/bcos-txpool/txpool/utilities/TransactionBucket.h index 2c5b050e89..d38014d5a4 100644 --- a/bcos-txpool/bcos-txpool/txpool/utilities/TransactionBucket.h +++ b/bcos-txpool/bcos-txpool/txpool/utilities/TransactionBucket.h @@ -45,12 +45,18 @@ class MultiIndexTxContainer { public: IteratorImpl(typename Container::nth_index<0>::type::iterator& it) - : first(it->txHash), second(it->transaction), m_iterator(it) + : first(it->txHash), + // we assume that _transaction is not indexed so we can cast it to non-const + second(const_cast(it->transaction)), + m_iterator(it) {} IteratorImpl(const bcos::crypto::HashType& _first, const bcos::protocol::Transaction::Ptr& _transaction) - : first(_first), second(_transaction), m_iterator() + : first(_first), + // we assume that _transaction is not indexed so we can cast it to non-const + second(const_cast(_transaction)), + m_iterator() {} friend bool operator==( @@ -68,7 +74,7 @@ class MultiIndexTxContainer Container::nth_index<0>::type::iterator getIterator() const { return m_iterator; } const bcos::crypto::HashType& first; - const bcos::protocol::Transaction::Ptr& second; + bcos::protocol::Transaction::Ptr& second; private: typename Container::nth_index<0>::type::iterator m_iterator; diff --git a/bcos-utilities/bcos-utilities/BucketMap.h b/bcos-utilities/bcos-utilities/BucketMap.h index 1101f1ab65..ae6078622e 100644 --- a/bcos-utilities/bcos-utilities/BucketMap.h +++ b/bcos-utilities/bcos-utilities/BucketMap.h @@ -63,7 +63,7 @@ class Bucket : public std::enable_shared_from_thisfirst; } - ValueType& value() { return const_cast(m_it->second); } + ValueType& value() { return m_it->second; } private: typename Bucket::Ptr m_bucket;