Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/tck/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_executable(${TCK_SERVER_NAME}
src/key/KeyService.cc
src/sdk/SdkClient.cc
src/token/TokenService.cc
src/topic/TopicService.cc
src/main.cc
src/TckServer.cc)

Expand Down
51 changes: 51 additions & 0 deletions src/tck/include/topic/TopicService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: Apache-2.0
#ifndef HIERO_TCK_CPP_TOPIC_SERVICE_H_
#define HIERO_TCK_CPP_TOPIC_SERVICE_H_

#include <nlohmann/json_fwd.hpp>

namespace Hiero::TCK::TopicService
{
/**
* Forward declarations.
*/
struct CreateTopicParams;
struct DeleteTopicParams;
struct GetTopicInfoQueryParams;
struct TopicMessageSubmitParams;

/**
* Create a topic.
*
* @param params The parameters to use to create a topic.
* @return A JSON response containing the status of the topic creation and the new topic's ID.
*/
nlohmann::json createTopic(const CreateTopicParams& params);

/**
* Delete a topic
*
* @param params The parameters to use to delete a topic.
* @return A json response containing the status of the deletion of the topic.
*/
nlohmann::json deleteTopic(const DeleteTopicParams& params);

/**
* Get topic info.
*
* @param params The parameters to use to get info of a topic.
* @return A JSON response containing the status of the topic info.
*/
nlohmann::json getTopicInfo(const GetTopicInfoQueryParams& params);

/**
* Submit a topic message.
*
* @param params The parameters to use to submit a topic message.
* @return A JSON response containing the status of the submission of the topic message.
*/
nlohmann::json submitTopicMessage(const TopicMessageSubmitParams& params);

} // namespace Hiero::TCK::TopicService

#endif // HIERO_TCK_CPP_TOPIC_SERVICE_H_
116 changes: 116 additions & 0 deletions src/tck/include/topic/params/CreateTopicParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// SPDX-License-Identifier: Apache-2.0
#ifndef HIERO_TCK_CPP_CREATE_TOPIC_PARAMS_H_
#define HIERO_TCK_CPP_CREATE_TOPIC_PARAMS_H_

#include "common/CommonTransactionParams.h"
#include "nlohmann/json.hpp"

#include "token/CustomFeeSerializer.h"

#include "json/JsonUtils.h"
#include <optional>
#include <string>
#include <vector>

namespace Hiero::TCK::TopicService
{
/**
* Struct to hold the arguments for a `createTopic` JSON-RPC method call.
*/
struct CreateTopicParams
{
/**
* Short publicly visible memo about the topic. No guarantee of uniqueness. (UTF-8 encoding max 100 bytes)
*/
std::optional<std::string> mMemo;

/**
* Access control for update/delete of the topic. DER-encoded hex string representation for private or public keys.
* Keylists and threshold keys are the hex of the serialized protobuf bytes.
*/
std::optional<std::string> mAdminKey;

/**
* Access control for submit message. DER-encoded hex string representation for private or public keys. Keylists and
* threshold keys are the hex of the serialized protobuf bytes.
*/
std::optional<std::string> mSubmitKey;

/**
* The amount of time to attempt to extend the topic's lifetime by automatically at the topic's expirationTime. Units
* of seconds. Min: 6999999 (≈30 days), Max: 8000001 (≈92 days)
*/
std::string mAutoRenewPeriod;

/**
* Optional account to be used at the topic's expirationTime to extend the life of the topic. Must sign transaction if
* specified.
*/
std::optional<std::string> mAutoRenewAccount;

/**
* A key that controls updates and deletions of topic fees. DER-encoded hex string representation for private or
* public keys. Keylists and threshold keys are the hex of the serialized protobuf bytes.
*/
std::optional<std::string> mFeeScheduleKey;

/**
* A list of keys that, if used to sign a message submission, allow the sender to bypass fees. DER-encoded hex string
* representation for private or public keys.
*/
std::optional<std::vector<std::string>> mFeeExemptKeys;

/**
* A fee structure applied to message submissions for revenue generation.
*/
std::optional<std::vector<std::shared_ptr<CustomFee>>> mCustomFees;

/**
* Any parameters common to all transaction types.
*/
std::optional<CommonTransactionParams> mCommonTxParams;
};

} // namespace Hiero::TCK::TopicService

namespace nlohmann
{
/**
* JSON serializer template specialization required to convert CreateTopicParams arguments properly.
*/
template<>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::TopicService::CreateTopicParams>
{
/**
* Convert a Json Object to a CreateTopicParams
*
* @param jsonFrom The json object which will fill the CreateTopicParams.
* @param params The CreateTopicParam to fill the json object.
*/
static void from_json(const json& jsonFrom, Hiero::TCK::TopicService::CreateTopicParams& params)
{
params.mMemo = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "memo");

params.mAdminKey = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "adminKey");

params.mSubmitKey = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "submitKey");

params.mAutoRenewPeriod = Hiero::TCK::getRequiredJsonParameter<std::string>(jsonFrom, "autoRenewPeriod");

params.mAutoRenewAccount = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "autoRenewAccount");

params.mFeeScheduleKey = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "feeScheduleKey");

params.mFeeExemptKeys = Hiero::TCK::getOptionalJsonParameter<std::vector<std::string>>(jsonFrom, "feeExemptKeys");

params.mCustomFees =
Hiero::TCK::getOptionalJsonParameter<std::vector<std::shared_ptr<Hiero::CustomFee>>>(jsonFrom, "customFees");

params.mCommonTxParams =
Hiero::TCK::getOptionalJsonParameter<Hiero::TCK::CommonTransactionParams>(jsonFrom, "commonTransactionParams");
}
};

} // namespace nlohmann

#endif // HIERO_TCK_CPP_CREATE_TOPIC_PARAMS_H_
57 changes: 57 additions & 0 deletions src/tck/include/topic/params/DeleteTopicParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: Apache-2.0
#ifndef HIERO_TCK_CPP_DELETE_TOPIC_PARAMS_H_
#define HIERO_TCK_CPP_DELETE_TOPIC_PARAMS_H_

#include "common/CommonTransactionParams.h"
#include "nlohmann/json.hpp"

#include "json/JsonUtils.h"
#include <optional>
#include <string>

namespace Hiero::TCK::TopicService
{
/**
* Struct to hold the arguments for a `deleteTopic` Json-RPC method call.
*/
struct DeleteTopicParams
{
/**
* The ID of the topic to delete.
*/
std::optional<std::string> mTopicId;

/**
* Any parameters common to all transaction types.
*/
std::optional<CommonTransactionParams> mCommonTxParams;
};

} // namespace Hiero::TCK::TopicService

namespace nlohmann
{
/**
* JSON serializer template specialisation required to convert DeleteTopicParams argument properly.
*/
template<>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::TopicService::DeleteTopicParams>
{
/**
* Convert a JSON object to a DeleteTopicParams.
*
* @param jsonFrom The JSON object with which to fill the DeleteTopicParams.
* @param params The DeleteTopicParams to fill with the JSON object.
*/
static void from_json(const json& jsonFrom, Hiero::TCK::TopicService::DeleteTopicParams& params)
{
params.mTopicId = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "topicId");

params.mCommonTxParams =
Hiero::TCK::getOptionalJsonParameter<Hiero::TCK::CommonTransactionParams>(jsonFrom, "commonTransactionParams");
}
};

} // namespace nlohmann

#endif // HIERO_TCK_CPP_DELETE_TOPIC_PARAMS_H_
62 changes: 62 additions & 0 deletions src/tck/include/topic/params/GetTopicInfoQueryParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: Apache-2.0
#ifndef HIERO_TCK_CPP_GET_TOPIC_INFO_QUERY_PARAMS_H_
#define HIERO_TCK_CPP_GET_TOPIC_INFO_QUERY_PARAMS_H_

#include "nlohmann/json.hpp"

#include "json/JsonUtils.h"
#include <optional>
#include <string>

namespace Hiero::TCK::TopicService
{
/**
* Struct to hold the arguments for a `getTopicInfo` Json-RPC method call
*/
struct GetTopicInfoQueryParams
{
/**
* The ID of the topic to query.
*/
std::optional<std::string> mTopicId;

/**
* Explicit payment amount for the query in tinybars.
*/
std::optional<std::string> mQueryPayment;

/**
* Maximum payment amount for the query in tinybars.
*/
std::optional<std::string> mMaxQueryPayment;
};

} // namespace Hiero::TCK::TopicService

namespace nlohmann
{
/**
* JSON serializer template specialisation required to convert GetTopicInfoQueryParams arguments properly.
*/
template<>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::TopicService::GetTopicInfoQueryParams>
{
/**
* Convert a Json Object to a GetTopicInfoQueryParams
*
* @param jsonFrom The json object which will fill the GetTopicInfoQueryParams.
* @param params The GetTopicInfoQueryParams to fill the json object.
*/
static void from_json(const json& jsonFrom, Hiero::TCK::TopicService::GetTopicInfoQueryParams& params)
{
params.mTopicId = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "topicId");

params.mQueryPayment = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "queryPayment");

params.mMaxQueryPayment = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "maxQueryPayment");
}
};

} // namespace nlohmann

#endif // HIERO_TCK_CPP_GET_TOPIC_INFO_QUERY_PARAMS_H_
71 changes: 71 additions & 0 deletions src/tck/include/topic/params/TopicMessageSubmitParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: Apache-2.0
#ifndef HIERO_TCK_CPP_TOPIC_MESSAGE_SUBMIT_PARAMS_H_
#define HIERO_TCK_CPP_TOPIC_MESSAGE_SUBMIT_PARAMS_H_

#include "common/CommonTransactionParams.h"
#include "nlohmann/json.hpp"

#include "json/JsonUtils.h"
#include <optional>
#include <string>

namespace Hiero::TCK::TopicService
{
/**
* Struct to hold the arguments for a `submitTopicMessage` JSON-RPC method call
*/
struct TopicMessageSubmitParams
{
/**
* The ID of the topic to submit the message to.
*/
std::optional<std::string> mTopicId;

/**
* The message content to submit. UTF-8 encoding. Will be automatically chunked if the message exceeds the chunk size.
*/
std::optional<std::string> mMessage;

/**
* The maximum number of chunks the message can be split into. Default: 20. Used when message size exceeds chunk size.
*/
std::optional<int> mMaxChunks;

/**
* Any parameters common to all transaction types.
*/
std::optional<CommonTransactionParams> mCommonTxParams;
};

} // namespace Hiero::TCK::TopicService

namespace nlohmann
{
/**
* Json serializer template specialisation required to convert TopicMessageSubmitParams argument properly
*/
template<>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::TopicService::TopicMessageSubmitParams>
{
/**
* Convert a Json Object to a TopicMessageSubmitParams
*
* @param jsonFrom The JSON object with which to fill the TopicMessageSubmitParams
* @param params the TopicMessageSubmitParams to fill with the JSON object.
*/
static void from_json(const json& jsonFrom, Hiero::TCK::TopicService::TopicMessageSubmitParams& params)
{
params.mTopicId = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "topicId");

params.mMessage = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "message");

params.mMaxChunks = Hiero::TCK::getOptionalJsonParameter<int>(jsonFrom, "maxChunks");

params.mCommonTxParams =
Hiero::TCK::getOptionalJsonParameter<Hiero::TCK::CommonTransactionParams>(jsonFrom, "commonTransactionParams");
}
};

} // namespace nlohmann

#endif // HIERO_TCK_CPP_TOPIC_MESSAGE_SUBMIT_PARAMS_H_
Loading
Loading