Skip to content

Commit

Permalink
cosmetics
Browse files Browse the repository at this point in the history
Signed-off-by: Moonraker <[email protected]>
  • Loading branch information
Solonets committed Feb 12, 2018
1 parent 0eba575 commit e4673f1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
32 changes: 13 additions & 19 deletions irohad/ametsuchi/impl/storage_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@

#include <boost/format.hpp>

using iroha::expected::Error;
using iroha::expected::Result;
using iroha::expected::Value;
using iroha::expected::makeError;
using iroha::expected::makeValue;

namespace iroha {
namespace ametsuchi {

Expand Down Expand Up @@ -69,11 +63,11 @@ namespace iroha {
"SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;");
}

Result<std::unique_ptr<TemporaryWsv>, std::string> StorageImpl::createTemporaryWsv() {
expected::Result<std::unique_ptr<TemporaryWsv>, std::string> StorageImpl::createTemporaryWsv() {
auto command_executors = model::CommandExecutorFactory::create();
if (not command_executors.has_value()) {
log_->error(kCommandExecutorError);
return makeError(kCommandExecutorError);
return expected::makeError(kCommandExecutorError);
}

auto postgres_connection =
Expand All @@ -82,24 +76,24 @@ namespace iroha {
postgres_connection->activate();
} catch (const pqxx::broken_connection &e) {
log_->error(kPsqlBroken, e.what());
return makeError((boost::format(kPsqlBroken) % e.what()).str());
return expected::makeError((boost::format(kPsqlBroken) % e.what()).str());
}
auto wsv_transaction =
std::make_unique<pqxx::nontransaction>(*postgres_connection, kTmpWsv);

return makeValue<std::unique_ptr<TemporaryWsv>>(
return expected::makeValue<std::unique_ptr<TemporaryWsv>>(
std::make_unique<TemporaryWsvImpl>(
std::move(postgres_connection),
std::move(wsv_transaction),
std::move(command_executors.value()))
);
}

Result<std::unique_ptr<MutableStorage>, std::string> StorageImpl::createMutableStorage() {
expected::Result<std::unique_ptr<MutableStorage>, std::string> StorageImpl::createMutableStorage() {
auto command_executors = model::CommandExecutorFactory::create();
if (not command_executors.has_value()) {
log_->error(kCommandExecutorError);
return makeError(kCommandExecutorError);
return expected::makeError(kCommandExecutorError);
}

auto postgres_connection =
Expand All @@ -108,7 +102,7 @@ namespace iroha {
postgres_connection->activate();
} catch (const pqxx::broken_connection &e) {
log_->error(kPsqlBroken, e.what());
return makeError((boost::format(kPsqlBroken) % e.what()).str());
return expected::makeError((boost::format(kPsqlBroken) % e.what()).str());
}
auto wsv_transaction =
std::make_unique<pqxx::nontransaction>(*postgres_connection, kTmpWsv);
Expand All @@ -120,7 +114,7 @@ namespace iroha {
.as_blocking()
.subscribe([&top_hash](auto block) { top_hash = block.hash; });

return makeValue<std::unique_ptr<MutableStorage>>(
return expected::makeValue<std::unique_ptr<MutableStorage>>(
std::make_unique<MutableStorageImpl>(
top_hash.value_or(hash256_t{}),
std::move(postgres_connection),
Expand All @@ -134,15 +128,15 @@ namespace iroha {
auto storageResult = createMutableStorage();
bool inserted = false;
storageResult.match(
[&](Value<std::unique_ptr<ametsuchi::MutableStorage>> &storage) {
[&](expected::Value<std::unique_ptr<ametsuchi::MutableStorage>> &storage) {
inserted = storage.value->apply(
block,
[](const auto &current_block, auto &query, const auto &top_hash) {
return true;
});
log_->info("block inserted: {}", inserted);
commit(std::move(storage.value));
}, [&](Error<std::string> &error) {
}, [&](expected::Error<std::string> &error) {
log_->error("Cannot create mutable storage");
}
);
Expand Down Expand Up @@ -219,15 +213,15 @@ DROP TABLE IF EXISTS index_by_id_height_asset;
std::move(wsv_transaction));
}

Result<std::shared_ptr<StorageImpl>, std::string> StorageImpl::create(
expected::Result<std::shared_ptr<StorageImpl>, std::string> StorageImpl::create(
std::string block_store_dir,
std::string postgres_options) {
auto ctx = initConnections(block_store_dir, postgres_options);
if (not ctx.has_value()) {
return makeError("Failed to connect to PostgreSql");
return expected::makeError("Failed to connect to PostgreSql");
}

return makeValue(std::shared_ptr<StorageImpl>(
return expected::makeValue(std::shared_ptr<StorageImpl>(
new StorageImpl(block_store_dir,
postgres_options,
std::move(ctx->block_store),
Expand Down
12 changes: 8 additions & 4 deletions irohad/synchronizer/impl/synchronizer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ namespace iroha {
storageResult.match(
[&](expected::Value<std::unique_ptr<ametsuchi::MutableStorage>> &_storage) {
storage = std::move(_storage.value);
}, [](expected::Error<std::string> &error) {}
}, [&](expected::Error<std::string> &error) {
storage = nullptr;
log_->error(error.error);
}
);
if (not storage) {
log_->error("Cannot create mutable storage");
return;
}
if (validator_->validateBlock(commit_message, *storage)) {
Expand All @@ -65,10 +67,12 @@ namespace iroha {
storageResult.match(
[&](expected::Value<std::unique_ptr<ametsuchi::MutableStorage>> &_storage) {
storage = std::move(_storage.value);
}, [](expected::Error<std::string> &error) {}
}, [&](expected::Error<std::string> &error) {
storage = nullptr;
log_->error(error.error);
}
);
if (not storage) {
log_->error("cannot create storage");
return;
}
auto chain = blockLoader_->retrieveBlocks(signature.pubkey);
Expand Down
20 changes: 10 additions & 10 deletions test/module/irohad/ametsuchi/ametsuchi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void apply(S &&storage, const Block &block) {
[&](iroha::expected::Value<std::unique_ptr<MutableStorage>> &_storage) {
ms = std::move(_storage.value);
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
FAIL();
}
);
ms->apply(block, [](const auto &, auto &, const auto &) { return true; });
Expand All @@ -168,7 +168,7 @@ TEST_F(AmetsuchiTest, GetBlocksCompletedWhenCalled) {
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
FAIL();
}
);
ASSERT_TRUE(storage);
Expand All @@ -192,7 +192,7 @@ TEST_F(AmetsuchiTest, SampleTest) {
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
FAIL();
}
);
ASSERT_TRUE(storage);
Expand Down Expand Up @@ -292,7 +292,7 @@ TEST_F(AmetsuchiTest, PeerTest) {
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
FAIL();
}
);
ASSERT_TRUE(storage);
Expand Down Expand Up @@ -322,7 +322,7 @@ TEST_F(AmetsuchiTest, queryGetAccountAssetTransactionsTest) {
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
FAIL();
}
);
ASSERT_TRUE(storage);
Expand Down Expand Up @@ -464,7 +464,7 @@ TEST_F(AmetsuchiTest, AddSignatoryTest) {
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
FAIL();
}
);
ASSERT_TRUE(storage);
Expand Down Expand Up @@ -717,7 +717,7 @@ TEST_F(AmetsuchiTest, TestingStorageWhenInsertBlock) {
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
FAIL();
}
);
ASSERT_TRUE(storage);
Expand Down Expand Up @@ -758,7 +758,7 @@ TEST_F(AmetsuchiTest, TestingStorageWhenDropAll) {
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
FAIL();
}
);
ASSERT_TRUE(storage);
Expand All @@ -785,7 +785,7 @@ TEST_F(AmetsuchiTest, TestingStorageWhenDropAll) {
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
new_storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
FAIL();
}
);
ASSERT_EQ(0, wsv->getPeers().value().size());
Expand All @@ -805,7 +805,7 @@ TEST_F(AmetsuchiTest, FindTxByHashTest) {
[&](iroha::expected::Value<std::shared_ptr<StorageImpl>> &_storage) {
storage = _storage.value;
}, [](iroha::expected::Error<std::string> &error) {
ASSERT_TRUE(0);
FAIL();
}
);
ASSERT_TRUE(storage);
Expand Down

0 comments on commit e4673f1

Please sign in to comment.