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
9 changes: 9 additions & 0 deletions src/tck/include/token/TokenService.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct UnfreezeTokenParams;
struct UnpauseTokenParams;
struct UpdateTokenFeeScheduleParams;
struct UpdateTokenParams;
struct WipeTokenParams;

/**
* Associate an account with tokens.
Expand Down Expand Up @@ -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_
74 changes: 74 additions & 0 deletions src/tck/include/token/params/WipeTokenParams.h
Original file line number Diff line number Diff line change
@@ -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 <nlohmann/json.hpp>
#include <optional>
#include <string>

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

/**
* The ID of the account from which to wipe the tokens.
*/
std::optional<std::string> mAccountId;

/**
* The amount of fungible tokens to wipe.
*/
std::optional<std::string> mAmount;

/**
* The serial numbers of the NFTs to wipe.
*/
std::optional<std::vector<std::string>> mSerialNumbers;

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

} // namespace Hedera::TCK::TokenService

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

} // namespace nlohmann

#endif // HIERO_TCK_CPP_WIPE_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 @@ -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"
Expand Down Expand Up @@ -397,5 +398,7 @@ template TckServer::MethodHandle TckServer::getHandle<TokenService::UpdateTokenF
nlohmann::json (*method)(const TokenService::UpdateTokenFeeScheduleParams&));
template TckServer::MethodHandle TckServer::getHandle<TokenService::UpdateTokenParams>(
nlohmann::json (*method)(const TokenService::UpdateTokenParams&));
template TckServer::MethodHandle TckServer::getHandle<TokenService::WipeTokenParams>(
nlohmann::json (*method)(const TokenService::WipeTokenParams&));

} // namespace Hiero::TCK
1 change: 1 addition & 0 deletions src/tck/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
46 changes: 46 additions & 0 deletions src/tck/src/token/TokenService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -38,12 +39,14 @@
#include <TokenUnfreezeTransaction.h>
#include <TokenUnpauseTransaction.h>
#include <TokenUpdateTransaction.h>
#include <TokenWipeTransaction.h>
#include <TransactionReceipt.h>
#include <TransactionResponse.h>
#include <impl/EntityIdHelper.h>
#include <impl/HexConverter.h>
#include <impl/Utilities.h>

#include <algorithm>
#include <chrono>
#include <cstdint>
#include <nlohmann/json.hpp>
Expand Down Expand Up @@ -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<uint64_t> 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
Loading