Skip to content

Commit

Permalink
Add AssetResponse
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 3266112 commit 3b7dcec
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 0 deletions.
82 changes: 82 additions & 0 deletions shared_model/interfaces/common_objects/asset.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_ASSET_HPP
#define IROHA_SHARED_MODEL_ASSET_HPP

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

namespace shared_model {
namespace interface {
class Asset : public Primitive<Asset, iroha::model::Asset> {
public:
/**
* @return Identity of asset
*/
virtual const types::AccountIdType &assetId() const = 0;

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

/**
* @return Asset's fixed precision
*/
virtual const types::PrecisionType &precision() const = 0;

/**
* Stringify the data.
* @return the content of asset.
*/
std::string toString() const override {
return detail::PrettyStringBuilder()
.init("Asset")
.append("assetId", assetId())
.append("domainId", domainId())
.append("precision", std::to_string(precision()))
.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 assetId() == rhs.assetId() and domainId() == rhs.domainId()
and precision() == rhs.precision();
}

/**
* Makes old model.
* @return An allocated old model of account asset response.
*/
OldModelType *makeOldModel() const override {
OldModelType *oldModel = new OldModelType();
oldModel->asset_id = assetId();
oldModel->domain_id = domainId();
oldModel->precision = precision();
return oldModel;
}
};
} // namespace interface
} // namespace shared_model
#endif // IROHA_SHARED_MODEL_ASSET_HPP
73 changes: 73 additions & 0 deletions shared_model/interfaces/query_responses/asset_response.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* 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_ASSET_RESPONSE_HPP
#define IROHA_SHARED_MODEL_ASSET_RESPONSE_HPP

#include "interfaces/common_objects/asset.hpp"
#include "interfaces/common_objects/types.hpp"
#include "interfaces/primitive.hpp"
#include "interfaces/visitor_apply_for_all.hpp"
#include "model/queries/responses/asset_response.hpp"
#include "utils/string_builder.hpp"

namespace shared_model {
namespace interface {
/**
* Provide response with asset
*/
class AssetResponse
: public Primitive<AssetResponse, iroha::model::AssetResponse> {
public:
/**
* @return Attached asset
*/
virtual const Asset &asset() const = 0;

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

/**
* @return true if the data are same.
*/
bool operator==(const ModelType &rhs) const override {
return asset() == rhs.asset();
}

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

0 comments on commit 3b7dcec

Please sign in to comment.