forked from hyperledger-iroha/iroha-dco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: motxx <[email protected]>
- Loading branch information
Showing
2 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
76
shared_model/interfaces/query_responses/account_response.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |