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
11 changes: 10 additions & 1 deletion src/tck/include/file/FileService.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Hiero::TCK::FileService
* Forward declarations.
*/
struct CreateFileParams;
struct DeleteFileParams;
struct UpdateFileParams;

/**
Expand All @@ -20,6 +21,14 @@ struct UpdateFileParams;
*/
nlohmann::json createFile(const CreateFileParams& params);

/**
* 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);

/**
* Update a file.
*
Expand All @@ -30,4 +39,4 @@ nlohmann::json updateFile(const UpdateFileParams& params);

} // namespace Hiero::TCK::FileService

#endif // HIERO_TCK_CPP_FILE_SERVICE_H_
#endif // HIERO_TCK_CPP_FILE_SERVICE_H_
56 changes: 56 additions & 0 deletions src/tck/include/file/params/DeleteFileParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: Apache-2.0
#ifndef HIERO_TCK_CPP_DELETE_FILE_PARAMS_H_
#define HIERO_TCK_CPP_DELETE_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 a `deleteFile` JSON-RPC method call.
*/
struct DeleteFileParams
{
/**
* The ID of the file to delete.
*/
std::optional<std::string> mFileId;

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

} // namespace Hiero::TCK::FileService

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

} // namespace nlohmann

#endif // HIERO_TCK_CPP_DELETE_FILE_PARAMS_H_
4 changes: 4 additions & 0 deletions src/tck/src/TckServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "account/params/UpdateAccountParams.h"
#include "file/FileService.h"
#include "file/params/CreateFileParams.h"
#include "file/params/DeleteFileParams.h"
#include "file/params/UpdateFileParams.h"
#include "key/KeyService.h"
#include "key/params/GenerateKeyParams.h"
Expand Down Expand Up @@ -95,6 +96,7 @@ TckServer::TckServer(int port)

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

setupHttpHandler();
Expand Down Expand Up @@ -207,6 +209,8 @@ template TckServer::MethodHandle TckServer::getHandle<TokenService::ClaimAirdrop
nlohmann::json (*method)(const TokenService::ClaimAirdropParams&));
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::UpdateFileParams>(
nlohmann::json (*method)(const FileService::UpdateFileParams&));

Expand Down
27 changes: 26 additions & 1 deletion src/tck/src/file/FileService.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
#include "file/FileService.h"
#include "file/params/CreateFileParams.h"
#include "file/params/DeleteFileParams.h"
#include "file/params/UpdateFileParams.h"
#include "key/KeyService.h"
#include "sdk/SdkClient.h"
#include "json/JsonErrorType.h"
#include "json/JsonRpcException.h"

#include <FileCreateTransaction.h>
#include <FileDeleteTransaction.h>
#include <FileId.h>
#include <FileUpdateTransaction.h>
#include <Key.h>
Expand Down Expand Up @@ -76,6 +78,29 @@ nlohmann::json createFile(const CreateFileParams& params)
};
}

//-----
nlohmann::json deleteFile(const DeleteFileParams& params)
{
FileDeleteTransaction fileDeleteTransaction;
fileDeleteTransaction.setGrpcDeadline(SdkClient::DEFAULT_TCK_REQUEST_TIMEOUT);

if (params.mFileId.has_value())
{
fileDeleteTransaction.setFileId(FileId::fromString(params.mFileId.value()));
}

if (params.mCommonTxParams.has_value())
{
params.mCommonTxParams->fillOutTransaction(fileDeleteTransaction, SdkClient::getClient());
}

return {
{"status",
gStatusToString.at(
fileDeleteTransaction.execute(SdkClient::getClient()).getReceipt(SdkClient::getClient()).mStatus)}
};
}

//-----
nlohmann::json updateFile(const UpdateFileParams& params)
{
Expand Down Expand Up @@ -128,4 +153,4 @@ nlohmann::json updateFile(const UpdateFileParams& params)
};
}

} // namespace Hiero::TCK::FileService
} // namespace Hiero::TCK::FileService
Loading