Skip to content

Commit

Permalink
Add AccountResponse
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 243dd6c commit 3266112
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 0 deletions.
82 changes: 82 additions & 0 deletions shared_model/interfaces/common_objects/account.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* 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_SHARED_MODEL_ACCOUNT_HPP
#define IROHA_SHARED_MODEL_ACCOUNT_HPP

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

namespace shared_model {
namespace interface {
class Account : public Primitive<Account, iroha::model::Account> {
public:
/**
* @return Identity of user, for fetching data
*/
virtual const types::AccountIdType &accountId() const = 0;

/**
* @return Identity of domain, for fetching data
*/
virtual const types::DomainIdType &domainId() const = 0;

/**
* @return Minimum quorum of signatures needed for transactions
*/
virtual const types::QuorumType &quorum() const = 0;

/**
* Stringify the data.
* @return the content of account asset.
*/
std::string toString() const override {
return detail::PrettyStringBuilder()
.init("Account")
.append("accountId", accountId())
.append("domainId", domainId())
.append("quorum", std::to_string(quorum()))
.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.
*/
OldModelType *makeOldModel() const override {
OldModelType *oldModel = new OldModelType();
oldModel->account_id = accountId();
oldModel->domain_id = domainId();
oldModel->quorum = quorum();
return oldModel;
}
};
} // namespace interface
} // namespace shared_model
#endif // IROHA_SHARED_MODEL_ACCOUNT_HPP
76 changes: 76 additions & 0 deletions shared_model/interfaces/query_responses/account_response.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* 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_SHARED_MODEL_ACCOUNT_RESPONSE_HPP
#define IROHA_SHARED_MODEL_ACCOUNT_RESPONSE_HPP

#include <new>
#include "interfaces/common_objects/account.hpp"
#include "interfaces/common_objects/types.hpp"
#include "interfaces/primitive.hpp"
#include "interfaces/visitor_apply_for_all.hpp"
#include "model/queries/responses/account_response.hpp"
#include "utils/string_builder.hpp"

namespace shared_model {
namespace interface {
/**
* Provide response with account
*/
class AccountResponse
: public Primitive<AccountResponse, iroha::model::AccountResponse> {
public:
/**
* @return the fetched account.
*/
virtual const Account &account() const = 0;

/**
* Stringify the data.
* @return string representation of data.
*/
std::string toString() const override {
return detail::PrettyStringBuilder()
.init("AccountResponse")
.append(account().toString())
.finalize();
}

/**
* Implementation of operator ==
* @param rhs - the right hand-side of GetAccountAssetResponse
* @return true if they have same values.
*/
bool operator==(const ModelType &rhs) const override {
return account() == rhs.account();
}

/**
* Makes old model.
* @return An allocated old model of asset response.
*/
OldModelType *makeOldModel() const override {
OldModelType *oldModel = new OldModelType();
using OldAccountType = decltype(oldModel->account);
auto p = std::shared_ptr<OldAccountType>(account().makeOldModel());
new (&oldModel->account) OldAccountType(*p);
return oldModel;
}
};
} // namespace interface
} // namespace shared_model
#endif // IROHA_SHARED_MODEL_ACCOUNT_RESPONSE_HPP

0 comments on commit 3266112

Please sign in to comment.