diff --git a/irohad/ametsuchi/ametsuchi.hpp b/irohad/ametsuchi/ametsuchi.hpp index 9504762aec..b16b6c67b4 100644 --- a/irohad/ametsuchi/ametsuchi.hpp +++ b/irohad/ametsuchi/ametsuchi.hpp @@ -18,8 +18,10 @@ #ifndef IROHA_AMETSUCHI_H #define IROHA_AMETSUCHI_H -#include -#include +#include +#include +#include +#include namespace iroha { @@ -29,19 +31,17 @@ namespace iroha { * Storage class, which allows queries on current committed state, and * creation of state which can be mutated with blocks and transactions */ - class Ametsuchi : public QueryApi { + class Ametsuchi : public StateQuery, public BlockQuery { public: /** * Creates a mutable state from the current state * @return Created mutable state */ - virtual std::unique_ptr createMutableState() = 0; + virtual TemporaryWSV* createTemporaryWSV() = 0; - /** - * Permanently applies the mutable state to storage - * @param state Mutated state to be applied - */ - virtual void applyMutableState(MutableState&& state) = 0; + virtual MutableStorage* createMutableStorage() = 0; + + virtual void commit(MutableStorage* mutableStorage) = 0; }; } // namespace ametsuchi diff --git a/irohad/ametsuchi/block_query.hpp b/irohad/ametsuchi/block_query.hpp new file mode 100644 index 0000000000..39b5f44328 --- /dev/null +++ b/irohad/ametsuchi/block_query.hpp @@ -0,0 +1,56 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IROHA_BLOCK_QUERY_HPP +#define IROHA_BLOCK_QUERY_HPP + +namespace iroha { + + namespace ametsuchi { + + class BlockQuery { + public: + /** + * Get all transactions of an account. + * @param pub_key - account's first public key + * @return observable of DAO Transaction + */ + virtual rxcpp::observable + get_account_transactions(iroha::crypto::ed25519::pubkey_t pub_key) = 0; + + /** + * Get all transactions with a certain asset + * @param asset_full_name - full name of an asset, i.e. name#domain + * @return observable of DAO Transaction + */ + virtual rxcpp::observable get_asset_transactions( + std::string asset_full_name) = 0; + + /** + * Get all transactions of a certain wallet + * @param wallet_id - unique wallet + * @return observable of DAO Transaction + */ + virtual rxcpp::observable + get_wallet_transactions(std::string wallet_id) = 0; + }; + + } // namespace ametsuchi + +} // namespace iroha + +#endif // IROHA_BLOCK_QUERY_HPP diff --git a/irohad/ametsuchi/command_executor.hpp b/irohad/ametsuchi/command_executor.hpp new file mode 100644 index 0000000000..bf3e2465ee --- /dev/null +++ b/irohad/ametsuchi/command_executor.hpp @@ -0,0 +1,33 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IROHA_COMMANDEXECUTOR_HPP +#define IROHA_COMMANDEXECUTOR_HPP + +namespace iroha { + + namespace ametsuchi { + + class CommandExecutor { + virtual void execute(dao::Command command) = 0; + }; + + } // namespace ametsuchi + +}// namespace iroha + +#endif //IROHA_COMMANDEXECUTOR_HPP diff --git a/irohad/ametsuchi/mutable_storage.hpp b/irohad/ametsuchi/mutable_storage.hpp new file mode 100644 index 0000000000..c354e82282 --- /dev/null +++ b/irohad/ametsuchi/mutable_storage.hpp @@ -0,0 +1,36 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IROHA_MUTABLESTORAGE_HPP +#define IROHA_MUTABLESTORAGE_HPP + +#include + +namespace iroha { + namespace ametsuchi { + + class MutableStorage : public WSVQuery, public BlockQuery { + virtual bool apply( + dao::Block block, + std::function + function) = 0; + }; + + } // namespace ametsuchi +} // namespace iroha + +#endif // IROHA_MUTABLESTORAGE_HPP diff --git a/irohad/ametsuchi/mutable_state.hpp b/irohad/ametsuchi/temporary_wsv.hpp similarity index 56% rename from irohad/ametsuchi/mutable_state.hpp rename to irohad/ametsuchi/temporary_wsv.hpp index 0869593fe6..b121b653c1 100644 --- a/irohad/ametsuchi/mutable_state.hpp +++ b/irohad/ametsuchi/temporary_wsv.hpp @@ -15,10 +15,11 @@ * limitations under the License. */ -#ifndef IROHA_MUTABLESTATE_HPP -#define IROHA_MUTABLESTATE_HPP +#ifndef IROHA_TEMPORARYWSV_HPP +#define IROHA_TEMPORARYWSV_HPP -#include +#include +#include #include #include @@ -27,37 +28,11 @@ namespace iroha { namespace ametsuchi { /** - * Reflects a temporary state of storage + * Reflects a temporary state of world state view * Allows queries on the temporary state */ - class MutableState : public QueryApi { + class TemporaryWSV : public WSVQuery { public: - /** - * Specifies the error during apply process in TransactionContext - */ - class StorageException; - - /** - * The context used in @see apply transaction method - */ - class TransactionContext { - /** - * Attempts to apply a command to current mutable state - * Throws exception in case of internal error - * @tparam T Command type - * @param command Command to be applied - * @throws StorageException - */ - template - void try_apply(T command); - }; - - /** - * Applies a block to current mutable state - * @param block Block to be applied - */ - virtual void apply(dao::Block block) = 0; - /** * Applies a transaction to current mutable state * using logic specified in function @@ -67,7 +42,7 @@ namespace iroha { */ virtual bool apply( dao::Transaction transaction, - std::function + std::function function) = 0; }; @@ -75,4 +50,4 @@ namespace iroha { } // namespace iroha -#endif // IROHA_MUTABLESTATE_HPP +#endif // IROHA_TEMPORARYWSV_HPP diff --git a/irohad/ametsuchi/query_api.hpp b/irohad/ametsuchi/wsv_query.hpp similarity index 50% rename from irohad/ametsuchi/query_api.hpp rename to irohad/ametsuchi/wsv_query.hpp index f2c6c3b464..c1876b58b8 100644 --- a/irohad/ametsuchi/query_api.hpp +++ b/irohad/ametsuchi/wsv_query.hpp @@ -1,21 +1,22 @@ -/* -Copyright Soramitsu Co., Ltd. 2016 All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef IROHA_QUERY_API_HPP -#define IROHA_QUERY_API_HPP +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IROHA_WSVQUERY_HPP +#define IROHA_WSVQUERY_HPP #include #include @@ -27,7 +28,7 @@ namespace iroha { namespace ametsuchi { - class QueryApi { + class WSVQuery { public: /** * Get account by it's first public key. @@ -73,34 +74,10 @@ namespace iroha { */ virtual std::vector get_domain_assets( std::string domain_full_name) = 0; - - /** - * Get all transactions of an account. - * @param pub_key - account's first public key - * @return observable of DAO Transaction - */ - virtual rxcpp::observable - get_account_transactions(iroha::crypto::ed25519::pubkey_t pub_key) = 0; - - /** - * Get all transactions with a certain asset - * @param asset_full_name - full name of an asset, i.e. name#domain - * @return observable of DAO Transaction - */ - virtual rxcpp::observable get_asset_transactions( - std::string asset_full_name) = 0; - - /** - * Get all transactions of a certain wallet - * @param wallet_id - unique wallet - * @return observable of DAO Transaction - */ - virtual rxcpp::observable - get_wallet_transactions(std::string wallet_id) = 0; }; } // namespace ametsuchi } // namespace iroha -#endif // IROHA_QUERY_API_HPP +#endif // IROHA_WSVQUERY_HPP