Line data Source code
1 : /**
2 : * Copyright Soramitsu Co., Ltd. All Rights Reserved.
3 : * SPDX-License-Identifier: Apache-2.0
4 : */
5 :
6 : #ifndef IROHA_TRANSACTION_BATCH_HELPERS_HPP
7 : #define IROHA_TRANSACTION_BATCH_HELPERS_HPP
8 :
9 : #include <sstream>
10 :
11 : #include "cryptography/hash.hpp"
12 :
13 : namespace shared_model {
14 : namespace interface {
15 :
16 : /**
17 : * Provides a method that calculates reduced batch hash
18 : */
19 : class TransactionBatchHelpers {
20 : public:
21 : /**
22 : * Get the concatenation of reduced hashes as a single hash
23 : * That kind of hash does not respect batch type
24 : * @tparam Collection type of const ref iterator
25 : * @param reduced_hashes
26 : * @return concatenated reduced hashes
27 : */
28 : template <typename Collection>
29 : static types::HashType calculateReducedBatchHash(
30 : const Collection &reduced_hashes) {
31 4268 : std::stringstream concatenated_hash;
32 8875 : for (const auto &hash : reduced_hashes) {
33 4581 : concatenated_hash << hash.hex();
34 4268 : }
35 4285 : return types::HashType::fromHexString(concatenated_hash.str());
36 4285 : }
37 : };
38 : } // namespace interface
39 : } // namespace shared_model
40 :
41 : #endif // IROHA_TRANSACTION_BATCH_HELPERS_HPP
|