diff --git a/src/tck/include/token/TokenService.h b/src/tck/include/token/TokenService.h index d7c2aadc4..954835b8d 100644 --- a/src/tck/include/token/TokenService.h +++ b/src/tck/include/token/TokenService.h @@ -23,6 +23,7 @@ struct UnfreezeTokenParams; struct UnpauseTokenParams; struct UpdateTokenFeeScheduleParams; struct UpdateTokenParams; +struct WipeTokenParams; /** * Associate an account with tokens. @@ -136,6 +137,14 @@ nlohmann::json updateTokenFeeSchedule(const UpdateTokenFeeScheduleParams& params */ nlohmann::json updateToken(const UpdateTokenParams& params); +/** + * Wipe a token or tokens from an account. + * + * @param params The parameters to use to wipe the token(s). + * @ return A JSON response containing the status of the token wipe. + */ +nlohmann::json wipeToken(const WipeTokenParams& params); + } // namespace Hiero::TCK::TokenService #endif // HIERO_TCK_CPP_TOKEN_SERVICE_H_ diff --git a/src/tck/include/token/params/WipeTokenParams.h b/src/tck/include/token/params/WipeTokenParams.h new file mode 100644 index 000000000..355a7e171 --- /dev/null +++ b/src/tck/include/token/params/WipeTokenParams.h @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: Apache-2.0 +#ifndef HIERO_TCK_CPP_WIPE_TOKEN_PARAMS_H_ +#define HIERO_TCK_CPP_WIPE_TOKEN_PARAMS_H_ + +#include "common/CommonTransactionParams.h" +#include "json/JsonUtils.h" + +#include +#include +#include + +namespace Hiero::TCK::TokenService +{ +/** + * Struct to hold the arguments for a `wipeToken` JSON-RPC method call. + */ +struct WipeTokenParams +{ + /** + * The ID of the token to wipe. + */ + std::optional mTokenId; + + /** + * The ID of the account from which to wipe the tokens. + */ + std::optional mAccountId; + + /** + * The amount of fungible tokens to wipe. + */ + std::optional mAmount; + + /** + * The serial numbers of the NFTs to wipe. + */ + std::optional> mSerialNumbers; + + /** + * Any parameters common to all transaction types. + */ + std::optional mCommonTxParams; +}; + +} // namespace Hedera::TCK::TokenService + +namespace nlohmann +{ +/** + * JSON serializer template specialization required to convert WipeTokenParams arguments properly. + */ +template<> +struct [[maybe_unused]] adl_serializer +{ + /** + * Convert a JSON object to a WipeTokenParams. + * + * @param jsonFrom The JSON object with which to fill the WipeTokenParams. + * @param params The WipeTokenParams to fill with the JSON object. + */ + static void from_json(const json& jsonFrom, Hiero::TCK::TokenService::WipeTokenParams& params) + { + params.mTokenId = Hiero::TCK::getOptionalJsonParameter(jsonFrom, "tokenId"); + params.mAccountId = Hiero::TCK::getOptionalJsonParameter(jsonFrom, "accountId"); + params.mAmount = Hiero::TCK::getOptionalJsonParameter(jsonFrom, "amount"); + params.mSerialNumbers = Hiero::TCK::getOptionalJsonParameter>(jsonFrom, "serialNumbers"); + params.mCommonTxParams = + Hiero::TCK::getOptionalJsonParameter(jsonFrom, "commonTransactionParams"); + } +}; + +} // namespace nlohmann + +#endif // HIERO_TCK_CPP_WIPE_TOKEN_PARAMS_H_ diff --git a/src/tck/src/TckServer.cc b/src/tck/src/TckServer.cc index 40dd06017..af079b000 100644 --- a/src/tck/src/TckServer.cc +++ b/src/tck/src/TckServer.cc @@ -26,6 +26,7 @@ #include "token/params/UnpauseTokenParams.h" #include "token/params/UpdateTokenFeeScheduleParams.h" #include "token/params/UpdateTokenParams.h" +#include "token/params/WipeTokenParams.h" #include "json/JsonErrorType.h" #include "json/JsonRpcException.h" #include "json/JsonUtils.h" @@ -397,5 +398,7 @@ template TckServer::MethodHandle TckServer::getHandle( nlohmann::json (*method)(const TokenService::UpdateTokenParams&)); +template TckServer::MethodHandle TckServer::getHandle( + nlohmann::json (*method)(const TokenService::WipeTokenParams&)); } // namespace Hiero::TCK diff --git a/src/tck/src/main.cc b/src/tck/src/main.cc index 0973827a8..3d7465ac0 100644 --- a/src/tck/src/main.cc +++ b/src/tck/src/main.cc @@ -45,6 +45,7 @@ int main(int argc, char** argv) tckServer.add("unfreezeToken", tckServer.getHandle(&TokenService::unfreezeToken)); tckServer.add("updateTokenFeeSchedule", tckServer.getHandle(&TokenService::updateTokenFeeSchedule)); tckServer.add("updateToken", tckServer.getHandle(&TokenService::updateToken)); + tckServer.add("wipeToken", tckServer.getHandle(&TokenService::wipeToken)); // Start listening for requests. tckServer.startServer(); diff --git a/src/tck/src/token/TokenService.cc b/src/tck/src/token/TokenService.cc index f06a2c59f..5177a33c2 100644 --- a/src/tck/src/token/TokenService.cc +++ b/src/tck/src/token/TokenService.cc @@ -16,6 +16,7 @@ #include "token/params/UnpauseTokenParams.h" #include "token/params/UpdateTokenFeeScheduleParams.h" #include "token/params/UpdateTokenParams.h" +#include "token/params/WipeTokenParams.h" #include "json/JsonErrorType.h" #include "json/JsonRpcException.h" @@ -38,12 +39,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -677,4 +680,47 @@ nlohmann::json updateToken(const UpdateTokenParams& params) }; } +//----- +nlohmann::json wipeToken(const WipeTokenParams& params) +{ + TokenWipeTransaction tokenWipeTransaction; + tokenWipeTransaction.setGrpcDeadline(SdkClient::DEFAULT_TCK_REQUEST_TIMEOUT); + + if (params.mTokenId.has_value()) + { + tokenWipeTransaction.setTokenId(TokenId::fromString(params.mTokenId.value())); + } + + if (params.mAccountId.has_value()) + { + tokenWipeTransaction.setAccountId(AccountId::fromString(params.mAccountId.value())); + } + + if (params.mAmount.has_value()) + { + tokenWipeTransaction.setAmount(Hiero::internal::EntityIdHelper::getNum(params.mAmount.value())); + } + + if (params.mSerialNumbers.has_value()) + { + std::vector serialNumbers; + for (const std::string& serialNumber : params.mSerialNumbers.value()) + { + serialNumbers.push_back(internal::EntityIdHelper::getNum(serialNumber)); + } + tokenWipeTransaction.setSerialNumbers(serialNumbers); + } + + if (params.mCommonTxParams.has_value()) + { + params.mCommonTxParams->fillOutTransaction(tokenWipeTransaction, SdkClient::getClient()); + } + + return { + {"status", + gStatusToString.at( + tokenWipeTransaction.execute(SdkClient::getClient()).getReceipt(SdkClient::getClient()).mStatus)} + }; +} + } // namespace Hiero::TCK::TokenService