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.
Merge branch 'feature/shared_model_common_builders' into develop
Signed-off-by: Nikita Alekseev <[email protected]>
- Loading branch information
Showing
31 changed files
with
2,018 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
81 changes: 81 additions & 0 deletions
81
shared_model/builders/common_objects/account_asset_builder.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,81 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. 2018 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_ACCOUNT_ASSET_BUILDER_HPP | ||
#define IROHA_ACCOUNT_ASSET_BUILDER_HPP | ||
|
||
#include "builders/common_objects/common.hpp" | ||
#include "interfaces/common_objects/account_asset.hpp" | ||
|
||
// TODO: 14.02.2018 nickaleks Add check for uninitialized fields IR-972 | ||
|
||
namespace shared_model { | ||
namespace builder { | ||
/** | ||
* AccountAssetBuilder is a class, used for construction of AccountAsset | ||
* objects | ||
* @tparam BuilderImpl is a type, which defines builder for implementation | ||
* of shared_model. Since we return abstract classes, it is necessary for | ||
* them to be instantiated with some concrete implementation | ||
* @tparam Validator is a type, whose responsibility is | ||
* to perform stateless validation on model fields | ||
*/ | ||
template <typename BuilderImpl, typename Validator> | ||
class AccountAssetBuilder | ||
: public CommonObjectBuilder<interface::AccountAsset, | ||
BuilderImpl, | ||
Validator> { | ||
public: | ||
AccountAssetBuilder accountId( | ||
const interface::types::AccountIdType &account_id) { | ||
AccountAssetBuilder copy(*this); | ||
copy.builder_ = this->builder_.accountId(account_id); | ||
return copy; | ||
} | ||
|
||
AccountAssetBuilder assetId( | ||
const interface::types::AssetIdType &asset_id) { | ||
AccountAssetBuilder copy(*this); | ||
copy.builder_ = this->builder_.assetId(asset_id); | ||
return copy; | ||
} | ||
|
||
AccountAssetBuilder balance(const interface::Amount &amount) { | ||
AccountAssetBuilder copy(*this); | ||
copy.builder_ = this->builder_.balance(amount); | ||
return copy; | ||
} | ||
|
||
protected: | ||
virtual std::string builderName() const override { | ||
return "Account Asset Builder"; | ||
} | ||
|
||
virtual validation::ReasonsGroupType validate( | ||
const interface::AccountAsset &object) override { | ||
validation::ReasonsGroupType reasons; | ||
this->validator_.validateAccountId(reasons, object.accountId()); | ||
this->validator_.validateAssetId(reasons, object.assetId()); | ||
// Do not validate balance, since its amount can be 0, which is | ||
// forbidden by validation | ||
|
||
return reasons; | ||
} | ||
}; | ||
} // namespace builder | ||
} // namespace shared_model | ||
#endif // IROHA_ACCOUNT_ASSET_BUILDER_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,86 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. 2018 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_ACCOUNT_BUILDER_HPP | ||
#define IROHA_ACCOUNT_BUILDER_HPP | ||
|
||
#include "builders/common_objects/common.hpp" | ||
#include "interfaces/common_objects/account.hpp" | ||
|
||
// TODO: 14.02.2018 nickaleks Add check for uninitialized fields IR-972 | ||
|
||
namespace shared_model { | ||
namespace builder { | ||
|
||
/** | ||
* AccountBuilder is a class, used for construction of Account objects | ||
* @tparam BuilderImpl is a type, which defines builder for implementation | ||
* of shared_model. Since we return abstract classes, it is necessary for | ||
* them to be instantiated with some concrete implementation | ||
* @tparam Validator is a type, whose responsibility is | ||
* to perform stateless validation on model fields | ||
*/ | ||
template <typename BuilderImpl, typename Validator> | ||
class AccountBuilder : public CommonObjectBuilder<interface::Account, | ||
BuilderImpl, | ||
Validator> { | ||
public: | ||
AccountBuilder accountId( | ||
const interface::types::AccountIdType &account_id) { | ||
AccountBuilder copy(*this); | ||
copy.builder_ = this->builder_.accountId(account_id); | ||
return copy; | ||
} | ||
|
||
AccountBuilder domainId( | ||
const interface::types::DomainIdType &domain_id) { | ||
AccountBuilder copy(*this); | ||
copy.builder_ = this->builder_.domainId(domain_id); | ||
return copy; | ||
} | ||
|
||
AccountBuilder quorum(const interface::types::QuorumType &quorum) { | ||
AccountBuilder copy(*this); | ||
copy.builder_ = this->builder_.quorum(quorum); | ||
return copy; | ||
} | ||
|
||
AccountBuilder jsonData(const interface::types::JsonType &json_data) { | ||
AccountBuilder copy(*this); | ||
copy.builder_ = this->builder_.jsonData(json_data); | ||
return copy; | ||
} | ||
|
||
protected: | ||
virtual std::string builderName() const override { | ||
return "Account Builder"; | ||
} | ||
|
||
virtual validation::ReasonsGroupType validate( | ||
const interface::Account &object) override { | ||
validation::ReasonsGroupType reasons; | ||
this->validator_.validateAccountId(reasons, object.accountId()); | ||
this->validator_.validateDomainId(reasons, object.domainId()); | ||
this->validator_.validateQuorum(reasons, object.quorum()); | ||
|
||
return reasons; | ||
} | ||
}; | ||
} // namespace builder | ||
} // namespace shared_model | ||
|
||
#endif // IROHA_ACCOUNT_BUILDER_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,71 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. 2018 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_AMOUNT_BUILDER_HPP | ||
#define IROHA_AMOUNT_BUILDER_HPP | ||
|
||
#include "builders/common_objects/common.hpp" | ||
#include "interfaces/common_objects/amount.hpp" | ||
|
||
// TODO: 14.02.2018 nickaleks Add check for uninitialized fields IR-972 | ||
|
||
namespace shared_model { | ||
namespace builder { | ||
|
||
/** | ||
* AmountBuilder is a class, used for construction of Amount objects | ||
* @tparam BuilderImpl is a type, which defines builder for implementation | ||
* of shared_model. Since we return abstract classes, it is necessary for | ||
* them to be instantiated with some concrete implementation | ||
* @tparam Validator is a type, whose responsibility is | ||
* to perform stateless validation on model fields | ||
*/ | ||
template <typename BuilderImpl, typename Validator> | ||
class AmountBuilder : public CommonObjectBuilder<interface::Amount, | ||
BuilderImpl, | ||
Validator> { | ||
public: | ||
AmountBuilder intValue(const boost::multiprecision::uint256_t &value) { | ||
AmountBuilder copy(*this); | ||
copy.builder_ = this->builder_.intValue(value); | ||
return copy; | ||
} | ||
|
||
AmountBuilder precision( | ||
const interface::types::PrecisionType &precision) { | ||
AmountBuilder copy(*this); | ||
copy.builder_ = this->builder_.precision(precision); | ||
return copy; | ||
} | ||
|
||
protected: | ||
virtual std::string builderName() const override { | ||
return "Amount Builder"; | ||
} | ||
|
||
virtual validation::ReasonsGroupType validate( | ||
const interface::Amount &object) override { | ||
validation::ReasonsGroupType reasons; | ||
this->validator_.validateAmount(reasons, object); | ||
|
||
return reasons; | ||
} | ||
}; | ||
} // namespace builder | ||
} // namespace shared_model | ||
|
||
#endif // IROHA_AMOUNT_BUILDER_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,78 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. 2018 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_ASSET_BUILDER_HPP | ||
#define IROHA_ASSET_BUILDER_HPP | ||
|
||
#include "builders/common_objects/common.hpp" | ||
#include "interfaces/common_objects/asset.hpp" | ||
#include "interfaces/common_objects/types.hpp" | ||
|
||
// TODO: 14.02.2018 nickaleks Add check for uninitialized fields IR-972 | ||
|
||
namespace shared_model { | ||
namespace builder { | ||
|
||
/** | ||
* AssetBuilder is a class, used for construction of Asset objects | ||
* @tparam BuilderImpl is a type, which defines builder for implementation | ||
* of shared_model. Since we return abstract classes, it is necessary for | ||
* them to be instantiated with some concrete implementation | ||
* @tparam Validator is a type, whose responsibility is | ||
* to perform stateless validation on model fields | ||
*/ | ||
template <typename BuilderImpl, typename Validator> | ||
class AssetBuilder | ||
: public CommonObjectBuilder<interface::Asset, BuilderImpl, Validator> { | ||
public: | ||
AssetBuilder assetId(const interface::types::AccountIdType &asset_id) { | ||
AssetBuilder copy(*this); | ||
copy.builder_ = this->builder_.assetId(asset_id); | ||
return copy; | ||
} | ||
|
||
AssetBuilder domainId(const interface::types::DomainIdType &domain_id) { | ||
AssetBuilder copy(*this); | ||
copy.builder_ = this->builder_.domainId(domain_id); | ||
return copy; | ||
} | ||
|
||
AssetBuilder precision( | ||
const interface::types::PrecisionType &precision) { | ||
AssetBuilder copy(*this); | ||
copy.builder_ = this->builder_.precision(precision); | ||
return copy; | ||
} | ||
|
||
protected: | ||
virtual std::string builderName() const override { | ||
return "Asset Builder"; | ||
} | ||
|
||
virtual validation::ReasonsGroupType validate(const interface::Asset &object) override { | ||
validation::ReasonsGroupType reasons; | ||
this->validator_.validateAssetId(reasons, object.assetId()); | ||
this->validator_.validateDomainId(reasons, object.domainId()); | ||
this->validator_.validatePrecision(reasons, object.precision()); | ||
|
||
return reasons; | ||
} | ||
}; | ||
} // namespace builder | ||
} // namespace shared_model | ||
|
||
#endif // IROHA_ASSET_BUILDER_HPP |
Oops, something went wrong.