forked from hyperledger-iroha/iroha-dco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transaction sequence interface (hyperledger-iroha#1469)
* Transaction sequence interface Signed-off-by: kamilsa <[email protected]>
- Loading branch information
Showing
10 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
shared_model/interfaces/common_objects/transaction_sequence_common.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef IROHA_TRANSACTION_SEQUENCE_COMMON_HPP | ||
#define IROHA_TRANSACTION_SEQUENCE_COMMON_HPP | ||
|
||
#include <boost/range/any_range.hpp> | ||
|
||
namespace shared_model { | ||
namespace interface { | ||
|
||
class Transaction; | ||
|
||
namespace types { | ||
|
||
using TransactionsForwardCollectionType = | ||
boost::any_range<Transaction, | ||
boost::forward_traversal_tag, | ||
const Transaction &>; | ||
} | ||
} // namespace interface | ||
} // namespace shared_model | ||
|
||
#endif // IROHA_TRANSACTION_SEQUENCE_COMMON_HPP |
32 changes: 32 additions & 0 deletions
32
shared_model/interfaces/iroha_internal/transaction_sequence.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "interfaces/iroha_internal/transaction_sequence.hpp" | ||
|
||
namespace shared_model { | ||
namespace interface { | ||
|
||
iroha::expected::Result<TransactionSequence, std::string> | ||
TransactionSequence::createTransactionSequence( | ||
const types::TransactionsForwardCollectionType &transactions, | ||
const validation::TransactionsCollectionValidator &validator) { | ||
auto answer = validator.validate(transactions); | ||
if (answer.hasErrors()) { | ||
return iroha::expected::makeError(answer.reason()); | ||
} | ||
return iroha::expected::makeValue(TransactionSequence(transactions)); | ||
} | ||
|
||
types::TransactionsForwardCollectionType | ||
TransactionSequence::transactions() { | ||
return transactions_; | ||
} | ||
|
||
TransactionSequence::TransactionSequence( | ||
const types::TransactionsForwardCollectionType &transactions) | ||
: transactions_(transactions) {} | ||
|
||
} // namespace interface | ||
} // namespace shared_model |
52 changes: 52 additions & 0 deletions
52
shared_model/interfaces/iroha_internal/transaction_sequence.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef IROHA_TRANSACTION_SEQUENCE_HPP | ||
#define IROHA_TRANSACTION_SEQUENCE_HPP | ||
|
||
#include "common/result.hpp" | ||
#include "interfaces/common_objects/transaction_sequence_common.hpp" | ||
#include "validators/transactions_collection/transactions_collection_validator.hpp" | ||
|
||
namespace shared_model { | ||
namespace interface { | ||
|
||
/** | ||
* Transaction sequence is the collection of transactions where: | ||
* 1. All transactions from the same batch are place contiguously | ||
* 2. All batches are full (no transaction from the batch can be outside | ||
* sequence) | ||
*/ | ||
class TransactionSequence { | ||
public: | ||
/** | ||
* Creator of transaction sequence | ||
* @param transactions collection of transactions | ||
* @param validator validator of the collections | ||
* @return Result containing transaction sequence if validation successful | ||
* and string message containing error otherwise | ||
*/ | ||
static iroha::expected::Result<TransactionSequence, std::string> | ||
createTransactionSequence( | ||
const types::TransactionsForwardCollectionType &transactions, | ||
const validation::TransactionsCollectionValidator &validator); | ||
|
||
/** | ||
* Get transactions collection | ||
* @return transactions collection | ||
*/ | ||
types::TransactionsForwardCollectionType transactions(); | ||
|
||
private: | ||
explicit TransactionSequence( | ||
const types::TransactionsForwardCollectionType &transactions); | ||
|
||
types::TransactionsForwardCollectionType transactions_; | ||
}; | ||
|
||
} // namespace interface | ||
} // namespace shared_model | ||
|
||
#endif // IROHA_TRANSACTION_SEQUENCE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
shared_model/validators/transactions_collection/signed_transactions_collection_validator.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "validators/transactions_collection/signed_transactions_collection_validator.hpp" | ||
|
||
namespace shared_model { | ||
namespace validation { | ||
|
||
Answer SignedTransactionsCollectionValidator::validate( | ||
const interface::types::TransactionsForwardCollectionType &transactions) | ||
const { | ||
return Answer(); | ||
} | ||
|
||
} // namespace validation | ||
} // namespace shared_model |
29 changes: 29 additions & 0 deletions
29
shared_model/validators/transactions_collection/signed_transactions_collection_validator.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef IROHA_SIGNED_TRANSACTIONS_COLLECTION_VALIDATOR_HPP | ||
#define IROHA_SIGNED_TRANSACTIONS_COLLECTION_VALIDATOR_HPP | ||
|
||
#include "validators/transactions_collection/transactions_collection_validator.hpp" | ||
|
||
namespace shared_model { | ||
namespace validation { | ||
|
||
/** | ||
* Signed transactions collection validator does not allow to any | ||
* transaction from the collection to be unsigned. Batch logic should be | ||
* checked | ||
*/ | ||
class SignedTransactionsCollectionValidator | ||
: public TransactionsCollectionValidator { | ||
public: | ||
Answer validate(const interface::types::TransactionsForwardCollectionType | ||
&transactions) const override; | ||
}; | ||
|
||
} // namespace validation | ||
} // namespace shared_model | ||
|
||
#endif // IROHA_SIGNED_TRANSACTIONS_COLLECTION_VALIDATOR_HPP |
34 changes: 34 additions & 0 deletions
34
shared_model/validators/transactions_collection/transactions_collection_validator.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef IROHA_TRANSACTION_SEQUENCE_VALIDATOR_HPP | ||
#define IROHA_TRANSACTION_SEQUENCE_VALIDATOR_HPP | ||
|
||
#include "interfaces/common_objects/transaction_sequence_common.hpp" | ||
#include "validators/answer.hpp" | ||
|
||
namespace shared_model { | ||
namespace validation { | ||
|
||
/** | ||
* Validator of transaction's collection, this is not fair implementation | ||
* now, it always returns empty answer | ||
*/ | ||
class TransactionsCollectionValidator { | ||
public: | ||
/** | ||
* Validates collection of transactions | ||
* @param transactions collection of transactions | ||
* @return Answer containing errors if any | ||
*/ | ||
virtual Answer validate( | ||
const interface::types::TransactionsForwardCollectionType | ||
&transactions) const = 0; | ||
}; | ||
|
||
} // namespace validation | ||
} // namespace shared_model | ||
|
||
#endif // IROHA_TRANSACTION_SEQUENCE_VALIDATOR_HPP |
18 changes: 18 additions & 0 deletions
18
...d_model/validators/transactions_collection/unsigned_transactions_collection_validator.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "validators/transactions_collection/unsigned_transactions_collection_validator.hpp" | ||
|
||
namespace shared_model { | ||
namespace validation { | ||
|
||
Answer UnsignedTransactionsCollectionValidator::validate( | ||
const interface::types::TransactionsForwardCollectionType &transactions) | ||
const { | ||
return Answer(); | ||
} | ||
|
||
} // namespace validation | ||
} // namespace shared_model |
28 changes: 28 additions & 0 deletions
28
...d_model/validators/transactions_collection/unsigned_transactions_collection_validator.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef IROHA_UNSIGNED_TRANSACTIONS_SEQUENCE_VALIDATOR_HPP | ||
#define IROHA_UNSIGNED_TRANSACTIONS_SEQUENCE_VALIDATOR_HPP | ||
|
||
#include "validators/transactions_collection/transactions_collection_validator.hpp" | ||
|
||
namespace shared_model { | ||
namespace validation { | ||
|
||
/** | ||
* Unsigned transactions collection validator allows to some transaction | ||
* from the collection to be unsigned. Batch logic should be checked | ||
*/ | ||
class UnsignedTransactionsCollectionValidator | ||
: public TransactionsCollectionValidator { | ||
public: | ||
Answer validate(const interface::types::TransactionsForwardCollectionType | ||
&transactions) const override; | ||
}; | ||
|
||
} // namespace validation | ||
} // namespace shared_model | ||
|
||
#endif // IROHA_UNSIGNED_TRANSACTIONS_SEQUENCE_VALIDATOR_HPP |