Skip to content

Commit

Permalink
Fix review issues
Browse files Browse the repository at this point in the history
Signed-off-by: motxx <[email protected]>
  • Loading branch information
motxx authored and lebdron committed Dec 19, 2017
1 parent e68dcb7 commit a2d1a97
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 241 deletions.
15 changes: 3 additions & 12 deletions shared_model/interfaces/common_objects/account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
#define IROHA_SHARED_MODEL_ACCOUNT_HPP

#include "interfaces/common_objects/types.hpp"
#include "interfaces/primitive.hpp"
#include "interfaces/hashable.hpp"
#include "cryptography/hash.hpp"
#include "model/account.hpp"
#include "utils/string_builder.hpp"

namespace shared_model {
namespace interface {
class Account : public Primitive<Account, iroha::model::Account> {
class Account : public Hashable<Account, iroha::model::Account> {
public:
/**
* @return Identity of user, for fetching data
Expand Down Expand Up @@ -55,16 +56,6 @@ namespace shared_model {
.finalize();
}

/**
* Checks equality of objects inside
* @param rhs - other wrapped value
* @return true, if wrapped objects are same
*/
bool operator==(const ModelType &rhs) const override {
return accountId() == rhs.accountId() and domainId() == rhs.domainId()
and quorum() == rhs.quorum();
}

/**
* Makes old model.
* @return An allocated old model of account asset response.
Expand Down
6 changes: 4 additions & 2 deletions shared_model/interfaces/common_objects/account_asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
#include <new>
#include "interfaces/common_objects/amount.hpp"
#include "interfaces/common_objects/types.hpp"
#include "interfaces/primitive.hpp"
#include "interfaces/hashable.hpp"
#include "model/account_asset.hpp"
#include "utils/string_builder.hpp"

namespace shared_model {
namespace interface {
class AccountAsset
: public Primitive<AccountAsset, iroha::model::AccountAsset> {
: public Hashable<AccountAsset, iroha::model::AccountAsset> {
public:
/**
* @return Identity of user, for fetching data
Expand Down Expand Up @@ -77,6 +77,8 @@ namespace shared_model {
oldModel->account_id = accountId();
oldModel->asset_id = assetId();
using OldBalanceType = decltype(oldModel->balance);
/// Use shared_ptr and placement-new to copy new model field to oldModel's field and
/// to return raw pointer
auto p = std::shared_ptr<OldBalanceType>(balance().makeOldModel());
new (&oldModel->balance) OldBalanceType(*p);
return oldModel;
Expand Down
13 changes: 2 additions & 11 deletions shared_model/interfaces/common_objects/amount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
#include "interfaces/common_objects/amount.hpp"
#include "interfaces/common_objects/types.hpp"
#include "interfaces/polymorphic_wrapper.hpp"
#include "interfaces/primitive.hpp"
#include "interfaces/hashable.hpp"
#include "utils/string_builder.hpp"

namespace shared_model {
namespace interface {
class Amount : public Primitive<Amount, iroha::Amount> {
class Amount : public Hashable<Amount, iroha::Amount> {
public:
/**
* Converts to uint64_t vector
Expand Down Expand Up @@ -67,10 +67,6 @@ namespace shared_model {
virtual detail::PolymorphicWrapper<Amount> percentage(
const Amount &percents) const = 0;

/**
* Comparisons are possible between amounts with different precisions.
*/

/**
* Checks equality of objects inside
* @param rhs - other wrapped value
Expand All @@ -80,11 +76,6 @@ namespace shared_model {
return intValue() == rhs.intValue() and precision() == rhs.precision();
}

virtual bool operator<(const Amount &) const = 0;
virtual bool operator>(const Amount &) const = 0;
virtual bool operator<=(const Amount &) const = 0;
virtual bool operator>=(const Amount &) const = 0;

/**
* Stringify the data.
* @return the content of asset.
Expand Down
4 changes: 2 additions & 2 deletions shared_model/interfaces/common_objects/asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
#define IROHA_SHARED_MODEL_ASSET_HPP

#include "interfaces/common_objects/types.hpp"
#include "interfaces/primitive.hpp"
#include "interfaces/hashable.hpp"
#include "model/asset.hpp"
#include "utils/string_builder.hpp"

namespace shared_model {
namespace interface {
class Asset : public Primitive<Asset, iroha::model::Asset> {
class Asset : public Hashable<Asset, iroha::model::Asset> {
public:
/**
* @return Identity of asset
Expand Down
4 changes: 2 additions & 2 deletions shared_model/interfaces/common_objects/signature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "cryptography/blob.hpp"
#include "cryptography/public_key.hpp"
#include "cryptography/signed.hpp"
#include "interfaces/primitive.hpp"
#include "interfaces/hashable.hpp"
#include "model/signature.hpp"
#include "utils/string_builder.hpp"

Expand All @@ -31,7 +31,7 @@ namespace shared_model {
/**
* Class represents signature of high-level domain objects.
*/
class Signature : public Primitive<Signature, iroha::model::Signature> {
class Signature : public Hashable<Signature, iroha::model::Signature> {
public:
/**
* Type of public key
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

/**
* 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_ABSTRACT_ERROR_RESPONSE_HPP
#define IROHA_ABSTRACT_ERROR_RESPONSE_HPP

#include "interfaces/primitive.hpp"
#include "model/queries/responses/error_response.hpp"
#include "utils/string_builder.hpp"

namespace shared_model {
namespace interface {
/**
* Abstract error response
* @tparam Model - concrete model error response
*/
template <typename Model>
class AbstractErrorResponse
: public Primitive<Model, iroha::model::ErrorResponse> {
private:
/**
* @return string representation of error reason
*/
virtual std::string reason() const = 0;

/**
* @return old model error reason
*/
virtual iroha::model::ErrorResponse::Reason oldModelReason() const = 0;

public:
// ------------------------| Primitive override |-------------------------

std::string toString() const override {
return detail::PrettyStringBuilder().init(reason()).finalize();
}

iroha::model::ErrorResponse *makeOldModel() const override {
auto error_reponse = new iroha::model::ErrorResponse();
error_reponse->reason = oldModelReason();
return error_reponse;
}

bool operator==(const Model &rhs) const override { return true; }
};
} // namespace interface
} // namespace shared_model

#endif // IROHA_ABSTRACT_ERROR_RESPONSE_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ namespace shared_model {
OldModelType *makeOldModel() const override {
OldModelType *oldModel = new OldModelType();
using OldAccountAssetType = decltype(oldModel->acct_asset);
/// Use shared_ptr and placement-new to copy new model field to oldModel's field and
/// to return raw pointer
auto p =
std::shared_ptr<OldAccountAssetType>(accountAsset().makeOldModel());
new (&oldModel->acct_asset) OldAccountAssetType(*p);
Expand Down
11 changes: 10 additions & 1 deletion shared_model/interfaces/query_responses/account_response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ namespace shared_model {
*/
virtual const Account &account() const = 0;

/**
* @return roles attached to the account
*/
virtual const types::RolesType &roles() const = 0;

/**
* Stringify the data.
* @return string representation of data.
Expand All @@ -47,6 +52,8 @@ namespace shared_model {
return detail::PrettyStringBuilder()
.init("AccountResponse")
.append(account().toString())
.append("roles")
.appendAll(roles(), [](auto s) { return s; })
.finalize();
}

Expand All @@ -56,7 +63,7 @@ namespace shared_model {
* @return true if they have same values.
*/
bool operator==(const ModelType &rhs) const override {
return account() == rhs.account();
return account() == rhs.account() and roles() == rhs.roles();
}

/**
Expand All @@ -66,6 +73,8 @@ namespace shared_model {
OldModelType *makeOldModel() const override {
OldModelType *oldModel = new OldModelType();
using OldAccountType = decltype(oldModel->account);
/// Use shared_ptr and placement-new to copy new model field to oldModel's field and
/// to return raw pointer
auto p = std::shared_ptr<OldAccountType>(account().makeOldModel());
new (&oldModel->account) OldAccountType(*p);
return oldModel;
Expand Down
3 changes: 3 additions & 0 deletions shared_model/interfaces/query_responses/asset_response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef IROHA_SHARED_MODEL_ASSET_RESPONSE_HPP
#define IROHA_SHARED_MODEL_ASSET_RESPONSE_HPP

#include <new>
#include "interfaces/common_objects/asset.hpp"
#include "interfaces/common_objects/types.hpp"
#include "interfaces/primitive.hpp"
Expand Down Expand Up @@ -63,6 +64,8 @@ namespace shared_model {
OldModelType *makeOldModel() const override {
OldModelType *oldModel = new OldModelType();
using OldAssetType = decltype(oldModel->asset);
/// Use shared_ptr and placement-new to copy new model field to oldModel's field and
/// to return raw pointer
auto p = std::shared_ptr<OldAssetType>(asset().makeOldModel());
new (&oldModel->asset) OldAssetType(*p);
return oldModel;
Expand Down
Loading

0 comments on commit a2d1a97

Please sign in to comment.