-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
479: Implement
NetworkVersionInfoQuery
(#483)
Signed-off-by: Rob Walworth <[email protected]> Co-authored-by: Deyan Zhekov <[email protected]>
- Loading branch information
Showing
17 changed files
with
872 additions
and
8 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
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,95 @@ | ||
/*- | ||
* | ||
* Hedera C++ SDK | ||
* | ||
* Copyright (C) 2020 - 2022 Hedera Hashgraph, LLC | ||
* | ||
* 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 HEDERA_SDK_CPP_NETWORK_VERSION_INFO_H_ | ||
#define HEDERA_SDK_CPP_NETWORK_VERSION_INFO_H_ | ||
|
||
#include "SemanticVersion.h" | ||
|
||
#include <cstddef> | ||
#include <memory> | ||
#include <vector> | ||
|
||
namespace proto | ||
{ | ||
class NetworkGetVersionInfoResponse; | ||
} | ||
|
||
namespace Hedera | ||
{ | ||
/** | ||
* Contains information about the network's version. | ||
*/ | ||
class NetworkVersionInfo | ||
{ | ||
public: | ||
NetworkVersionInfo() = default; | ||
|
||
/** | ||
* Construct from a protobuf schema SemanticVersion and a Hedera services SemanticVersion. | ||
* | ||
* @param hapi The SemanticVersion of the protobuf schema. | ||
* @param hedera The SemanticVersion of the Hedera services. | ||
*/ | ||
NetworkVersionInfo(const SemanticVersion& hapi, const SemanticVersion& hedera); | ||
|
||
/** | ||
* Construct a NetworkVersionInfo object from a NetworkGetVersionInfoResponse protobuf object. | ||
* | ||
* @param proto The NetworkGetVersionInfoResponse protobuf object from which to construct a NetworkVersionInfo object. | ||
* @return The constructed NetworkVersionInfo object. | ||
*/ | ||
[[nodiscard]] static NetworkVersionInfo fromProtobuf(const proto::NetworkGetVersionInfoResponse& proto); | ||
|
||
/** | ||
* Construct a NetworkVersionInfo object from a byte array. | ||
* | ||
* @param bytes The byte array from which to construct a NetworkVersionInfo object. | ||
* @return The constructed NetworkVersionInfo object. | ||
*/ | ||
[[nodiscard]] static NetworkVersionInfo fromBytes(const std::vector<std::byte>& bytes); | ||
|
||
/** | ||
* Construct a NetworkGetVersionInfoResponse protobuf object from this NetworkVersionInfo object. | ||
* | ||
* @return A pointer to the created NetworkVersionInfo protobuf object. | ||
*/ | ||
[[nodiscard]] std::unique_ptr<proto::NetworkGetVersionInfoResponse> toProtobuf() const; | ||
|
||
/** | ||
* Construct a representative byte array from this NetworkVersionInfo object. | ||
* | ||
* @return The byte array representing this NetworkVersionInfo object. | ||
*/ | ||
[[nodiscard]] std::vector<std::byte> toBytes() const; | ||
|
||
/** | ||
* The version of the protobuf schema in use by the network. | ||
*/ | ||
SemanticVersion mProtobufVersion; | ||
|
||
/** | ||
* The version of the Hedera services in use by the network. | ||
*/ | ||
SemanticVersion mServicesVersion; | ||
}; | ||
|
||
} // namespace Hedera | ||
|
||
#endif // HEDERA_SDK_CPP_NETWORK_VERSION_INFO_H_ |
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,83 @@ | ||
/*- | ||
* | ||
* Hedera C++ SDK | ||
* | ||
* Copyright (C) 2020 - 2022 Hedera Hashgraph, LLC | ||
* | ||
* 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 HEDERA_SDK_CPP_NETWORK_VERSION_INFO_QUERY_H_ | ||
#define HEDERA_SDK_CPP_NETWORK_VERSION_INFO_QUERY_H_ | ||
|
||
#include "Query.h" | ||
|
||
namespace Hedera | ||
{ | ||
class NetworkVersionInfo; | ||
} | ||
|
||
namespace Hedera | ||
{ | ||
/** | ||
* Get the deployed versions of Hedera Services and the HAPI proto in semantic version format. | ||
*/ | ||
class NetworkVersionInfoQuery : public Query<NetworkVersionInfoQuery, NetworkVersionInfo> | ||
{ | ||
private: | ||
/** | ||
* Derived from Executable. Construct a Query protobuf object from this NetworkVersionInfoQuery object. | ||
* | ||
* @param client The Client trying to construct this NetworkVersionInfoQuery. | ||
* @param node The Node to which this NetworkVersionInfoQuery will be sent. | ||
* @return A Query protobuf object filled with this NetworkVersionInfoQuery object's data. | ||
*/ | ||
[[nodiscard]] proto::Query makeRequest(const Client& client, | ||
const std::shared_ptr<internal::Node>& node) const override; | ||
|
||
/** | ||
* Derived from Executable. Construct a NetworkVersionInfo object from a Response protobuf object. | ||
* | ||
* @param response The Response protobuf object from which to construct a NetworkVersionInfo object. | ||
* @return A NetworkVersionInfo object filled with the Response protobuf object's data. | ||
*/ | ||
[[nodiscard]] NetworkVersionInfo mapResponse(const proto::Response& response) const override; | ||
|
||
/** | ||
* Derived from Executable. Get the status response code for a submitted NetworkVersionInfoQuery from a Response | ||
* protobuf object. | ||
* | ||
* @param response The Response protobuf object from which to grab the NetworkVersionInfoQuery status response code. | ||
* @return The NetworkVersionInfoQuery status response code of the input Response protobuf object. | ||
*/ | ||
[[nodiscard]] Status mapResponseStatus(const proto::Response& response) const override; | ||
|
||
/** | ||
* Derived from Executable. Submit this NetworkVersionInfoQuery to a Node. | ||
* | ||
* @param client The Client submitting this NetworkVersionInfoQuery. | ||
* @param deadline The deadline for submitting this NetworkVersionInfoQuery. | ||
* @param node Pointer to the Node to which this NetworkVersionInfoQuery should be submitted. | ||
* @param response Pointer to the Response protobuf object that gRPC should populate with the response information | ||
* from the gRPC server. | ||
* @return The gRPC status of the submission. | ||
*/ | ||
[[nodiscard]] grpc::Status submitRequest(const Client& client, | ||
const std::chrono::system_clock::time_point& deadline, | ||
const std::shared_ptr<internal::Node>& node, | ||
proto::Response* response) const override; | ||
}; | ||
|
||
} // namespace Hedera | ||
|
||
#endif // HEDERA_SDK_CPP_NETWORK_VERSION_INFO_QUERY_H_ |
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,131 @@ | ||
/*- | ||
* | ||
* Hedera C++ SDK | ||
* | ||
* Copyright (C) 2020 - 2022 Hedera Hashgraph, LLC | ||
* | ||
* 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 HEDERA_SDK_CPP_SEMANTIC_VERSION_H_ | ||
#define HEDERA_SDK_CPP_SEMANTIC_VERSION_H_ | ||
|
||
#include <cstddef> | ||
#include <memory> | ||
#include <string> | ||
#include <string_view> | ||
#include <vector> | ||
|
||
namespace proto | ||
{ | ||
class SemanticVersion; | ||
} | ||
|
||
namespace Hedera | ||
{ | ||
/** | ||
* Hedera follows semantic versioning for both the HAPI protobufs and the Services software. This type allows the | ||
* getVersionInfo query in the NetworkService to return the deployed versions of both protobufs and software on the node | ||
* answering the query. | ||
*/ | ||
class SemanticVersion | ||
{ | ||
public: | ||
SemanticVersion() = default; | ||
|
||
/** | ||
* Construct from a major, minor, and patch number. | ||
* | ||
* @param major The major number. | ||
* @param minor The minor number. | ||
* @param patch The patch number. | ||
* @param pre The pre-release version number. | ||
* @param build The build metadata. | ||
*/ | ||
SemanticVersion(int major, int minor, int patch, std::string_view pre = "", std::string_view build = ""); | ||
|
||
/** | ||
* Compare this SemanticVersion to another SemanticVersion and determine if they represent the same semantic version. | ||
* | ||
* @param other The other SemanticVersion with which to compare this SemanticVersion. | ||
* @return \c TRUE if this SemanticVersion is the same as the input SemanticVersion, otherwise \c FALSE. | ||
*/ | ||
bool operator==(const SemanticVersion& other) const; | ||
|
||
/** | ||
* Construct a SemanticVersion object from a SemanticVersion protobuf object. | ||
* | ||
* @param proto The SemanticVersion protobuf object from which to construct a SemanticVersion object. | ||
* @return The constructed SemanticVersion object. | ||
*/ | ||
[[nodiscard]] static SemanticVersion fromProtobuf(const proto::SemanticVersion& proto); | ||
|
||
/** | ||
* Construct a SemanticVersion object from a byte array. | ||
* | ||
* @param bytes The byte array representing a SemanticVersion object. | ||
* @return The constructed SemanticVersion object. | ||
*/ | ||
[[nodiscard]] static SemanticVersion fromBytes(const std::vector<std::byte>& bytes); | ||
|
||
/** | ||
* Construct a SemanticVersion protobuf object from this SemanticVersion object. | ||
* | ||
* @return A pointer to the created SemanticVersion protobuf object. | ||
*/ | ||
[[nodiscard]] std::unique_ptr<proto::SemanticVersion> toProtobuf() const; | ||
|
||
/** | ||
* Construct a representative byte array from this SemanticVersion object. | ||
* | ||
* @return The byte array representing this SemanticVersion object. | ||
*/ | ||
[[nodiscard]] std::vector<std::byte> toBytes() const; | ||
|
||
/** | ||
* Construct a string representation of this SemanticVersion object. | ||
* | ||
* @return The string representation of this SemanticVersion object. | ||
*/ | ||
[[nodiscard]] std::string toString() const; | ||
|
||
/** | ||
* Major number. Increases with incompatible API changes. | ||
*/ | ||
int mMajor = 0; | ||
|
||
/** | ||
* Minor number. Increases with backwards-compatible new functionality. | ||
*/ | ||
int mMinor = 0; | ||
|
||
/** | ||
* Patch number. Increases with backwards-compatible bug fixes. | ||
*/ | ||
int mPatch = 0; | ||
|
||
/** | ||
* Pre-release version. This may be denoted by appending a hyphen and a series of dot-separated identifiers. | ||
*/ | ||
std::string mPre; | ||
|
||
/** | ||
* Build metadata. This may be denoted by appending a plus sign and a series of dot-separated identifiers immediately | ||
* following the patch or pre-release version. | ||
*/ | ||
std::string mBuild; | ||
}; | ||
|
||
} // namespace Hedera | ||
|
||
#endif // HEDERA_SDK_CPP_SEMANTIC_VERSION_H_ |
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
Oops, something went wrong.