diff --git a/src/tck/include/token/TokenService.h b/src/tck/include/token/TokenService.h index 0c07aac9..ea667fe4 100644 --- a/src/tck/include/token/TokenService.h +++ b/src/tck/include/token/TokenService.h @@ -11,6 +11,7 @@ namespace Hiero::TCK::TokenService */ struct CreateTokenParams; struct DeleteTokenParams; +struct GrantTokenKycParams; struct UpdateTokenParams; /** @@ -29,6 +30,14 @@ nlohmann::json createToken(const CreateTokenParams& params); */ nlohmann::json deleteToken(const DeleteTokenParams& params); +/** + * Grant KYC of a token to an account. + * + * @param params The parameters to use to grant KYC. + * @return A JSON response containing the status of the token KYC grant. + */ +nlohmann::json grantTokenKyc(const GrantTokenKycParams& params); + /** * Update a token. * diff --git a/src/tck/include/token/params/GrantTokenKycParams.h b/src/tck/include/token/params/GrantTokenKycParams.h new file mode 100644 index 00000000..1e317cde --- /dev/null +++ b/src/tck/include/token/params/GrantTokenKycParams.h @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: Apache-2.0 +#ifndef HIERO_TCK_CPP_GRANT_TOKEN_KYC_PARAMS_H_ +#define HIERO_TCK_CPP_GRANT_TOKEN_KYC_PARAMS_H_ + +#include "common/CommonTransactionParams.h" +#include "json/JsonUtils.h" + +#include +#include +#include + +namespace Hiero::TCK::TokenService +{ +/** + * Struct to hold the arguments for a `grantTokenKyc` JSON-RPC method call. + */ +struct GrantTokenKycParams +{ + /** + * The ID of the token of which to grant KYC. + */ + std::optional mTokenId; + + /** + * The ID of the account to which to grant KYC. + */ + std::optional mAccountId; + + /** + * Any parameters common to all transaction types. + */ + std::optional mCommonTxParams; +}; + +} // namespace Hedera::TCK::TokenService + +namespace nlohmann +{ +/** + * JSON serializer template specialization required to convert GrantTokenKycParams arguments properly. + */ +template<> +struct [[maybe_unused]] adl_serializer +{ + /** + * Convert a JSON object to a GrantTokenKycParams. + * + * @param jsonFrom The JSON object with which to fill the GrantTokenKycParams. + * @param params The GrantTokenKycParams to fill with the JSON object. + */ + static void from_json(const json& jsonFrom, Hiero::TCK::TokenService::GrantTokenKycParams& params) + { + params.mTokenId = Hiero::TCK::getOptionalJsonParameter(jsonFrom, "tokenId"); + params.mAccountId = Hiero::TCK::getOptionalJsonParameter(jsonFrom, "accountId"); + params.mCommonTxParams = + Hiero::TCK::getOptionalJsonParameter(jsonFrom, "commonTransactionParams"); + } +}; + +} // namespace nlohmann + +#endif // HIERO_TCK_CPP_GRANT_TOKEN_KYC_PARAMS_H_ \ No newline at end of file diff --git a/src/tck/src/TckServer.cc b/src/tck/src/TckServer.cc index 537815bd..71a4a72f 100644 --- a/src/tck/src/TckServer.cc +++ b/src/tck/src/TckServer.cc @@ -11,6 +11,7 @@ #include "sdk/params/SetupParams.h" #include "token/params/CreateTokenParams.h" #include "token/params/DeleteTokenParams.h" +#include "token/params/GrantTokenKycParams.h" #include "token/params/UpdateTokenParams.h" #include "json/JsonErrorType.h" #include "json/JsonRpcException.h" @@ -353,6 +354,8 @@ template TckServer::MethodHandle TckServer::getHandle( nlohmann::json (*method)(const TokenService::DeleteTokenParams&)); +template TckServer::MethodHandle TckServer::getHandle( + nlohmann::json (*method)(const TokenService::GrantTokenKycParams&)); template TckServer::MethodHandle TckServer::getHandle( nlohmann::json (*method)(const TokenService::UpdateTokenParams&)); diff --git a/src/tck/src/main.cc b/src/tck/src/main.cc index 2871dd80..d1d0b6b3 100644 --- a/src/tck/src/main.cc +++ b/src/tck/src/main.cc @@ -30,6 +30,7 @@ int main(int argc, char** argv) // Add the TokenService functions. tckServer.add("createToken", tckServer.getHandle(&TokenService::createToken)); tckServer.add("deleteToken", tckServer.getHandle(&TokenService::deleteToken)); + tckServer.add("grantTokenKyc", tckServer.getHandle(&TokenService::grantTokenKyc)); tckServer.add("updateToken", tckServer.getHandle(&TokenService::updateToken)); // Start listening for requests. diff --git a/src/tck/src/token/TokenService.cc b/src/tck/src/token/TokenService.cc index 51ed420d..4639bca4 100644 --- a/src/tck/src/token/TokenService.cc +++ b/src/tck/src/token/TokenService.cc @@ -4,6 +4,7 @@ #include "sdk/SdkClient.h" #include "token/params/CreateTokenParams.h" #include "token/params/DeleteTokenParams.h" +#include "token/params/GrantTokenKycParams.h" #include "token/params/UpdateTokenParams.h" #include "json/JsonErrorType.h" #include "json/JsonRpcException.h" @@ -12,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -202,6 +204,34 @@ nlohmann::json deleteToken(const DeleteTokenParams& params) }; } +//----- +nlohmann::json grantTokenKyc(const GrantTokenKycParams& params) +{ + TokenGrantKycTransaction tokenGrantKycTransaction; + tokenGrantKycTransaction.setGrpcDeadline(std::chrono::seconds(SdkClient::DEFAULT_TCK_REQUEST_TIMEOUT)); + + if (params.mTokenId.has_value()) + { + tokenGrantKycTransaction.setTokenId(TokenId::fromString(params.mTokenId.value())); + } + + if (params.mAccountId.has_value()) + { + tokenGrantKycTransaction.setAccountId(AccountId::fromString(params.mAccountId.value())); + } + + if (params.mCommonTxParams.has_value()) + { + params.mCommonTxParams->fillOutTransaction(tokenGrantKycTransaction, SdkClient::getClient()); + } + + return { + {"status", + gStatusToString.at( + tokenGrantKycTransaction.execute(SdkClient::getClient()).getReceipt(SdkClient::getClient()).mStatus)} + }; +} + //----- nlohmann::json updateToken(const UpdateTokenParams& params) {