Skip to content

Commit

Permalink
Transaction sequence interface (hyperledger-iroha#1469)
Browse files Browse the repository at this point in the history
* Transaction sequence interface

Signed-off-by: kamilsa <[email protected]>
  • Loading branch information
kamilsa authored Jun 20, 2018
1 parent cea1db8 commit 0514681
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 0 deletions.
1 change: 1 addition & 0 deletions shared_model/interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ add_library(shared_model_interfaces
queries/impl/blocks_query.cpp
queries/impl/query_payload_meta.cpp
iroha_internal/block_variant.cpp
iroha_internal/transaction_sequence.cpp
)

target_link_libraries(shared_model_interfaces
Expand Down
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 shared_model/interfaces/iroha_internal/transaction_sequence.cpp
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 shared_model/interfaces/iroha_internal/transaction_sequence.hpp
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
2 changes: 2 additions & 0 deletions shared_model/validators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
add_library(shared_model_stateless_validation
default_validator.cpp
field_validator.cpp
transactions_collection/signed_transactions_collection_validator.cpp
transactions_collection/unsigned_transactions_collection_validator.cpp
)

target_link_libraries(shared_model_stateless_validation
Expand Down
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
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
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
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
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

0 comments on commit 0514681

Please sign in to comment.