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_TX_STATUS_FACTORY_HPP
7 : #define IROHA_TX_STATUS_FACTORY_HPP
8 :
9 : #include <memory>
10 :
11 : #include "interfaces/transaction_responses/tx_response.hpp"
12 :
13 : namespace shared_model {
14 : namespace interface {
15 :
16 : /**
17 : * Factory which creates transaction status response
18 : */
19 : class TxStatusFactory {
20 : public:
21 : /// return type of all generative methods
22 : using FactoryReturnType = std::unique_ptr<TransactionResponse>;
23 :
24 : /// type of transaction hash
25 : using TransactionHashType =
26 : const TransactionResponse::TransactionHashType &;
27 :
28 : /// type of failed command name attached to \class TransactionResponse
29 : /// instance
30 : using StatelessErrorOrFailedCommandNameType =
31 : const TransactionResponse::StatelessErrorOrFailedCommandNameType &;
32 :
33 : /// type of failed command index attached to \class TransactionResponse
34 : /// instance
35 : using FailedCommandIndexType =
36 : TransactionResponse::FailedCommandIndexType;
37 :
38 : /// type of error code, with which command failed, attached to \class
39 : /// TransactionResponse instance
40 : using ErrorCodeType = TransactionResponse::ErrorCodeType;
41 :
42 : /// represents transaction error, empty or not
43 : struct TransactionError {
44 : std::decay_t<StatelessErrorOrFailedCommandNameType> cmd_name_;
45 : FailedCommandIndexType cmd_index_;
46 : ErrorCodeType error_code_;
47 :
48 : TransactionError() : cmd_name_{}, cmd_index_{}, error_code_{} {}
49 : TransactionError(StatelessErrorOrFailedCommandNameType cmd_name,
50 : FailedCommandIndexType cmd_index,
51 : ErrorCodeType error_code)
52 123 : : cmd_name_{cmd_name},
53 123 : cmd_index_{cmd_index},
54 123 : error_code_{error_code} {}
55 : };
56 :
57 : // ------------------------| Stateless statuses |-------------------------
58 :
59 : /// Creates stateless failed transaction status
60 : virtual FactoryReturnType makeStatelessFail(
61 : TransactionHashType,
62 : TransactionError tx_error = TransactionError()) = 0;
63 :
64 : /// Creates stateless valid transaction status
65 : virtual FactoryReturnType makeStatelessValid(
66 : TransactionHashType,
67 : TransactionError tx_error = TransactionError()) = 0;
68 :
69 : // ------------------------| Stateful statuses |--------------------------
70 :
71 : /// Creates stateful failed transaction status
72 : virtual FactoryReturnType makeStatefulFail(
73 : TransactionHashType,
74 : TransactionError tx_error = TransactionError()) = 0;
75 : /// Creates stateful valid transaction status
76 : virtual FactoryReturnType makeStatefulValid(
77 : TransactionHashType,
78 : TransactionError tx_error = TransactionError()) = 0;
79 :
80 : // --------------------------| Final statuses |---------------------------
81 :
82 : /// Creates committed transaction status
83 : virtual FactoryReturnType makeCommitted(
84 : TransactionHashType,
85 : TransactionError tx_error = TransactionError()) = 0;
86 :
87 : /// Creates rejected transaction status
88 : virtual FactoryReturnType makeRejected(
89 : TransactionHashType,
90 : TransactionError tx_error = TransactionError()) = 0;
91 :
92 : // --------------------------| Rest statuses |----------------------------
93 :
94 : /// Creates transaction expired status
95 : virtual FactoryReturnType makeMstExpired(
96 : TransactionHashType,
97 : TransactionError tx_error = TransactionError()) = 0;
98 :
99 : /// Creates transaction pending status
100 : virtual FactoryReturnType makeMstPending(
101 : TransactionHashType,
102 : TransactionError tx_error = TransactionError()) = 0;
103 :
104 : /// Creates transaction is not received status
105 : virtual FactoryReturnType makeNotReceived(
106 : TransactionHashType,
107 : TransactionError tx_error = TransactionError()) = 0;
108 :
109 : /// Creates status which shows that enough signatures were collected
110 : virtual FactoryReturnType makeEnoughSignaturesCollected(
111 : TransactionHashType,
112 : TransactionError tx_error = TransactionError()) = 0;
113 :
114 : virtual ~TxStatusFactory() = default;
115 : };
116 : } // namespace interface
117 : } // namespace shared_model
118 :
119 : #endif // IROHA_TX_STATUS_FACTORY_HPP
|