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.
Add create object helper (for transaction builder)
- Loading branch information
Showing
5 changed files
with
201 additions
and
86 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
core/transaction_builder/helper/create_objects_helper.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,119 @@ | ||
/* | ||
Copyright Soramitsu Co., Ltd. 2016 All Rights Reserved. | ||
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 CORE_TRANSACTION_BUILDER_CREATE_OBJECTS_HPP | ||
#define CORE_TRANSACTION_BUILDER_CREATE_OBJECTS_HPP | ||
|
||
#include <infra/protobuf/api.pb.h> | ||
#include <util/exception.hpp> | ||
|
||
namespace transaction { | ||
|
||
/* | ||
Primitives | ||
*/ | ||
|
||
inline Api::BaseObject createValueString(std::string val) { | ||
Api::BaseObject ret; | ||
ret.set_valuestring(std::move(val)); | ||
return ret; | ||
} | ||
|
||
inline Api::BaseObject createValueInt(int val) { | ||
Api::BaseObject ret; | ||
ret.set_valueint(static_cast<::google::protobuf::int64>(val)); | ||
return ret; | ||
} | ||
|
||
inline Api::BaseObject createValueBool(bool val) { | ||
Api::BaseObject ret; | ||
ret.set_valueboolean(val); | ||
return ret; | ||
} | ||
|
||
inline Api::BaseObject createValueDouble(double val) { | ||
Api::BaseObject ret; | ||
ret.set_valuedouble(val); | ||
return ret; | ||
} | ||
|
||
inline Api::Trust createTrust(double value, bool isOk) { | ||
Api::Trust ret; | ||
ret.set_value(value); | ||
ret.set_isok(isOk); | ||
return ret; | ||
} | ||
|
||
/* | ||
Map | ||
*/ | ||
|
||
using Map = std::unordered_map<std::string, Api::BaseObject>; | ||
|
||
/* | ||
Assets | ||
*/ | ||
|
||
inline Api::Domain createDomain(std::string ownerPublicKey, std::string name) { | ||
Api::Domain ret; | ||
ret.set_ownerpublickey(std::move(ownerPublicKey)); | ||
ret.set_name(std::move(name)); | ||
return ret; | ||
} | ||
|
||
inline Api::Account createAccount(std::string publicKey, std::string name, | ||
std::vector<std::string> assets) { | ||
Api::Account ret; | ||
ret.set_publickey(std::move(publicKey)); | ||
ret.set_name(std::move(name)); | ||
*ret.mutable_assets() = ::google::protobuf::RepeatedPtrField<std::string>( | ||
assets.begin(), assets.end()); | ||
return ret; | ||
} | ||
|
||
inline Api::Asset createAsset(std::string domain, std::string name, | ||
::transaction::Map value, | ||
std::string smartContractName) { | ||
Api::Asset ret; | ||
ret.set_domain(std::move(domain)); | ||
ret.set_name(std::move(name)); | ||
*ret.mutable_value() = ::google::protobuf::Map<std::string, Api::BaseObject>( | ||
value.begin(), value.end()); | ||
ret.set_smartcontractname(std::move(smartContractName)); | ||
return ret; | ||
} | ||
|
||
inline Api::SimpleAsset createSimpleAsset(std::string domain, std::string name, | ||
Api::BaseObject value, | ||
std::string smartContractName) { | ||
Api::SimpleAsset ret; | ||
ret.set_domain(std::move(domain)); | ||
ret.set_name(std::move(name)); | ||
*ret.mutable_value() = std::move(value); | ||
ret.set_smartcontractname(std::move(smartContractName)); | ||
return ret; | ||
} | ||
|
||
inline Api::Peer createPeer(std::string publicKey, std::string address, | ||
Api::Trust trust) { | ||
Api::Peer ret; | ||
ret.set_publickey(std::move(publicKey)); | ||
ret.set_address(std::move(address)); | ||
*ret.mutable_trust() = std::move(trust); | ||
return ret; | ||
} | ||
} | ||
#endif |
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
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
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
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