Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tokenUnfreezeTransaction): Implement JSON-RPC method endpoint for TokenUnfreezeTransaction #849

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
50e4fd6
feat: add associateToken rpc method
rwalworth Nov 21, 2024
06e4f7e
Merge branch 'main' into 00831-tck-c++-implement-json-rpc-method-endp…
rwalworth Nov 22, 2024
ef89605
refactor: make associate use hiero names
rwalworth Nov 22, 2024
a18b745
feat: add pauseToken endpoint
rwalworth Nov 22, 2024
8d67ce0
feat(TCK): add dissociateToken tests
rwalworth Nov 25, 2024
23129b4
Merge branch '00831-tck-c++-implement-json-rpc-method-endpoint-for-to…
rwalworth Nov 25, 2024
cd5020f
Merge branch 'main' into 00831-tck-c++-implement-json-rpc-method-endp…
rwalworth Dec 2, 2024
d4dcad6
Merge branch 'main' into 00834-tck-c++-implement-json-rpc-method-endp…
rwalworth Dec 2, 2024
357219d
Merge branch 'main' into 00838-tck-c++-implement-json-rpc-method-endp…
rwalworth Dec 2, 2024
4f4f5ec
feat: add freezeToken endpoint
rwalworth Dec 3, 2024
40aa70b
Merge branch '00831-tck-c++-implement-json-rpc-method-endpoint-for-to…
rwalworth Dec 3, 2024
5600640
Merge branch '00838-tck-c++-implement-json-rpc-method-endpoint-for-to…
rwalworth Dec 3, 2024
cb34ea3
feat: add unfreezeToken endpoint
rwalworth Dec 3, 2024
cd94608
Merge branch 'main' into 00834-tck-c++-implement-json-rpc-method-endp…
rwalworth Dec 13, 2024
417ab0a
Merge branch 'main' into 00845-tck-c++-implement-json-rpc-method-endp…
rwalworth Dec 14, 2024
6b84504
Merge branch '00834-tck-c++-implement-json-rpc-method-endpoint-for-to…
rwalworth Dec 14, 2024
a5715c4
Merge remote-tracking branch 'origin/main' into 00845-tck-c++-impleme…
gsstoykov Jan 15, 2025
d273ef5
fix: Resolve merge conflicts
gsstoykov Jan 15, 2025
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
9 changes: 9 additions & 0 deletions src/tck/include/token/TokenService.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct DeleteTokenParams;
struct DissociateTokenParams;
struct FreezeTokenParams;
struct PauseTokenParams;
struct UnfreezeTokenParams;
struct UnpauseTokenParams;
struct UpdateTokenFeeScheduleParams;
struct UpdateTokenParams;
Expand Down Expand Up @@ -67,6 +68,14 @@ nlohmann::json freezeToken(const FreezeTokenParams& params);
*/
nlohmann::json pauseToken(const PauseTokenParams& params);

/**
* Unfreeze a token from an account.
*
* @params The parameters to use to unfreeze a token.
* @return A JSON response containing the status of the token unfreeze.
*/
nlohmann::json unfreezeToken(const UnfreezeTokenParams& params);

/**
* Unpause a token.
*
Expand Down
62 changes: 62 additions & 0 deletions src/tck/include/token/params/UnfreezeTokenParams.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_UNFREEZE_TOKEN_PARAMS_H_
#define HIERO_TCK_CPP_UNFREEZE_TOKEN_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 `unfreezeToken` JSON-RPC method call.
*/
struct UnfreezeTokenParams
{
/**
* The ID of the token to freeze.
*/
std::optional<std::string> mTokenId;

/**
* The ID of the account to freeze.
*/
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 UnfreezeTokenParams arguments properly.
*/
template<>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::TokenService::UnfreezeTokenParams>
{
/**
* Convert a JSON object to a UnfreezeTokenParams.
*
* @param jsonFrom The JSON object with which to fill the UnfreezeTokenParams.
* @param params The UnfreezeTokenParams to fill with the JSON object.
*/
static void from_json(const json& jsonFrom, Hiero::TCK::TokenService::UnfreezeTokenParams& 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_UNFREEZE_TOKEN_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 @@ -15,6 +15,7 @@
#include "token/params/DissociateTokenParams.h"
#include "token/params/FreezeTokenParams.h"
#include "token/params/PauseTokenParams.h"
#include "token/params/UnfreezeTokenParams.h"
#include "token/params/UnpauseTokenParams.h"
#include "token/params/UpdateTokenFeeScheduleParams.h"
#include "token/params/UpdateTokenParams.h"
Expand Down Expand Up @@ -367,6 +368,8 @@ template TckServer::MethodHandle TckServer::getHandle<TokenService::FreezeTokenP
nlohmann::json (*method)(const TokenService::FreezeTokenParams&));
template TckServer::MethodHandle TckServer::getHandle<TokenService::PauseTokenParams>(
nlohmann::json (*method)(const TokenService::PauseTokenParams&));
template TckServer::MethodHandle TckServer::getHandle<TokenService::UnfreezeTokenParams>(
nlohmann::json (*method)(const TokenService::UnfreezeTokenParams&));
template TckServer::MethodHandle TckServer::getHandle<TokenService::UnpauseTokenParams>(
nlohmann::json (*method)(const TokenService::UnpauseTokenParams&));
template TckServer::MethodHandle TckServer::getHandle<TokenService::UpdateTokenFeeScheduleParams>(
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 @@ -35,6 +35,7 @@ int main(int argc, char** argv)
tckServer.add("freezeToken", tckServer.getHandle(&TokenService::freezeToken));
tckServer.add("pauseToken", tckServer.getHandle(&TokenService::pauseToken));
tckServer.add("unpauseToken", tckServer.getHandle(&TokenService::unpauseToken));
tckServer.add("unfreezeToken", tckServer.getHandle(&TokenService::unfreezeToken));
tckServer.add("updateTokenFeeSchedule", tckServer.getHandle(&TokenService::updateTokenFeeSchedule));
tckServer.add("updateToken", tckServer.getHandle(&TokenService::updateToken));

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 @@ -8,6 +8,7 @@
#include "token/params/DissociateTokenParams.h"
#include "token/params/FreezeTokenParams.h"
#include "token/params/PauseTokenParams.h"
#include "token/params/UnfreezeTokenParams.h"
#include "token/params/UnpauseTokenParams.h"
#include "token/params/UpdateTokenFeeScheduleParams.h"
#include "token/params/UpdateTokenParams.h"
Expand All @@ -26,6 +27,7 @@
#include <TokenPauseTransaction.h>
#include <TokenSupplyType.h>
#include <TokenType.h>
#include <TokenUnfreezeTransaction.h>
#include <TokenUnpauseTransaction.h>
#include <TokenUpdateTransaction.h>
#include <TransactionReceipt.h>
Expand Down Expand Up @@ -334,6 +336,34 @@ nlohmann::json pauseToken(const PauseTokenParams& params)
};
}

//-----
nlohmann::json unfreezeToken(const UnfreezeTokenParams& params)
{
TokenUnfreezeTransaction tokenUnfreezeTransaction;
tokenUnfreezeTransaction.setGrpcDeadline(SdkClient::DEFAULT_TCK_REQUEST_TIMEOUT);

if (params.mTokenId.has_value())
{
tokenUnfreezeTransaction.setTokenId(TokenId::fromString(params.mTokenId.value()));
}

if (params.mAccountId.has_value())
{
tokenUnfreezeTransaction.setAccountId(AccountId::fromString(params.mAccountId.value()));
}

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

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

//-----
nlohmann::json unpauseToken(const UnpauseTokenParams& params)
{
Expand Down
Loading