Skip to content

Commit 9e0286d

Browse files
rwalworthgsstoykov
andauthored
feat(tokenWipeTransaction): Implement JSON-RPC method endpoint for TokenWipeTransaction (#920)
Signed-off-by: Rob Walworth <robert.walworth@swirldslabs.com> Co-authored-by: gsstoykov <georgi.stoykov@limechain.tech>
1 parent c1d2fd5 commit 9e0286d

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed

src/tck/include/token/TokenService.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct UnfreezeTokenParams;
2323
struct UnpauseTokenParams;
2424
struct UpdateTokenFeeScheduleParams;
2525
struct UpdateTokenParams;
26+
struct WipeTokenParams;
2627

2728
/**
2829
* Associate an account with tokens.
@@ -136,6 +137,14 @@ nlohmann::json updateTokenFeeSchedule(const UpdateTokenFeeScheduleParams& params
136137
*/
137138
nlohmann::json updateToken(const UpdateTokenParams& params);
138139

140+
/**
141+
* Wipe a token or tokens from an account.
142+
*
143+
* @param params The parameters to use to wipe the token(s).
144+
* @ return A JSON response containing the status of the token wipe.
145+
*/
146+
nlohmann::json wipeToken(const WipeTokenParams& params);
147+
139148
} // namespace Hiero::TCK::TokenService
140149

141150
#endif // HIERO_TCK_CPP_TOKEN_SERVICE_H_
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
#ifndef HIERO_TCK_CPP_WIPE_TOKEN_PARAMS_H_
3+
#define HIERO_TCK_CPP_WIPE_TOKEN_PARAMS_H_
4+
5+
#include "common/CommonTransactionParams.h"
6+
#include "json/JsonUtils.h"
7+
8+
#include <nlohmann/json.hpp>
9+
#include <optional>
10+
#include <string>
11+
12+
namespace Hiero::TCK::TokenService
13+
{
14+
/**
15+
* Struct to hold the arguments for a `wipeToken` JSON-RPC method call.
16+
*/
17+
struct WipeTokenParams
18+
{
19+
/**
20+
* The ID of the token to wipe.
21+
*/
22+
std::optional<std::string> mTokenId;
23+
24+
/**
25+
* The ID of the account from which to wipe the tokens.
26+
*/
27+
std::optional<std::string> mAccountId;
28+
29+
/**
30+
* The amount of fungible tokens to wipe.
31+
*/
32+
std::optional<std::string> mAmount;
33+
34+
/**
35+
* The serial numbers of the NFTs to wipe.
36+
*/
37+
std::optional<std::vector<std::string>> mSerialNumbers;
38+
39+
/**
40+
* Any parameters common to all transaction types.
41+
*/
42+
std::optional<CommonTransactionParams> mCommonTxParams;
43+
};
44+
45+
} // namespace Hedera::TCK::TokenService
46+
47+
namespace nlohmann
48+
{
49+
/**
50+
* JSON serializer template specialization required to convert WipeTokenParams arguments properly.
51+
*/
52+
template<>
53+
struct [[maybe_unused]] adl_serializer<Hiero::TCK::TokenService::WipeTokenParams>
54+
{
55+
/**
56+
* Convert a JSON object to a WipeTokenParams.
57+
*
58+
* @param jsonFrom The JSON object with which to fill the WipeTokenParams.
59+
* @param params The WipeTokenParams to fill with the JSON object.
60+
*/
61+
static void from_json(const json& jsonFrom, Hiero::TCK::TokenService::WipeTokenParams& params)
62+
{
63+
params.mTokenId = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "tokenId");
64+
params.mAccountId = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "accountId");
65+
params.mAmount = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "amount");
66+
params.mSerialNumbers = Hiero::TCK::getOptionalJsonParameter<std::vector<std::string>>(jsonFrom, "serialNumbers");
67+
params.mCommonTxParams =
68+
Hiero::TCK::getOptionalJsonParameter<Hiero::TCK::CommonTransactionParams>(jsonFrom, "commonTransactionParams");
69+
}
70+
};
71+
72+
} // namespace nlohmann
73+
74+
#endif // HIERO_TCK_CPP_WIPE_TOKEN_PARAMS_H_

src/tck/src/TckServer.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "token/params/UnpauseTokenParams.h"
2727
#include "token/params/UpdateTokenFeeScheduleParams.h"
2828
#include "token/params/UpdateTokenParams.h"
29+
#include "token/params/WipeTokenParams.h"
2930
#include "json/JsonErrorType.h"
3031
#include "json/JsonRpcException.h"
3132
#include "json/JsonUtils.h"
@@ -397,5 +398,7 @@ template TckServer::MethodHandle TckServer::getHandle<TokenService::UpdateTokenF
397398
nlohmann::json (*method)(const TokenService::UpdateTokenFeeScheduleParams&));
398399
template TckServer::MethodHandle TckServer::getHandle<TokenService::UpdateTokenParams>(
399400
nlohmann::json (*method)(const TokenService::UpdateTokenParams&));
401+
template TckServer::MethodHandle TckServer::getHandle<TokenService::WipeTokenParams>(
402+
nlohmann::json (*method)(const TokenService::WipeTokenParams&));
400403

401404
} // namespace Hiero::TCK

src/tck/src/main.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ int main(int argc, char** argv)
4545
tckServer.add("unfreezeToken", tckServer.getHandle(&TokenService::unfreezeToken));
4646
tckServer.add("updateTokenFeeSchedule", tckServer.getHandle(&TokenService::updateTokenFeeSchedule));
4747
tckServer.add("updateToken", tckServer.getHandle(&TokenService::updateToken));
48+
tckServer.add("wipeToken", tckServer.getHandle(&TokenService::wipeToken));
4849

4950
// Start listening for requests.
5051
tckServer.startServer();

src/tck/src/token/TokenService.cc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "token/params/UnpauseTokenParams.h"
1717
#include "token/params/UpdateTokenFeeScheduleParams.h"
1818
#include "token/params/UpdateTokenParams.h"
19+
#include "token/params/WipeTokenParams.h"
1920
#include "json/JsonErrorType.h"
2021
#include "json/JsonRpcException.h"
2122

@@ -38,12 +39,14 @@
3839
#include <TokenUnfreezeTransaction.h>
3940
#include <TokenUnpauseTransaction.h>
4041
#include <TokenUpdateTransaction.h>
42+
#include <TokenWipeTransaction.h>
4143
#include <TransactionReceipt.h>
4244
#include <TransactionResponse.h>
4345
#include <impl/EntityIdHelper.h>
4446
#include <impl/HexConverter.h>
4547
#include <impl/Utilities.h>
4648

49+
#include <algorithm>
4750
#include <chrono>
4851
#include <cstdint>
4952
#include <nlohmann/json.hpp>
@@ -677,4 +680,47 @@ nlohmann::json updateToken(const UpdateTokenParams& params)
677680
};
678681
}
679682

683+
//-----
684+
nlohmann::json wipeToken(const WipeTokenParams& params)
685+
{
686+
TokenWipeTransaction tokenWipeTransaction;
687+
tokenWipeTransaction.setGrpcDeadline(SdkClient::DEFAULT_TCK_REQUEST_TIMEOUT);
688+
689+
if (params.mTokenId.has_value())
690+
{
691+
tokenWipeTransaction.setTokenId(TokenId::fromString(params.mTokenId.value()));
692+
}
693+
694+
if (params.mAccountId.has_value())
695+
{
696+
tokenWipeTransaction.setAccountId(AccountId::fromString(params.mAccountId.value()));
697+
}
698+
699+
if (params.mAmount.has_value())
700+
{
701+
tokenWipeTransaction.setAmount(Hiero::internal::EntityIdHelper::getNum(params.mAmount.value()));
702+
}
703+
704+
if (params.mSerialNumbers.has_value())
705+
{
706+
std::vector<uint64_t> serialNumbers;
707+
for (const std::string& serialNumber : params.mSerialNumbers.value())
708+
{
709+
serialNumbers.push_back(internal::EntityIdHelper::getNum(serialNumber));
710+
}
711+
tokenWipeTransaction.setSerialNumbers(serialNumbers);
712+
}
713+
714+
if (params.mCommonTxParams.has_value())
715+
{
716+
params.mCommonTxParams->fillOutTransaction(tokenWipeTransaction, SdkClient::getClient());
717+
}
718+
719+
return {
720+
{"status",
721+
gStatusToString.at(
722+
tokenWipeTransaction.execute(SdkClient::getClient()).getReceipt(SdkClient::getClient()).mStatus)}
723+
};
724+
}
725+
680726
} // namespace Hiero::TCK::TokenService

0 commit comments

Comments
 (0)