diff --git a/irohad/ametsuchi/CMakeLists.txt b/irohad/ametsuchi/CMakeLists.txt index 0a3be8a12d..cf95605824 100644 --- a/irohad/ametsuchi/CMakeLists.txt +++ b/irohad/ametsuchi/CMakeLists.txt @@ -25,3 +25,7 @@ target_link_libraries(ametsuchi SOCI::core SOCI::postgresql ) + +target_compile_definitions(ametsuchi + PRIVATE SOCI_USE_BOOST HAVE_BOOST + ) diff --git a/irohad/ametsuchi/impl/mutable_storage_impl.cpp b/irohad/ametsuchi/impl/mutable_storage_impl.cpp index f29fa24f5e..c934aa99a7 100644 --- a/irohad/ametsuchi/impl/mutable_storage_impl.cpp +++ b/irohad/ametsuchi/impl/mutable_storage_impl.cpp @@ -23,16 +23,18 @@ #include "ametsuchi/impl/postgres_wsv_command.hpp" #include "ametsuchi/impl/postgres_wsv_query.hpp" #include "ametsuchi/wsv_command.hpp" +#include "interfaces/common_objects/common_objects_factory.hpp" #include "model/sha3_hash.hpp" namespace iroha { namespace ametsuchi { MutableStorageImpl::MutableStorageImpl( shared_model::interface::types::HashType top_hash, - std::unique_ptr sql) + std::unique_ptr sql, + std::shared_ptr factory) : top_hash_(top_hash), sql_(std::move(sql)), - wsv_(std::make_shared(*sql_)), + wsv_(std::make_shared(*sql_, factory)), executor_(std::make_shared(*sql_)), block_index_(std::make_unique(*sql_)), command_executor_(std::make_shared(wsv_, executor_)), diff --git a/irohad/ametsuchi/impl/mutable_storage_impl.hpp b/irohad/ametsuchi/impl/mutable_storage_impl.hpp index 9ca05de4eb..bed99caa4b 100644 --- a/irohad/ametsuchi/impl/mutable_storage_impl.hpp +++ b/irohad/ametsuchi/impl/mutable_storage_impl.hpp @@ -23,6 +23,7 @@ #include "ametsuchi/mutable_storage.hpp" #include "execution/command_executor.hpp" +#include "interfaces/common_objects/common_objects_factory.hpp" #include "logger/logger.hpp" namespace iroha { @@ -37,7 +38,9 @@ namespace iroha { public: MutableStorageImpl(shared_model::interface::types::HashType top_hash, - std::unique_ptr sql); + std::unique_ptr sql, + std::shared_ptr + factory); bool apply( const shared_model::interface::Block &block, diff --git a/irohad/ametsuchi/impl/postgres_block_index.hpp b/irohad/ametsuchi/impl/postgres_block_index.hpp index a2f0e20141..60a917bc83 100644 --- a/irohad/ametsuchi/impl/postgres_block_index.hpp +++ b/irohad/ametsuchi/impl/postgres_block_index.hpp @@ -21,7 +21,7 @@ #include #include "ametsuchi/impl/block_index.hpp" -#include "ametsuchi/impl/postgres_wsv_common.hpp" +#include "ametsuchi/impl/soci_utils.hpp" #include "interfaces/transaction.hpp" #include "logger/logger.hpp" diff --git a/irohad/ametsuchi/impl/postgres_block_query.hpp b/irohad/ametsuchi/impl/postgres_block_query.hpp index cf43616657..1d6e1cd6ca 100644 --- a/irohad/ametsuchi/impl/postgres_block_query.hpp +++ b/irohad/ametsuchi/impl/postgres_block_query.hpp @@ -23,7 +23,7 @@ #include "ametsuchi/block_query.hpp" #include "ametsuchi/impl/flat_file/flat_file.hpp" #include "logger/logger.hpp" -#include "postgres_wsv_common.hpp" +#include "ametsuchi/impl/soci_utils.hpp" namespace iroha { namespace ametsuchi { diff --git a/irohad/ametsuchi/impl/postgres_ordering_service_persistent_state.hpp b/irohad/ametsuchi/impl/postgres_ordering_service_persistent_state.hpp index af2013d92f..5c7dc45106 100644 --- a/irohad/ametsuchi/impl/postgres_ordering_service_persistent_state.hpp +++ b/irohad/ametsuchi/impl/postgres_ordering_service_persistent_state.hpp @@ -18,7 +18,7 @@ #ifndef IROHA_POSTGRES_ORDERING_SERVICE_PERSISTENT_STATE_HPP #define IROHA_POSTGRES_ORDERING_SERVICE_PERSISTENT_STATE_HPP -#include "ametsuchi/impl/postgres_wsv_common.hpp" +#include "ametsuchi/impl/soci_utils.hpp" #include "ametsuchi/ordering_service_persistent_state.hpp" #include "common/result.hpp" #include "logger/logger.hpp" diff --git a/irohad/ametsuchi/impl/postgres_wsv_command.cpp b/irohad/ametsuchi/impl/postgres_wsv_command.cpp index 0cbdd8c4a0..d5b77038af 100644 --- a/irohad/ametsuchi/impl/postgres_wsv_command.cpp +++ b/irohad/ametsuchi/impl/postgres_wsv_command.cpp @@ -17,8 +17,16 @@ #include "ametsuchi/impl/postgres_wsv_command.hpp" +#include + #include + #include "backend/protobuf/permissions.hpp" +#include "interfaces/common_objects/account.hpp" +#include "interfaces/common_objects/account_asset.hpp" +#include "interfaces/common_objects/asset.hpp" +#include "interfaces/common_objects/domain.hpp" +#include "interfaces/common_objects/peer.hpp" namespace iroha { namespace ametsuchi { diff --git a/irohad/ametsuchi/impl/postgres_wsv_command.hpp b/irohad/ametsuchi/impl/postgres_wsv_command.hpp index 9785cb98f1..9f1cbe7ae1 100644 --- a/irohad/ametsuchi/impl/postgres_wsv_command.hpp +++ b/irohad/ametsuchi/impl/postgres_wsv_command.hpp @@ -20,7 +20,7 @@ #include "ametsuchi/wsv_command.hpp" -#include "ametsuchi/impl/postgres_wsv_common.hpp" +#include "ametsuchi/impl/soci_utils.hpp" namespace iroha { namespace ametsuchi { diff --git a/irohad/ametsuchi/impl/postgres_wsv_common.hpp b/irohad/ametsuchi/impl/postgres_wsv_common.hpp deleted file mode 100644 index acb4080105..0000000000 --- a/irohad/ametsuchi/impl/postgres_wsv_common.hpp +++ /dev/null @@ -1,176 +0,0 @@ -/** - * Copyright Soramitsu Co., Ltd. 2018 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_POSTGRES_WSV_COMMON_HPP -#define IROHA_POSTGRES_WSV_COMMON_HPP - -#include - -#define SOCI_USE_BOOST -#define HAVE_BOOST -#include -#include - -#include "builders/default_builders.hpp" -#include "common/result.hpp" -#include "logger/logger.hpp" - -namespace iroha { - namespace ametsuchi { - - /** - * Transforms soci::rowset to vector of Ts by applying - * transform_func - * @tparam T - type to transform to - * @tparam Operator - type of transformation function, must return T - * @param result - soci::rowset which contains several rows from - * the database - * @param transform_func - function which transforms result row to T - * @return vector of target type - */ - template - std::vector transform(const soci::rowset &result, - Operator &&transform_func) noexcept { - std::vector values; - std::transform(result.begin(), - result.end(), - std::back_inserter(values), - transform_func); - - return values; - } - - /** - * Execute build function and return error in case it throws - * @tparam T - result value type - * @param f - function which returns BuilderResult - * @return whatever f returns, or error in case exception has been thrown - */ - template - static inline auto tryBuild(BuildFunc &&f) noexcept -> decltype(f()) { - try { - return f(); - } catch (std::exception &e) { - return expected::makeError(std::make_shared(e.what())); - } - } - - template - void processSoci(soci::statement &st, - soci::indicator &ind, - ParamType &row, - Function f) { - while (st.fetch()) { - switch (ind) { - case soci::i_ok: - f(row); - case soci::i_null: - case soci::i_truncated: - break; - } - } - } - - static inline shared_model::builder::BuilderResult< - shared_model::interface::Account> - makeAccount(const std::string &account_id, - const std::string &domain_id, - const shared_model::interface::types::QuorumType &quorum, - const std::string &data) noexcept { - return tryBuild([&] { - return shared_model::builder::DefaultAccountBuilder() - .accountId(account_id) - .domainId(domain_id) - .quorum(quorum) - .jsonData(data) - .build(); - }); - } - - static inline shared_model::builder::BuilderResult< - shared_model::interface::Asset> - makeAsset(const std::string &asset_id, - const std::string &domain_id, - const int32_t precision) noexcept { - return tryBuild([&] { - return shared_model::builder::DefaultAssetBuilder() - .assetId(asset_id) - .domainId(domain_id) - .precision(precision) - .build(); - }); - } - - static inline shared_model::builder::BuilderResult< - shared_model::interface::AccountAsset> - makeAccountAsset(const std::string &account_id, - const std::string &asset_id, - const std::string &amount) noexcept { - return tryBuild([&] { - return shared_model::builder::DefaultAccountAssetBuilder() - .accountId(account_id) - .assetId(asset_id) - .balance(shared_model::interface::Amount(amount)) - .build(); - }); - } - - static inline shared_model::builder::BuilderResult< - shared_model::interface::Peer> - makePeer(const soci::row &row) noexcept { - return tryBuild([&row] { - return shared_model::builder::DefaultPeerBuilder() - .pubkey(shared_model::crypto::PublicKey( - shared_model::crypto::Blob::fromHexString( - row.get(0)))) - .address(row.get(1)) - .build(); - }); - } - - static inline shared_model::builder::BuilderResult< - shared_model::interface::Domain> - makeDomain(const std::string &domain_id, const std::string &role) noexcept { - return tryBuild([&domain_id, &role] { - return shared_model::builder::DefaultDomainBuilder() - .domainId(domain_id) - .defaultRole(role) - .build(); - }); - } - - /** - * Transforms result to optional - * value -> optional - * error -> nullopt - * @tparam T type of object inside - * @param result BuilderResult - * @return optional - */ - template - static inline boost::optional> fromResult( - const shared_model::builder::BuilderResult &result) { - return result.match( - [](const expected::Value> &v) { - return boost::make_optional(v.value); - }, - [](const expected::Error> &e) - -> boost::optional> { return boost::none; }); - } - } // namespace ametsuchi -} // namespace iroha -#endif // IROHA_POSTGRES_WSV_COMMON_HPP diff --git a/irohad/ametsuchi/impl/postgres_wsv_query.cpp b/irohad/ametsuchi/impl/postgres_wsv_query.cpp index b88ed5f42c..224da8775f 100644 --- a/irohad/ametsuchi/impl/postgres_wsv_query.cpp +++ b/irohad/ametsuchi/impl/postgres_wsv_query.cpp @@ -16,7 +16,34 @@ */ #include "ametsuchi/impl/postgres_wsv_query.hpp" + +#include + +#include "ametsuchi/impl/soci_utils.hpp" #include "backend/protobuf/permissions.hpp" +#include "common/result.hpp" + +namespace { + /** + * Transforms result to optional + * value -> optional + * error -> nullopt + * @tparam T type of object inside + * @param result BuilderResult + * @return optional + */ + template + boost::optional> fromResult( + shared_model::interface::CommonObjectsFactory::FactoryResult< + std::unique_ptr> &&result) { + return result.match( + [](iroha::expected::Value> &v) { + return boost::make_optional(std::shared_ptr(std::move(v.value))); + }, + [](iroha::expected::Error) + -> boost::optional> { return boost::none; }); + } +} // namespace namespace iroha { namespace ametsuchi { @@ -36,12 +63,17 @@ namespace iroha { const std::string kAccountId = "account_id"; const std::string kDomainId = "domain_id"; - PostgresWsvQuery::PostgresWsvQuery(soci::session &sql) - : sql_(sql), log_(logger::log("PostgresWsvQuery")) {} + PostgresWsvQuery::PostgresWsvQuery( + soci::session &sql, + std::shared_ptr factory) + : sql_(sql), factory_(factory), log_(logger::log("PostgresWsvQuery")) {} - PostgresWsvQuery::PostgresWsvQuery(std::unique_ptr sql_ptr) + PostgresWsvQuery::PostgresWsvQuery( + std::unique_ptr sql_ptr, + std::shared_ptr factory) : sql_ptr_(std::move(sql_ptr)), sql_(*sql_ptr_), + factory_(factory), log_(logger::log("PostgresWsvQuery")) {} bool PostgresWsvQuery::hasAccountGrantablePermission( @@ -133,8 +165,8 @@ namespace iroha { return boost::none; } - return fromResult( - makeAccount(account_id, domain_id.get(), quorum.get(), data.get())); + return fromResult(factory_->createAccount( + account_id, domain_id.get(), quorum.get(), data.get())); } boost::optional PostgresWsvQuery::getAccountDetail( @@ -221,7 +253,8 @@ namespace iroha { return boost::none; } - return fromResult(makeAsset(asset_id, domain_id.get(), precision.get())); + return fromResult( + factory_->createAsset(asset_id, domain_id.get(), precision.get())); } boost::optional< @@ -234,8 +267,11 @@ namespace iroha { std::vector> assets; for (auto &t : st) { - fromResult(makeAccountAsset(account_id, t.get<1>(), t.get<2>())) | - [&assets](const auto &asset) { assets.push_back(asset); }; + fromResult(factory_->createAccountAsset( + account_id, + t.get<1>(), + shared_model::interface::Amount(t.get<2>()))) + | [&assets](const auto &asset) { assets.push_back(asset); }; } return boost::make_optional(assets); @@ -258,7 +294,8 @@ namespace iroha { return boost::none; } - return fromResult(makeAccountAsset(account_id, asset_id, amount.get())); + return fromResult(factory_->createAccountAsset( + account_id, asset_id, shared_model::interface::Amount(amount.get()))); } boost::optional> @@ -275,7 +312,7 @@ namespace iroha { return boost::none; } - return fromResult(makeDomain(domain_id, role.get())); + return fromResult(factory_->createDomain(domain_id, role.get())); } boost::optional>> @@ -284,16 +321,16 @@ namespace iroha { (sql_.prepare << "SELECT public_key, address FROM peer"); std::vector> peers; - auto results = transform< - shared_model::builder::BuilderResult>( - rows, makePeer); - for (auto &r : results) { - r.match( - [&](expected::Value> - &v) { peers.push_back(v.value); }, - [&](expected::Error> &e) { - log_->info(*e.error); - }); + for (auto &row : rows) { + auto address = row.get(1); + auto key = shared_model::crypto::PublicKey( + shared_model::crypto::Blob::fromHexString(row.get(0))); + + auto peer = factory_->createPeer(address, key); + peer.match( + [&](expected::Value> + &v) { peers.push_back(std::move(v.value)); }, + [&](expected::Error &e) { log_->info(e.error); }); } return peers; } diff --git a/irohad/ametsuchi/impl/postgres_wsv_query.hpp b/irohad/ametsuchi/impl/postgres_wsv_query.hpp index 3fd0c64acd..49795a08dd 100644 --- a/irohad/ametsuchi/impl/postgres_wsv_query.hpp +++ b/irohad/ametsuchi/impl/postgres_wsv_query.hpp @@ -20,14 +20,24 @@ #include "ametsuchi/wsv_query.hpp" -#include "postgres_wsv_common.hpp" +#include + +#include "interfaces/common_objects/common_objects_factory.hpp" +#include "logger/logger.hpp" namespace iroha { namespace ametsuchi { class PostgresWsvQuery : public WsvQuery { public: - explicit PostgresWsvQuery(soci::session &sql); - explicit PostgresWsvQuery(std::unique_ptr sql_ptr); + PostgresWsvQuery( + soci::session &sql, + std::shared_ptr + factory); + + PostgresWsvQuery( + std::unique_ptr sql_ptr, + std::shared_ptr + factory); boost::optional> getAccountRoles(const shared_model::interface::types::AccountIdType @@ -84,6 +94,7 @@ namespace iroha { private: std::unique_ptr sql_ptr_; soci::session &sql_; + std::shared_ptr factory_; logger::Logger log_; }; } // namespace ametsuchi diff --git a/irohad/ametsuchi/impl/soci_utils.hpp b/irohad/ametsuchi/impl/soci_utils.hpp new file mode 100644 index 0000000000..6efcab4a87 --- /dev/null +++ b/irohad/ametsuchi/impl/soci_utils.hpp @@ -0,0 +1,42 @@ +/** + * Copyright Soramitsu Co., Ltd. 2018 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_POSTGRES_WSV_COMMON_HPP +#define IROHA_POSTGRES_WSV_COMMON_HPP + +#include + +namespace iroha { + namespace ametsuchi { + template + inline void processSoci(soci::statement &st, + soci::indicator &ind, + ParamType &row, + Function f) { + while (st.fetch()) { + switch (ind) { + case soci::i_ok: + f(row); + case soci::i_null: + case soci::i_truncated: + break; + } + } + } + } // namespace ametsuchi +} // namespace iroha +#endif // IROHA_POSTGRES_WSV_COMMON_HPP diff --git a/irohad/ametsuchi/impl/storage_impl.cpp b/irohad/ametsuchi/impl/storage_impl.cpp index 7acf98dd6f..32c6fd4afa 100644 --- a/irohad/ametsuchi/impl/storage_impl.cpp +++ b/irohad/ametsuchi/impl/storage_impl.cpp @@ -43,11 +43,13 @@ namespace iroha { StorageImpl::StorageImpl(std::string block_store_dir, PostgresOptions postgres_options, std::unique_ptr block_store, - std::shared_ptr connection) + std::shared_ptr connection, + std::shared_ptr factory) : block_store_dir_(std::move(block_store_dir)), postgres_options_(std::move(postgres_options)), block_store_(std::move(block_store)), connection_(connection), + factory_(factory), log_(logger::log("StorageImpl")) {} expected::Result, std::string> @@ -55,7 +57,7 @@ namespace iroha { auto sql = std::make_unique(*connection_); return expected::makeValue>( - std::make_unique(std::move(sql))); + std::make_unique(std::move(sql), factory_)); } expected::Result, std::string> @@ -74,7 +76,8 @@ namespace iroha { [](expected::Error &) { return shared_model::interface::types::HashType(""); }), - std::move(sql))); + std::move(sql), + factory_)); } bool StorageImpl::insertBlock(const shared_model::interface::Block &block) { @@ -212,8 +215,11 @@ DROP TABLE IF EXISTS index_by_id_height_asset; }; expected::Result, std::string> - StorageImpl::create(std::string block_store_dir, - std::string postgres_options) { + StorageImpl::create( + std::string block_store_dir, + std::string postgres_options, + std::shared_ptr + factory) { boost::optional string_res = boost::none; PostgresOptions options(postgres_options); @@ -243,7 +249,8 @@ DROP TABLE IF EXISTS index_by_id_height_asset; new StorageImpl(block_store_dir, options, std::move(ctx.value.block_store), - connection.value))); + connection.value, + factory))); }, [&](expected::Error &error) { storage = error; }); }, @@ -270,7 +277,7 @@ DROP TABLE IF EXISTS index_by_id_height_asset; std::shared_ptr StorageImpl::getWsvQuery() const { auto sql = std::make_unique(*connection_); - return std::make_shared(std::move(sql)); + return std::make_shared(std::move(sql), factory_); } std::shared_ptr StorageImpl::getBlockQuery() const { diff --git a/irohad/ametsuchi/impl/storage_impl.hpp b/irohad/ametsuchi/impl/storage_impl.hpp index 32788dbbde..9a07060aed 100644 --- a/irohad/ametsuchi/impl/storage_impl.hpp +++ b/irohad/ametsuchi/impl/storage_impl.hpp @@ -20,12 +20,15 @@ #include "ametsuchi/storage.hpp" -#include -#include #include #include + +#include +#include + #include "ametsuchi/impl/postgres_options.hpp" #include "ametsuchi/key_value_storage.hpp" +#include "interfaces/common_objects/common_objects_factory.hpp" #include "logger/logger.hpp" namespace iroha { @@ -54,7 +57,10 @@ namespace iroha { public: static expected::Result, std::string> create( - std::string block_store_dir, std::string postgres_connection); + std::string block_store_dir, + std::string postgres_connection, + std::shared_ptr + factory_); expected::Result, std::string> createTemporaryWsv() override; @@ -94,7 +100,9 @@ namespace iroha { StorageImpl(std::string block_store_dir, PostgresOptions postgres_options, std::unique_ptr block_store, - std::shared_ptr connection); + std::shared_ptr connection, + std::shared_ptr + factory); /** * Folder with raw blocks @@ -112,11 +120,13 @@ namespace iroha { // Allows multiple readers and a single writer std::shared_timed_mutex rw_lock_; - logger::Logger log_; + std::shared_ptr factory_; rxcpp::subjects::subject> notifier_; + logger::Logger log_; + protected: static const std::string &init_; }; diff --git a/irohad/ametsuchi/impl/temporary_wsv_impl.cpp b/irohad/ametsuchi/impl/temporary_wsv_impl.cpp index d8cf25b059..bbc5fa72bd 100644 --- a/irohad/ametsuchi/impl/temporary_wsv_impl.cpp +++ b/irohad/ametsuchi/impl/temporary_wsv_impl.cpp @@ -22,9 +22,11 @@ namespace iroha { namespace ametsuchi { - TemporaryWsvImpl::TemporaryWsvImpl(std::unique_ptr sql) + TemporaryWsvImpl::TemporaryWsvImpl(std::unique_ptr sql, + std::shared_ptr + factory) : sql_(std::move(sql)), - wsv_(std::make_shared(*sql_)), + wsv_(std::make_shared(*sql_, factory)), executor_(std::make_shared(*sql_)), command_executor_(std::make_shared(wsv_, executor_)), command_validator_(std::make_shared(wsv_)), diff --git a/irohad/ametsuchi/impl/temporary_wsv_impl.hpp b/irohad/ametsuchi/impl/temporary_wsv_impl.hpp index 1ed34f2c3c..2d81360c85 100644 --- a/irohad/ametsuchi/impl/temporary_wsv_impl.hpp +++ b/irohad/ametsuchi/impl/temporary_wsv_impl.hpp @@ -22,6 +22,7 @@ #include "ametsuchi/temporary_wsv.hpp" #include "execution/command_executor.hpp" +#include "interfaces/common_objects/common_objects_factory.hpp" #include "logger/logger.hpp" namespace iroha { @@ -43,7 +44,9 @@ namespace iroha { bool is_released_; }; - explicit TemporaryWsvImpl(std::unique_ptr sql); + explicit TemporaryWsvImpl(std::unique_ptr sql, + std::shared_ptr + factory); expected::Result apply( const shared_model::interface::Transaction &, diff --git a/irohad/main/application.cpp b/irohad/main/application.cpp index b24fa545fc..7fffca37cc 100644 --- a/irohad/main/application.cpp +++ b/irohad/main/application.cpp @@ -18,6 +18,7 @@ #include "main/application.hpp" #include "ametsuchi/impl/postgres_ordering_service_persistent_state.hpp" #include "ametsuchi/impl/wsv_restorer_impl.hpp" +#include "backend/protobuf/common_objects/proto_common_objects_factory.hpp" #include "consensus/yac/impl/supermajority_checker_impl.hpp" #include "multi_sig_transactions/gossip_propagation_strategy.hpp" #include "multi_sig_transactions/mst_processor_impl.hpp" @@ -25,6 +26,7 @@ #include "multi_sig_transactions/mst_time_provider_impl.hpp" #include "multi_sig_transactions/storage/mst_storage_impl.hpp" #include "multi_sig_transactions/transport/mst_transport_grpc.hpp" +#include "validators/field_validator.hpp" using namespace iroha; using namespace iroha::ametsuchi; @@ -103,7 +105,10 @@ void Irohad::dropStorage() { * Initializing iroha daemon storage */ void Irohad::initStorage() { - auto storageResult = StorageImpl::create(block_store_dir_, pg_conn_); + auto factory = + std::make_shared>(); + auto storageResult = StorageImpl::create(block_store_dir_, pg_conn_, factory); storageResult.match( [&](expected::Value> &_storage) { storage = _storage.value; diff --git a/shared_model/interfaces/common_objects/common_objects_factory.hpp b/shared_model/interfaces/common_objects/common_objects_factory.hpp index 0381a71915..64161c4361 100644 --- a/shared_model/interfaces/common_objects/common_objects_factory.hpp +++ b/shared_model/interfaces/common_objects/common_objects_factory.hpp @@ -10,9 +10,12 @@ #include "common/result.hpp" #include "interfaces/common_objects/account.hpp" +#include "interfaces/common_objects/account_asset.hpp" +#include "interfaces/common_objects/asset.hpp" +#include "interfaces/common_objects/domain.hpp" #include "interfaces/common_objects/peer.hpp" +#include "interfaces/common_objects/signature.hpp" #include "interfaces/common_objects/types.hpp" -#include "interfaces/common_objects/domain.hpp" namespace shared_model { namespace interface { diff --git a/test/module/irohad/ametsuchi/CMakeLists.txt b/test/module/irohad/ametsuchi/CMakeLists.txt index 2e71ca7c54..f4045a1acb 100644 --- a/test/module/irohad/ametsuchi/CMakeLists.txt +++ b/test/module/irohad/ametsuchi/CMakeLists.txt @@ -58,6 +58,7 @@ target_link_libraries(postgres_options_test add_library(ametsuchi_fixture INTERFACE) target_link_libraries(ametsuchi_fixture INTERFACE integration_framework_config_helper + shared_model_proto_backend SOCI::core SOCI::postgresql ) diff --git a/test/module/irohad/ametsuchi/ametsuchi_fixture.hpp b/test/module/irohad/ametsuchi/ametsuchi_fixture.hpp index 6614f68333..0ee855250f 100644 --- a/test/module/irohad/ametsuchi/ametsuchi_fixture.hpp +++ b/test/module/irohad/ametsuchi/ametsuchi_fixture.hpp @@ -25,9 +25,11 @@ #include #include #include "ametsuchi/impl/storage_impl.hpp" +#include "backend/protobuf/common_objects/proto_common_objects_factory.hpp" #include "common/files.hpp" #include "framework/config_helper.hpp" #include "logger/logger.hpp" +#include "validators/field_validator.hpp" namespace iroha { namespace ametsuchi { @@ -56,7 +58,7 @@ namespace iroha { } virtual void connect() { - StorageImpl::create(block_store_path, pgopt_) + StorageImpl::create(block_store_path, pgopt_, factory) .match([&](iroha::expected::Value> &_storage) { storage = _storage.value; }, [](iroha::expected::Error &error) { @@ -78,6 +80,12 @@ namespace iroha { std::shared_ptr sql; + std::shared_ptr> + factory = + std::make_shared>(); + std::shared_ptr storage; // generate random valid dbname diff --git a/test/module/irohad/ametsuchi/ametsuchi_test.cpp b/test/module/irohad/ametsuchi/ametsuchi_test.cpp index d772265637..2296b9577e 100644 --- a/test/module/irohad/ametsuchi/ametsuchi_test.cpp +++ b/test/module/irohad/ametsuchi/ametsuchi_test.cpp @@ -671,7 +671,7 @@ TEST_F(AmetsuchiTest, TestingStorageWhenDropAll) { "=> insert block " "=> assert that inserted"); std::shared_ptr storage; - auto storageResult = StorageImpl::create(block_store_path, pgopt_); + auto storageResult = StorageImpl::create(block_store_path, pgopt_, factory); storageResult.match( [&](iroha::expected::Value> &_storage) { storage = _storage.value; @@ -698,8 +698,9 @@ TEST_F(AmetsuchiTest, TestingStorageWhenDropAll) { ASSERT_EQ(0, wsv->getPeers().value().size()); std::shared_ptr new_storage; - auto new_storageResult = StorageImpl::create(block_store_path, pgopt_); - storageResult.match( + auto new_storage_result = + StorageImpl::create(block_store_path, pgopt_, factory); + new_storage_result.match( [&](iroha::expected::Value> &_storage) { new_storage = _storage.value; }, diff --git a/test/module/irohad/ametsuchi/kv_storage_test.cpp b/test/module/irohad/ametsuchi/kv_storage_test.cpp index 9a52a1240f..b85e071dea 100644 --- a/test/module/irohad/ametsuchi/kv_storage_test.cpp +++ b/test/module/irohad/ametsuchi/kv_storage_test.cpp @@ -38,7 +38,7 @@ class KVTest : public AmetsuchiTest { protected: void SetUp() override { AmetsuchiTest::SetUp(); - auto storageResult = StorageImpl::create(block_store_path, pgopt_); + auto storageResult = StorageImpl::create(block_store_path, pgopt_, factory); storageResult.match( [&](iroha::expected::Value> &_storage) { storage = _storage.value; diff --git a/test/module/irohad/ametsuchi/storage_init_test.cpp b/test/module/irohad/ametsuchi/storage_init_test.cpp index 576f785fdb..a978bc0c3f 100644 --- a/test/module/irohad/ametsuchi/storage_init_test.cpp +++ b/test/module/irohad/ametsuchi/storage_init_test.cpp @@ -10,7 +10,9 @@ #include #include #include "ametsuchi/impl/storage_impl.hpp" +#include "backend/protobuf/common_objects/proto_common_objects_factory.hpp" #include "framework/config_helper.hpp" +#include "validators/field_validator.hpp" using namespace iroha::ametsuchi; using namespace iroha::expected; @@ -34,6 +36,11 @@ class StorageInitTest : public ::testing::Test { std::string pg_opt_without_dbname_; std::string pgopt_; + std::shared_ptr> + factory = std::make_shared>(); + void TearDown() override { soci::session sql(soci::postgresql, pg_opt_without_dbname_); std::string query = "DROP DATABASE IF EXISTS " + dbname_; @@ -47,7 +54,7 @@ class StorageInitTest : public ::testing::Test { * @then Database is created */ TEST_F(StorageInitTest, CreateStorageWithDatabase) { - StorageImpl::create(block_store_path, pgopt_) + StorageImpl::create(block_store_path, pgopt_, factory) .match([](const Value> &) { SUCCEED(); }, [](const Error &error) { FAIL() << error.error; }); soci::session sql(soci::postgresql, pg_opt_without_dbname_); @@ -66,7 +73,7 @@ TEST_F(StorageInitTest, CreateStorageWithDatabase) { TEST_F(StorageInitTest, CreateStorageWithInvalidPgOpt) { std::string pg_opt = "host=localhost port=5432 users=nonexistinguser dbname=test"; - StorageImpl::create(block_store_path, pg_opt) + StorageImpl::create(block_store_path, pg_opt, factory) .match( [](const Value> &) { FAIL() << "storage created, but should not"; diff --git a/test/module/irohad/ametsuchi/wsv_query_command_test.cpp b/test/module/irohad/ametsuchi/wsv_query_command_test.cpp index aea5b3f907..8c6278f1cd 100644 --- a/test/module/irohad/ametsuchi/wsv_query_command_test.cpp +++ b/test/module/irohad/ametsuchi/wsv_query_command_test.cpp @@ -51,7 +51,7 @@ namespace iroha { sql = std::make_unique(soci::postgresql, pgopt_); command = std::make_unique(*sql); - query = std::make_unique(*sql); + query = std::make_unique(*sql, factory); *sql << init_; } @@ -548,7 +548,7 @@ namespace iroha { sql = std::make_unique(soci::postgresql, pgopt_); command = std::make_unique(*sql); - query = std::make_unique(*sql); + query = std::make_unique(*sql, factory); } };