Skip to content
Merged
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
29 changes: 28 additions & 1 deletion src/tck/include/file/FileService.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@ namespace Hiero::TCK::FileService
/**
* Forward declarations.
*/
struct AppendFileParams;
struct CreateFileParams;
struct DeleteFileParams;
struct GetFileContentsParams;
struct GetFileInfoParams;
struct UpdateFileParams;

/**
* The parameters to use to append a file.
*
* @param params The parameters use to append a file.
* @return A JSON response containing the status of the appended file.
*/
nlohmann::json appendFile(const AppendFileParams& params);

/**
* Create a file.
*
Expand All @@ -22,13 +33,29 @@ struct UpdateFileParams;
nlohmann::json createFile(const CreateFileParams& params);

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

/**
* Get file contents.
*
* @param params The parameters to use to get the content of file.
* @return A JSON response containing the file contents.
*/
nlohmann::json getFileContents(const GetFileContentsParams& params);

/**
* Get file info.
*
* @param params The parameters to use to get file info.
* @return A JSON response containing the file info.
*/
nlohmann::json getFileInfo(const GetFileInfoParams& params);

/**
* Update a file.
*
Expand Down
78 changes: 78 additions & 0 deletions src/tck/include/file/params/AppendFileParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SPDX-License-Identifier: Apache-2.0
#ifndef HIERO_TCK_CPP_APPEND_FILE_PARAMS_H_
#define HIERO_TCK_CPP_APPEND_FILE_PARAMS_H_

#include "common/CommonTransactionParams.h"
#include "json/JsonUtils.h"

#include <nlohmann/json.hpp>
#include <optional>
#include <string>

namespace Hiero::TCK::FileService
{
/**
* Struct to hold the arguments for an `appendFile` JSON-RPC method call.
*/
struct AppendFileParams
{
/**
* The ID of the file to append to.
*/
std::optional<std::string> mFileId;

/**
* The contents of the file.
*/
std::string mContents;

/**
* Maximum number of chunks allowed for this transaction
*/
std::optional<int> mMaxChunks;

/**
* Size of each chunk in bytes
*/
std::optional<int> mChunkSize;

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

} // namespace Hiero::TCK::FileService

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

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

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

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

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

} // namespace nlohmann

#endif // HIERO_TCK_CPP_APPEND_FILE_PARAMS_H_
62 changes: 62 additions & 0 deletions src/tck/include/file/params/GetFileContentsParams.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_FILE_CONTENTS_PARAMS_H_
#define HIERO_TCK_CPP_GET_FILE_CONTENTS_PARAMS_H_

#include "json/JsonUtils.h"

#include <nlohmann/json.hpp>
#include <optional>
#include <string>

namespace Hiero::TCK::FileService
{
/**
* Struct to hold the arguments for a `getFileContents` JSON-RPC method call.
*/
struct GetFileContentsParams
{
/**
* The ID of the file to query.
*/
std::string mFileId;

/**
* 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::FileService

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

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_FILE_CONTENTS_PARAMS_H_
42 changes: 42 additions & 0 deletions src/tck/include/file/params/GetFileInfoParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: Apache-2.0
#ifndef HIERO_TCK_CPP_GET_FILE_INFO_PARAMS_H_
#define HIERO_TCK_CPP_GET_FILE_INFO_PARAMS_H_

#include "json/JsonUtils.h"

#include <nlohmann/json.hpp>
#include <optional>
#include <string>

namespace Hiero::TCK::FileService
{
/**
* Struct to hold the arguments for a `getFileInfo` JSON-RPC method call.
*/
struct GetFileInfoParams
{
/**
* The ID of the file to query.
*/
std::optional<std::string> mFileId;
};

} // namespace Hiero::TCK::FileService

namespace nlohmann
{
/**
* JSON serializer template specialization required to convert GetFileInfoParams arguments properly.
*/
template<>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::FileService::GetFileInfoParams>
{
static void from_json(const json& jsonFrom, Hiero::TCK::FileService::GetFileInfoParams& params)
{
params.mFileId = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "fileId");
}
};

} // namespace nlohmann

#endif // HIERO_TCK_CPP_GET_FILE_INFO_PARAMS_H_
12 changes: 12 additions & 0 deletions src/tck/src/TckServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
#include "account/params/TransferCryptoParams.h"
#include "account/params/UpdateAccountParams.h"
#include "file/FileService.h"
#include "file/params/AppendFileParams.h"
#include "file/params/CreateFileParams.h"
#include "file/params/DeleteFileParams.h"
#include "file/params/GetFileContentsParams.h"
#include "file/params/GetFileInfoParams.h"
#include "file/params/UpdateFileParams.h"
#include "key/KeyService.h"
#include "key/params/GenerateKeyParams.h"
Expand Down Expand Up @@ -95,8 +98,11 @@ TckServer::TckServer(int port)
mJsonRpcParser.addMethod("wipeToken", getHandle(TokenService::wipeToken));

// Add the FileService functions.
mJsonRpcParser.addMethod("appendFile", getHandle(FileService::appendFile));
mJsonRpcParser.addMethod("createFile", getHandle(FileService::createFile));
mJsonRpcParser.addMethod("deleteFile", getHandle(FileService::deleteFile));
mJsonRpcParser.addMethod("getFileContents", getHandle(FileService::getFileContents));
mJsonRpcParser.addMethod("getFileInfo", getHandle(FileService::getFileInfo));
mJsonRpcParser.addMethod("updateFile", getHandle(FileService::updateFile));

setupHttpHandler();
Expand Down Expand Up @@ -207,10 +213,16 @@ template TckServer::MethodHandle TckServer::getHandle<TokenService::CancelAirdro
nlohmann::json (*method)(const TokenService::CancelAirdropParams&));
template TckServer::MethodHandle TckServer::getHandle<TokenService::ClaimAirdropParams>(
nlohmann::json (*method)(const TokenService::ClaimAirdropParams&));
template TckServer::MethodHandle TckServer::getHandle<FileService::AppendFileParams>(
nlohmann::json (*method)(const FileService::AppendFileParams&));
template TckServer::MethodHandle TckServer::getHandle<FileService::CreateFileParams>(
nlohmann::json (*method)(const FileService::CreateFileParams&));
template TckServer::MethodHandle TckServer::getHandle<FileService::DeleteFileParams>(
nlohmann::json (*method)(const FileService::DeleteFileParams&));
template TckServer::MethodHandle TckServer::getHandle<FileService::GetFileContentsParams>(
nlohmann::json (*method)(const FileService::GetFileContentsParams&));
template TckServer::MethodHandle TckServer::getHandle<FileService::GetFileInfoParams>(
nlohmann::json (*method)(const FileService::GetFileInfoParams&));
template TckServer::MethodHandle TckServer::getHandle<FileService::UpdateFileParams>(
nlohmann::json (*method)(const FileService::UpdateFileParams&));

Expand Down
Loading
Loading