hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
pending_txs_storage_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_PENDING_TXS_STORAGE_IMPL_HPP
7 #define IROHA_PENDING_TXS_STORAGE_IMPL_HPP
8 
9 #include <list>
10 #include <set>
11 #include <shared_mutex>
12 #include <unordered_map>
13 
14 #include <rxcpp/rx.hpp>
17 
18 namespace iroha {
19 
20  class MstState;
21 
23  public:
29  using SharedState = std::shared_ptr<MstState>;
30  using SharedBatch = std::shared_ptr<TransactionBatch>;
31  using StateObservable = rxcpp::observable<SharedState>;
32  using BatchObservable = rxcpp::observable<SharedBatch>;
33 
35  BatchObservable prepared_batch,
36  BatchObservable expired_batch);
37 
39 
41  const AccountIdType &account_id) const override;
42 
43  expected::Result<Response, ErrorCode> getPendingTransactions(
46  const boost::optional<shared_model::interface::types::HashType>
47  &first_tx_hash) const override;
48 
49  private:
50  void updatedBatchesHandler(const SharedState &updated_batches);
51 
52  void removeBatch(const SharedBatch &batch);
53 
54  static std::set<AccountIdType> batchCreators(const TransactionBatch &batch);
55 
59  rxcpp::composite_subscription updated_batches_subscription_;
60  rxcpp::composite_subscription prepared_batch_subscription_;
61  rxcpp::composite_subscription expired_batch_subscription_;
62 
66  mutable std::shared_timed_mutex mutex_;
67 
82  struct AccountBatches {
83  std::list<std::shared_ptr<TransactionBatch>> batches;
84  std::
85  unordered_map<HashType, decltype(batches)::iterator, HashType::Hasher>
86  index;
87  uint64_t all_transactions_quantity{0};
88  };
89 
93  std::unordered_map<AccountIdType, AccountBatches> storage_;
94  };
95 
96 } // namespace iroha
97 
98 #endif // IROHA_PENDING_TXS_STORAGE_IMPL_HPP
Definition: hash.hpp:18
rxcpp::observable< SharedBatch > BatchObservable
Definition: pending_txs_storage_impl.hpp:32
crypto::Hash HashType
Type of hash.
Definition: types.hpp:35
shared_model::interface::types::AccountIdType AccountIdType
Definition: pending_txs_storage_impl.hpp:24
shared_model::interface::types::SharedTxsCollectionType SharedTxsCollectionType
Definition: pending_txs_storage_impl.hpp:27
Definition: block_query.hpp:14
Definition: pending_txs_storage_impl.hpp:22
std::string AccountIdType
Type of account id.
Definition: types.hpp:39
SharedTxsCollectionType getPendingTransactions(const AccountIdType &account_id) const override
Definition: pending_txs_storage_impl.cpp:38
rxcpp::observable< SharedState > StateObservable
Definition: pending_txs_storage_impl.hpp:31
Definition: transaction_batch.hpp:22
std::shared_ptr< MstState > SharedState
Definition: pending_txs_storage_impl.hpp:29
uint16_t TransactionsNumberType
Type of a number of transactions in block and query response page.
Definition: types.hpp:90
PendingTransactionStorageImpl(StateObservable updated_batches, BatchObservable prepared_batch, BatchObservable expired_batch)
Definition: pending_txs_storage_impl.cpp:13
Definition: pending_txs_storage.hpp:21
std::vector< std::shared_ptr< Transaction >> SharedTxsCollectionType
Definition: transaction_sequence_common.hpp:27
std::shared_ptr< TransactionBatch > SharedBatch
Definition: pending_txs_storage_impl.hpp:30
~PendingTransactionStorageImpl() override
Definition: pending_txs_storage_impl.cpp:31