Skip to content

Commit

Permalink
479: Implement NetworkVersionInfoQuery (#483)
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Walworth <[email protected]>
Co-authored-by: Deyan Zhekov <[email protected]>
  • Loading branch information
rwalworth and deyanzz authored Sep 1, 2023
1 parent d805f95 commit 6dbc639
Show file tree
Hide file tree
Showing 17 changed files with 872 additions and 8 deletions.
3 changes: 3 additions & 0 deletions sdk/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ add_library(${PROJECT_NAME} STATIC
src/LedgerId.cc
src/Mnemonic.cc
src/MnemonicBIP39.cc
src/NetworkVersionInfo.cc
src/NetworkVersionInfoQuery.cc
src/NftId.cc
src/PrivateKey.cc
src/PublicKey.cc
Expand All @@ -76,6 +78,7 @@ add_library(${PROJECT_NAME} STATIC
src/ScheduleInfo.cc
src/ScheduleInfoQuery.cc
src/ScheduleSignTransaction.cc
src/SemanticVersion.cc
src/StakingInfo.cc
src/Status.cc
src/SubscriptionHandle.cc
Expand Down
95 changes: 95 additions & 0 deletions sdk/main/include/NetworkVersionInfo.h
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_
83 changes: 83 additions & 0 deletions sdk/main/include/NetworkVersionInfoQuery.h
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_
131 changes: 131 additions & 0 deletions sdk/main/include/SemanticVersion.h
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_
1 change: 1 addition & 0 deletions sdk/main/include/TransferTransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class TransferTransaction : public Transaction<TransferTransaction>
friend class ContractInfoQuery;
friend class FileContentsQuery;
friend class FileInfoQuery;
friend class NetworkVersionInfoQuery;
friend class ScheduleInfoQuery;
friend class TokenInfoQuery;
friend class TokenNftInfoQuery;
Expand Down
6 changes: 6 additions & 0 deletions sdk/main/include/impl/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <proto/crypto_service.grpc.pb.h>
#include <proto/file_service.grpc.pb.h>
#include <proto/freeze_service.grpc.pb.h>
#include <proto/network_service.grpc.pb.h>
#include <proto/schedule_service.grpc.pb.h>
#include <proto/smart_contract_service.grpc.pb.h>
#include <proto/token_service.grpc.pb.h>
Expand Down Expand Up @@ -202,6 +203,11 @@ class Node
*/
std::unique_ptr<proto::FreezeService::Stub> mFreezeStub = nullptr;

/**
* Pointer to the gRPC stub used to communicate with the network service living on the remote node.
*/
std::unique_ptr<proto::NetworkService::Stub> mNetworkStub = nullptr;

/**
* Pointer to the gRPC stub used to communicate with the schedule service living on the remote node.
*/
Expand Down
3 changes: 3 additions & 0 deletions sdk/main/src/Executable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include "FileInfoQuery.h"
#include "FileUpdateTransaction.h"
#include "FreezeTransaction.h"
#include "NetworkVersionInfo.h"
#include "NetworkVersionInfoQuery.h"
#include "ScheduleCreateTransaction.h"
#include "ScheduleDeleteTransaction.h"
#include "ScheduleInfo.h"
Expand Down Expand Up @@ -378,6 +380,7 @@ template class Executable<FileDeleteTransaction, proto::Transaction, proto::Tran
template class Executable<FileInfoQuery, proto::Query, proto::Response, FileInfo>;
template class Executable<FileUpdateTransaction, proto::Transaction, proto::TransactionResponse, TransactionResponse>;
template class Executable<FreezeTransaction, proto::Transaction, proto::TransactionResponse, TransactionResponse>;
template class Executable<NetworkVersionInfoQuery, proto::Query, proto::Response, NetworkVersionInfo>;
template class Executable<ScheduleCreateTransaction,
proto::Transaction,
proto::TransactionResponse,
Expand Down
Loading

0 comments on commit 6dbc639

Please sign in to comment.