Skip to content

Commit

Permalink
Unity build: prepare support in irohad
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
  • Loading branch information
lebdron committed Aug 29, 2019
1 parent 97ec9cf commit 7096c5d
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 70 deletions.
1 change: 1 addition & 0 deletions irohad/ametsuchi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ add_library(ametsuchi
impl/postgres_wsv_command.cpp
impl/peer_query_wsv.cpp
impl/postgres_block_query.cpp
impl/executor_common.cpp
impl/postgres_command_executor.cpp
impl/postgres_indexer.cpp
impl/postgres_block_index.cpp
Expand Down
29 changes: 29 additions & 0 deletions irohad/ametsuchi/impl/executor_common.cpp
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
*/

#include "ametsuchi/impl/executor_common.hpp"

#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include "interfaces/permissions.hpp"

namespace iroha {
namespace ametsuchi {

const std::string kRootRolePermStr{
shared_model::interface::RolePermissionSet(
{shared_model::interface::permissions::Role::kRoot})
.toBitstring()};

shared_model::interface::types::DomainIdType getDomainFromName(
const shared_model::interface::types::AccountIdType &account_id) {
// TODO 03.10.18 andrei: IR-1728 Move getDomainFromName to shared_model
std::vector<std::string> res;
boost::split(res, account_id, boost::is_any_of("@"));
return res.at(1);
}

} // namespace ametsuchi
} // namespace iroha
22 changes: 22 additions & 0 deletions irohad/ametsuchi/impl/executor_common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef IROHA_AMETSUCHI_EXECUTOR_COMMON_HPP
#define IROHA_AMETSUCHI_EXECUTOR_COMMON_HPP

#include "interfaces/common_objects/types.hpp"

namespace iroha {
namespace ametsuchi {

extern const std::string kRootRolePermStr;

shared_model::interface::types::DomainIdType getDomainFromName(
const shared_model::interface::types::AccountIdType &account_id);

} // namespace ametsuchi
} // namespace iroha

#endif // IROHA_AMETSUCHI_EXECUTOR_COMMON_HPP
13 changes: 1 addition & 12 deletions irohad/ametsuchi/impl/postgres_command_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ namespace {
const std::string kPgTrue{"true"};
const std::string kPgFalse{"false"};

const auto kRootRolePermStr =
shared_model::interface::RolePermissionSet({Role::kRoot}).toBitstring();

std::string makeJsonString(std::string value) {
return std::string{"\""} + value + "\"";
}
Expand Down Expand Up @@ -187,7 +184,7 @@ namespace {
JOIN account_has_roles AS ar on ar.role_id = rp.role_id
WHERE ar.account_id = %4%)")
% kRolePermissionSetSize % permission_bitstring
% kRootRolePermStr % account_id)
% iroha::ametsuchi::kRootRolePermStr % account_id)
.str();
return query;
}
Expand Down Expand Up @@ -223,14 +220,6 @@ namespace {
return query;
}

shared_model::interface::types::DomainIdType getDomainFromName(
const shared_model::interface::types::AccountIdType &account_id) {
// TODO 03.10.18 andrei: IR-1728 Move getDomainFromName to shared_model
std::vector<std::string> res;
boost::split(res, account_id, boost::is_any_of("@"));
return res.at(1);
}

/**
* Generate an SQL subquery which checks if creator has corresponding
* permissions for target account
Expand Down
21 changes: 5 additions & 16 deletions irohad/ametsuchi/impl/postgres_specific_query_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@

#include "ametsuchi/impl/postgres_specific_query_executor.hpp"

#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/format.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/algorithm/transform.hpp>
#include <boost/range/irange.hpp>
#include "ametsuchi/block_storage.hpp"
#include "ametsuchi/impl/executor_common.hpp"
#include "ametsuchi/impl/soci_utils.hpp"
#include "backend/plain/account_detail_record_id.hpp"
#include "backend/plain/peer.hpp"
Expand Down Expand Up @@ -47,25 +46,15 @@ namespace {

using namespace iroha;

const auto kRootRolePermStr =
shared_model::interface::RolePermissionSet({Role::kRoot}).toBitstring();

shared_model::interface::types::DomainIdType getDomainFromName(
const shared_model::interface::types::AccountIdType &account_id) {
// TODO 03.10.18 andrei: IR-1728 Move getDomainFromName to shared_model
std::vector<std::string> res;
boost::split(res, account_id, boost::is_any_of("@"));
return res.at(1);
}

std::string getAccountRolePermissionCheckSql(
shared_model::interface::permissions::Role permission,
const std::string &account_alias = ":role_account_id") {
const auto perm_str =
shared_model::interface::RolePermissionSet({permission}).toBitstring();
const auto bits = shared_model::interface::RolePermissionSet::size();
// TODO 14.09.18 andrei: IR-1708 Load SQL from separate files
std::string query = (boost::format(R"(
std::string query =
(boost::format(R"(
SELECT
(
COALESCE(bit_or(rp.permission), '0'::bit(%1%))
Expand All @@ -75,8 +64,8 @@ namespace {
FROM role_has_permissions AS rp
JOIN account_has_roles AS ar on ar.role_id = rp.role_id
WHERE ar.account_id = %4%)")
% bits % perm_str % kRootRolePermStr % account_alias)
.str();
% bits % perm_str % iroha::ametsuchi::kRootRolePermStr % account_alias)
.str();
return query;
}

Expand Down
34 changes: 13 additions & 21 deletions irohad/multi_sig_transactions/transport/impl/mst_transport_grpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,19 @@ MstTransportGrpc::MstTransportGrpc(

shared_model::interface::types::SharedTxsCollectionType
MstTransportGrpc::deserializeTransactions(const transport::MstState *request) {
return boost::copy_range<
shared_model::interface::types::SharedTxsCollectionType>(
request->transactions()
| boost::adaptors::transformed(
[&](const auto &tx) { return transaction_factory_->build(tx); })
| boost::adaptors::filtered([&](const auto &result) {
return result.match(
[](const auto &) { return true; },
[&](const auto &error) {
log_->info("Transaction deserialization failed: hash {}, {}",
error.error.hash,
error.error.error);
return false;
});
})
| boost::adaptors::transformed([&](auto result) {
return std::move(
boost::get<iroha::expected::ValueOf<decltype(result)>>(
result))
.value;
}));
shared_model::interface::types::SharedTxsCollectionType tx_collection;
for (const auto &tx : request->transactions()) {
transaction_factory_->build(tx).match(
[&tx_collection](auto &&v) {
tx_collection.emplace_back(std::move(v).value);
},
[this](const auto &error) {
log_->info("Transaction deserialization failed: hash {}, {}",
error.error.hash,
error.error.error);
});
}
return tx_collection;
}

grpc::Status MstTransportGrpc::SendState(
Expand Down
34 changes: 13 additions & 21 deletions irohad/ordering/impl/on_demand_os_server_grpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,19 @@ OnDemandOsServerGrpc::OnDemandOsServerGrpc(
shared_model::interface::types::SharedTxsCollectionType
OnDemandOsServerGrpc::deserializeTransactions(
const proto::BatchesRequest *request) {
return boost::copy_range<
shared_model::interface::types::SharedTxsCollectionType>(
request->transactions()
| boost::adaptors::transformed(
[&](const auto &tx) { return transaction_factory_->build(tx); })
| boost::adaptors::filtered([&](const auto &result) {
return result.match(
[](const auto &) { return true; },
[&](const auto &error) {
log_->info("Transaction deserialization failed: hash {}, {}",
error.error.hash,
error.error.error);
return false;
});
})
| boost::adaptors::transformed([](auto result) {
return std::move(
boost::get<iroha::expected::ValueOf<decltype(result)>>(
result))
.value;
}));
shared_model::interface::types::SharedTxsCollectionType tx_collection;
for (const auto &tx : request->transactions()) {
transaction_factory_->build(tx).match(
[&tx_collection](auto &&v) {
tx_collection.emplace_back(std::move(v).value);
},
[this](const auto &error) {
log_->info("Transaction deserialization failed: hash {}, {}",
error.error.hash,
error.error.error);
});
}
return tx_collection;
}

grpc::Status OnDemandOsServerGrpc::SendBatches(
Expand Down

0 comments on commit 7096c5d

Please sign in to comment.