Skip to content

Commit

Permalink
put const cast into transaction bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyShi22 committed Sep 11, 2023
1 parent aa84fde commit 6f35e48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions bcos-txpool/bcos-txpool/txpool/utilities/TransactionBucket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<bcos::protocol::Transaction::Ptr&>(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<bcos::protocol::Transaction::Ptr&>(_transaction)),
m_iterator()
{}

friend bool operator==(
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion bcos-utilities/bcos-utilities/BucketMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Bucket : public std::enable_shared_from_this<Bucket<KeyType, ValueType, Ma
void setValue(typename MapType::iterator it) { m_it = it; };

const KeyType& key() { return m_it->first; }
ValueType& value() { return const_cast<ValueType&>(m_it->second); }
ValueType& value() { return m_it->second; }

private:
typename Bucket::Ptr m_bucket;
Expand Down

0 comments on commit 6f35e48

Please sign in to comment.