Skip to content

Commit

Permalink
feat: add grantTokenKyc method
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Walworth <[email protected]>
  • Loading branch information
rwalworth committed Dec 4, 2024
1 parent f7cd3e6 commit 9bbb8ae
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/tck/include/token/TokenService.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Hiero::TCK::TokenService
*/
struct CreateTokenParams;
struct DeleteTokenParams;
struct GrantTokenKycParams;
struct UpdateTokenParams;

/**
Expand All @@ -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.
*
Expand Down
62 changes: 62 additions & 0 deletions src/tck/include/token/params/GrantTokenKycParams.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_GRANT_TOKEN_KYC_PARAMS_H_
#define HIERO_TCK_CPP_GRANT_TOKEN_KYC_PARAMS_H_

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

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

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<std::string> mTokenId;

/**
* The ID of the account to which to grant KYC.
*/
std::optional<std::string> mAccountId;

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

} // namespace Hedera::TCK::TokenService

namespace nlohmann
{
/**
* JSON serializer template specialization required to convert GrantTokenKycParams arguments properly.
*/
template<>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::TokenService::GrantTokenKycParams>
{
/**
* 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<std::string>(jsonFrom, "tokenId");
params.mAccountId = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "accountId");
params.mCommonTxParams =
Hiero::TCK::getOptionalJsonParameter<Hiero::TCK::CommonTransactionParams>(jsonFrom, "commonTransactionParams");
}
};

} // namespace nlohmann

#endif // HIERO_TCK_CPP_GRANT_TOKEN_KYC_PARAMS_H_
3 changes: 3 additions & 0 deletions src/tck/src/TckServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -353,6 +354,8 @@ template TckServer::MethodHandle TckServer::getHandle<TokenService::CreateTokenP
nlohmann::json (*method)(const TokenService::CreateTokenParams&));
template TckServer::MethodHandle TckServer::getHandle<TokenService::DeleteTokenParams>(
nlohmann::json (*method)(const TokenService::DeleteTokenParams&));
template TckServer::MethodHandle TckServer::getHandle<TokenService::GrantTokenKycParams>(
nlohmann::json (*method)(const TokenService::GrantTokenKycParams&));
template TckServer::MethodHandle TckServer::getHandle<TokenService::UpdateTokenParams>(
nlohmann::json (*method)(const TokenService::UpdateTokenParams&));

Expand Down
1 change: 1 addition & 0 deletions src/tck/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 30 additions & 0 deletions src/tck/src/token/TokenService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -12,6 +13,7 @@
#include <Status.h>
#include <TokenCreateTransaction.h>
#include <TokenDeleteTransaction.h>
#include <TokenGrantKycTransaction.h>
#include <TokenId.h>
#include <TokenSupplyType.h>
#include <TokenType.h>
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 9bbb8ae

Please sign in to comment.