Skip to content

Commit

Permalink
Merge branch 'main' into 00488-add-accountcreatewithhtsexample
Browse files Browse the repository at this point in the history
  • Loading branch information
rwalworth committed Aug 30, 2023
2 parents 2d181e2 + 6922309 commit ed73ff7
Show file tree
Hide file tree
Showing 46 changed files with 2,437 additions and 92 deletions.
2 changes: 1 addition & 1 deletion sdk/examples/ConsensusPubSubExample.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Hedera C++ SDK
*
* Copyright (C) 2020 - 2022 Hedera Hashgraph, LLC
* Copyright (C) 2020 - 2023 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.
Expand Down
4 changes: 4 additions & 0 deletions sdk/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ add_library(${PROJECT_NAME} STATIC
src/FileInfo.cc
src/FileInfoQuery.cc
src/FileUpdateTransaction.cc
src/FreezeTransaction.cc
src/FreezeType.cc
src/HbarAllowance.cc
src/HbarTransfer.cc
src/Key.cc
Expand All @@ -77,6 +79,8 @@ add_library(${PROJECT_NAME} STATIC
src/StakingInfo.cc
src/Status.cc
src/SubscriptionHandle.cc
src/SystemDeleteTransaction.cc
src/SystemUndeleteTransaction.cc
src/TokenAllowance.cc
src/TokenAssociateTransaction.cc
src/TokenAssociation.cc
Expand Down
195 changes: 195 additions & 0 deletions sdk/main/include/FreezeTransaction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*-
*
* Hedera C++ SDK
*
* Copyright (C) 2020 - 2023 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_FREEZE_TRANSACTION_H_
#define HEDERA_SDK_CPP_FREEZE_TRANSACTION_H_

#include "FileId.h"
#include "FreezeType.h"
#include "Transaction.h"

#include <chrono>
#include <cstddef>
#include <optional>
#include <vector>

namespace proto
{
class FreezeTransactionBody;
class TransactionBody;
}

namespace Hedera
{
/**
*
* At consensus, sets the consensus time at which the platform should stop creating events and accepting transactions,
* and enter a maintenance window.
*
* Transaction Signing Requirements:
* - The key(s) on the file are required to sign the transaction.
*/
class FreezeTransaction : public Transaction<FreezeTransaction>
{
public:
FreezeTransaction() = default;

/**
* Construct from a TransactionBody protobuf object.
*
* @param transactionBody The TransactionBody protobuf object from which to construct.
* @throws std::invalid_argument If the input TransactionBody does not represent a Freeze transaction.
*/
explicit FreezeTransaction(const proto::TransactionBody& transactionBody);

/**
* Set the ID of the file to use for the network software upgrade.
*
* @param fileId The ID of the file to use for the network software upgrade.
* @return A reference to this FreezeTransaction object with the newly-set file ID.
* @throws IllegalStateException If this FreezeTransaction is frozen.
*/
FreezeTransaction& setFileId(const FileId& fileId);

/**
* Set the expected hash of the contents of the update file.
*
* @param hash The expected hash of the contents of the update file.
* @return A reference to this FreezeTransaction object with the newly-set file hash.
* @throws IllegalStateException If this FreezeTransaction is frozen.
*/
FreezeTransaction& setFileHash(const std::vector<std::byte>& hash);

/**
* Set the consensus time at which the maintenance window should begin.
*
* @param time The consensus time at which the maintenance window should begin.
* @return A reference to this FreezeTransaction object with the newly-set start time.
* @throws IllegalStateException If this FreezeTransaction is frozen.
*/
FreezeTransaction& setStartTime(const std::chrono::system_clock::time_point& time);

/**
* Set the type of network freeze or upgrade operation to perform.
*
* @param type The type of network freeze or upgrade operation to perform.
* @return A reference to this FreezeTransaction object with the newly-set freeze type.
* @throws IllegalStateException If this FreezeTransaction is frozen.
*/
FreezeTransaction& setFreezeType(const FreezeType& type);

/**
* Get the ID of the file to use for the network software upgrade.
*
* @return The ID of the file to use for the network software upgrade. Returns uninitialized if the file ID has not
* been set.
*/
[[nodiscard]] inline std::optional<FileId> getFileId() const { return mFileId; }

/**
* Get the expected hash of the contents of the update file.
*
* @return The expected hash of the contents of the update file.
*/
[[nodiscard]] inline std::vector<std::byte> getFileHash() const { return mFileHash; }

/**
* Get the consensus time at which the maintenance window should begin.
*
* @return The consensus time at which the maintenance window should begin.Returns uninitialized if the start time has
* not been set.
*/
[[nodiscard]] inline std::optional<std::chrono::system_clock::time_point> getStartTime() const { return mStartTime; }

/**
* Get the type of network freeze or upgrade operation to perform.
*
* @return The type of network freeze or upgrade operation to perform.
*/
[[nodiscard]] inline FreezeType getFreezeType() const { return mFreezeType; }

private:
friend class WrappedTransaction;

/**
* Derived from Executable. Construct a Transaction protobuf object from this FreezeTransaction object.
*
* @param client The Client trying to construct this FreezeTransaction.
* @param node The Node to which this FreezeTransaction will be sent. This is unused.
* @return A Transaction protobuf object filled with this FreezeTransaction object's data.
* @throws UninitializedException If the input client has no operator with which to sign this
* FreezeTransaction.
*/
[[nodiscard]] proto::Transaction makeRequest(const Client& client,
const std::shared_ptr<internal::Node>& /*node*/) const override;

/**
* Derived from Executable. Submit this FreezeTransaction to a Node.
*
* @param client The Client submitting this FreezeTransaction.
* @param deadline The deadline for submitting this FreezeTransaction.
* @param node Pointer to the Node to which this FreezeTransaction should be submitted.
* @param response Pointer to the TransactionResponse 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::TransactionResponse* response) const override;
/**
* Derived from Transaction. Build and add the FreezeTransaction protobuf representation to the Transaction
* protobuf object.
*
* @param body The TransactionBody protobuf object being built.
*/
void addToBody(proto::TransactionBody& body) const override;

/**
* Build a FreezeTransactionBody protobuf object from this FreezeTransaction object.
*
* @return A pointer to a FreezeTransactionBody protobuf object filled with this FreezeTransaction object's
* data.
*/
[[nodiscard]] proto::FreezeTransactionBody* build() const;

/**
* The ID of the file to use for the network software upgrade.
*/
std::optional<FileId> mFileId;

/**
* The expected hash of the contents of the update file.
*/
std::vector<std::byte> mFileHash;

/**
* The consensus time at which the maintenance window should begin.
*/
std::optional<std::chrono::system_clock::time_point> mStartTime;

/**
* The type of network freeze or upgrade operation to perform.
*/
FreezeType mFreezeType = FreezeType::UNKNOWN_FREEZE_TYPE;
};

} // namespace Hedera

#endif // HEDERA_SDK_CPP_FREEZE_TRANSACTION_H_
88 changes: 88 additions & 0 deletions sdk/main/include/FreezeType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*-
*
* Hedera C++ SDK
*
* Copyright (C) 2020 - 2023 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_FREEZE_TYPE_H_
#define HEDERA_SDK_CPP_FREEZE_TYPE_H_

#include <string_view>
#include <unordered_map>

namespace proto
{
enum FreezeType : int;
}

namespace Hedera
{
/**
* The type of network freeze or upgrade operation to be performed. This type dictates which fields are required.
*/
enum class FreezeType
{
/**
* An (invalid) default value for this enum, to ensure the client explicitly sets the intended type of freeze
* transaction.
*/
UNKNOWN_FREEZE_TYPE,
/**
* Freezes the network at the specified time. The start time field must be provided and must reference a future time.
* Any values specified for the update file and file hash fields will be ignored. This transaction does not perform
* any network changes or upgrades and requires manual intervention to restart the network.
*/
FREEZE_ONLY,
/**
* A non-freezing operation that initiates network wide preparation in advance of a scheduled freeze upgrade. The
* update_file and file_hash fields must be provided and valid. The start_time field may be omitted and any value
* present will be ignored.
*/
PREPARE_UPGRADE,
/**
* Freezes the network at the specified time and performs the previously prepared automatic upgrade across the entire
* network.
*/
FREEZE_UPGRADE,
/**
* Aborts a pending network freeze operation.
*/
FREEZE_ABORT,
/**
* Performs an immediate upgrade on auxiliary services and containers providing telemetry/metrics. Does not impact
* network operations.
*/
TELEMETRY_UPGRADE
};

/**
* Map of protobuf FreezeTypes to the corresponding FreezeType.
*/
extern const std::unordered_map<proto::FreezeType, FreezeType> gProtobufFreezeTypeToFreezeType;

/**
* Map of FreezeTypes to the corresponding protobuf FreezeType.
*/
extern const std::unordered_map<FreezeType, proto::FreezeType> gFreezeTypeToProtobufFreezeType;

/**
* Map of FreezeType to its corresponding string.
*/
[[maybe_unused]] extern const std::unordered_map<FreezeType, const char*> gFreezeTypeToString;

} // namespace Hedera

#endif // HEDERA_SDK_CPP_FREEZE_TYPE_H_
2 changes: 1 addition & 1 deletion sdk/main/include/SubscriptionHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Hedera C++ SDK
*
* Copyright (C) 2020 - 2022 Hedera Hashgraph, LLC
* Copyright (C) 2020 - 2023 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.
Expand Down
Loading

0 comments on commit ed73ff7

Please sign in to comment.