Skip to content

Commit

Permalink
removed some boost::accumulate from shared_model
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Boldyrev <miboldyrev@gmail.com>
  • Loading branch information
MBoldyrev committed Oct 22, 2019
1 parent fbe494d commit 69840ee
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 60 deletions.
14 changes: 6 additions & 8 deletions shared_model/backend/protobuf/batch_meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "interfaces/iroha_internal/batch_meta.hpp"

#include <boost/range/numeric.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include "cryptography/hash.hpp"
#include "interfaces/common_objects/types.hpp"
#include "transaction.pb.h"
Expand All @@ -28,13 +28,11 @@ namespace shared_model {
->index();
return static_cast<interface::types::BatchType>(which);
}()},
reduced_hashes_{boost::accumulate(
batch_meta_.reduced_hashes(),
ReducedHashesType{},
[](auto &&acc, const auto &hash) {
acc.emplace_back(crypto::Hash::fromHexString(hash));
return std::forward<decltype(acc)>(acc);
})} {}
reduced_hashes_{boost::copy_range<ReducedHashesType>(
batch_meta.reduced_hashes()
| boost::adaptors::transformed([](const auto &hash) {
return crypto::Hash::fromHexString(hash);
}))} {}

interface::types::BatchType type() const override {
return type_;
Expand Down
19 changes: 9 additions & 10 deletions shared_model/backend/protobuf/commands/impl/proto_create_role.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@

#include "backend/protobuf/commands/proto_create_role.hpp"

#include <boost/range/numeric.hpp>
#include "backend/protobuf/permissions.hpp"

namespace shared_model {
namespace proto {

CreateRole::CreateRole(iroha::protocol::Command &command)
: create_role_{command.create_role()},
role_permissions_{boost::accumulate(
create_role_.permissions(),
interface::RolePermissionSet{},
[](auto &&acc, const auto &perm) {
acc.set(permissions::fromTransport(
static_cast<iroha::protocol::RolePermission>(perm)));
return std::forward<decltype(acc)>(acc);
})} {}
: create_role_{command.create_role()}, role_permissions_{[&command] {
auto &perms_in = command.create_role().permissions();
interface::RolePermissionSet perms_out;
for (const auto &perm : perms_in) {
perms_out.set(permissions::fromTransport(
static_cast<iroha::protocol::RolePermission>(perm)));
}
return perms_out;
}()} {}

const interface::types::RoleIdType &CreateRole::roleName() const {
return create_role_.role_name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@

#include "backend/protobuf/queries/proto_get_transactions.hpp"

#include <boost/range/numeric.hpp>
#include <boost/range/adaptor/transformed.hpp>

namespace shared_model {
namespace proto {

GetTransactions::GetTransactions(iroha::protocol::Query &query)
: get_transactions_{query.payload().get_transactions()},
transaction_hashes_{boost::accumulate(
get_transactions_.tx_hashes(),
TransactionHashesType{},
[](auto &&acc, const auto &hash) {
acc.push_back(crypto::Hash::fromHexString(hash));
return std::forward<decltype(acc)>(acc);
})} {}
transaction_hashes_{boost::copy_range<TransactionHashesType>(
get_transactions_.tx_hashes()
| boost::adaptors::transformed([](const auto &hash) {
return crypto::Hash::fromHexString(hash);
}))} {}

const GetTransactions::TransactionHashesType &
GetTransactions::transactionHashes() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@

#include "backend/protobuf/query_responses/proto_account_response.hpp"

#include <boost/range/numeric.hpp>
#include <boost/range/adaptor/transformed.hpp>

namespace shared_model {
namespace proto {

AccountResponse::AccountResponse(
iroha::protocol::QueryResponse &query_response)
: account_response_{query_response.account_response()},
account_roles_{boost::accumulate(
account_response_.account_roles(),
AccountRolesIdType{},
[](auto &&roles, const auto &role) {
roles.push_back(interface::types::RoleIdType(role));
return std::move(roles);
})},
account_roles_{boost::copy_range<AccountRolesIdType>(
account_response_.account_roles()
| boost::adaptors::transformed([](const auto &role) {
return interface::types::RoleIdType(role);
}))},
account_{
*query_response.mutable_account_response()->mutable_account()} {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "backend/protobuf/query_responses/proto_role_permissions_response.hpp"

#include <boost/range/numeric.hpp>
#include "backend/protobuf/permissions.hpp"
#include "utils/string_builder.hpp"

Expand All @@ -16,14 +15,16 @@ namespace shared_model {
iroha::protocol::QueryResponse &query_response)
: role_permissions_response_{query_response
.role_permissions_response()},
role_permissions_{boost::accumulate(
role_permissions_response_.permissions(),
interface::RolePermissionSet{},
[](auto &&permissions, const auto &permission) {
permissions.set(permissions::fromTransport(
static_cast<iroha::protocol::RolePermission>(permission)));
return std::forward<decltype(permissions)>(permissions);
})} {}
role_permissions_{[&query_response] {
auto &perms_in =
query_response.role_permissions_response().permissions();
interface::RolePermissionSet perms_out;
for (const auto &perm : perms_in) {
perms_out.set(permissions::fromTransport(
static_cast<iroha::protocol::RolePermission>(perm)));
}
return perms_out;
}()} {}

const interface::RolePermissionSet &
RolePermissionsResponse::rolePermissions() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@

#include "backend/protobuf/query_responses/proto_roles_response.hpp"

#include <boost/range/numeric.hpp>
#include <boost/range/iterator_range_core.hpp>

namespace shared_model {
namespace proto {

RolesResponse::RolesResponse(iroha::protocol::QueryResponse &query_response)
: roles_response_{query_response.roles_response()},
roles_{boost::accumulate(roles_response_.roles(),
RolesIdType{},
[](auto &&roles, const auto &role) {
roles.emplace_back(role);
return std::move(roles);
})} {}
roles_{boost::copy_range<RolesIdType>(roles_response_.roles())} {}

const RolesResponse::RolesIdType &RolesResponse::roles() const {
return roles_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "backend/protobuf/query_responses/proto_signatories_response.hpp"

#include <boost/range/numeric.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include "cryptography/hash.hpp"

namespace shared_model {
Expand All @@ -14,15 +14,11 @@ namespace shared_model {
SignatoriesResponse::SignatoriesResponse(
iroha::protocol::QueryResponse &query_response)
: signatories_response_{query_response.signatories_response()},
keys_{[this] {
return boost::accumulate(
signatories_response_.keys(),
interface::types::PublicKeyCollectionType{},
[](auto acc, auto key) {
acc.emplace_back(crypto::Hash::fromHexString(key));
return acc;
});
}()} {}
keys_{boost::copy_range<interface::types::PublicKeyCollectionType>(
signatories_response_.keys()
| boost::adaptors::transformed([](const auto &key) {
return crypto::PublicKey::fromHexString(key);
}))} {}

const interface::types::PublicKeyCollectionType &SignatoriesResponse::keys()
const {
Expand Down

0 comments on commit 69840ee

Please sign in to comment.