Skip to content

Commit

Permalink
feat: add pauseToken endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Walworth <[email protected]>
  • Loading branch information
rwalworth committed Nov 22, 2024
1 parent e85ee2d commit a18b745
Show file tree
Hide file tree
Showing 9 changed files with 1,262 additions and 1,171 deletions.
2 changes: 1 addition & 1 deletion src/sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ option(BUILD_EXAMPLES "Build the example builds" OFF)

if(BUILD_EXAMPLES)
message(STATUS "Including examples in the build.")
add_subdirectory(tests)
add_subdirectory(examples)
else()
message(STATUS "Examples are not included in the build.")
endif()
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/examples/ConstructClientExample.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ int main(int argc, char** argv)

// Create a Client with a custom network.
const std::unordered_map<std::string, AccountId> network = {
{ "2.testnet.hedera.com:50211", AccountId(5ULL) },
{ "3.testnet.hedera.com:50211", AccountId(6ULL) }
{"2.testnet.hedera.com:50211", AccountId(5ULL)},
{ "3.testnet.hedera.com:50211", AccountId(6ULL)}
};
Client customClient = Client::forNetwork(network);

Expand Down
444 changes: 222 additions & 222 deletions src/sdk/main/src/RequestType.cc

Large diffs are not rendered by default.

1,878 changes: 939 additions & 939 deletions src/sdk/main/src/Status.cc

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/tck/include/token/TokenService.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace Hiero::TCK::TokenService
/**
* Forward declarations.
*/
class CreateTokenParams;
struct CreateTokenParams;
struct PauseTokenParams;

/**
* Create a token.
Expand All @@ -19,6 +20,14 @@ class CreateTokenParams;
*/
nlohmann::json createToken(const CreateTokenParams& params);

/**
* Pause a token.
*
* @param params The parameters to use to pause a token.
* @return A JSON response containing the status of the token pause.
*/
nlohmann::json pauseToken(const PauseTokenParams& params);

} // namespace Hiero::TCK::TokenService

#endif // HIERO_TCK_CPP_TOKEN_SERVICE_H_
56 changes: 56 additions & 0 deletions src/tck/include/token/params/PauseTokenParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: Apache-2.0
#ifndef HIERO_TCK_CPP_PAUSE_TOKEN_PARAMS_H_
#define HIERO_TCK_CPP_PAUSE_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 `pauseToken` JSON-RPC method call.
*/
struct PauseTokenParams
{
/**
* The ID of the token to pause.
*/
std::optional<std::string> mTokenId;

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

} // namespace Hiero::TCK::TokenService

namespace nlohmann
{
/**
* JSON serializer template specialization required to convert PauseTokenParams arguments properly.
*/
template<>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::TokenService::PauseTokenParams>
{
/**
* Convert a JSON object to a PauseTokenParams.
*
* @param jsonFrom The JSON object with which to fill the PauseTokenParams.
* @param params The PauseTokenParams to fill with the JSON object.
*/
static void from_json(const json& jsonFrom, Hiero::TCK::TokenService::PauseTokenParams& params)
{
params.mTokenId = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "tokenId");
params.mCommonTxParams =
Hiero::TCK::getOptionalJsonParameter<Hiero::TCK::CommonTransactionParams>(jsonFrom, "commonTransactionParams");
}
};

} // namespace nlohmann

#endif // HIERO_TCK_CPP_PAUSE_TOKEN_PARAMS_H_
7 changes: 3 additions & 4 deletions src/tck/src/TckServer.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// SPDX-License-Identifier: Apache-2.0
#include "TckServer.h"
#include "account/AccountService.h"
#include "account/params/CreateAccountParams.h"
#include "account/params/DeleteAccountParams.h"
#include "account/params/UpdateAccountParams.h"
#include "key/KeyService.h"
#include "key/params/GenerateKeyParams.h"
#include "sdk/SdkClient.h"
#include "sdk/params/ResetParams.h"
#include "sdk/params/SetupParams.h"
#include "token/TokenService.h"
#include "token/params/CreateTokenParams.h"
#include "token/params/PauseTokenParams.h"
#include "json/JsonErrorType.h"
#include "json/JsonRpcException.h"
#include "json/JsonUtils.h"
Expand Down Expand Up @@ -350,5 +347,7 @@ template TckServer::MethodHandle TckServer::getHandle<SdkClient::SetupParams>(

template TckServer::MethodHandle TckServer::getHandle<TokenService::CreateTokenParams>(
nlohmann::json (*method)(const TokenService::CreateTokenParams&));
template TckServer::MethodHandle TckServer::getHandle<TokenService::PauseTokenParams>(
nlohmann::json (*method)(const TokenService::PauseTokenParams&));

} // 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 @@ -29,6 +29,7 @@ int main(int argc, char** argv)

// Add the TokenService functions.
tckServer.add("createToken", tckServer.getHandle(&TokenService::createToken));
tckServer.add("pauseToken", tckServer.getHandle(&TokenService::pauseToken));

// Start listening for requests.
tckServer.startServer();
Expand Down
30 changes: 28 additions & 2 deletions src/tck/src/token/TokenService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
#include "key/KeyService.h"
#include "sdk/SdkClient.h"
#include "token/params/CreateTokenParams.h"
#include "token/params/PauseTokenParams.h"
#include "json/JsonErrorType.h"
#include "json/JsonRpcException.h"

#include <AccountId.h>
#include <Status.h>
#include <TokenCreateTransaction.h>
#include <TokenId.h>
#include <TokenPauseTransaction.h>
#include <TokenSupplyType.h>
#include <TokenType.h>
#include <TransactionReceipt.h>
Expand Down Expand Up @@ -169,8 +172,31 @@ nlohmann::json createToken(const CreateTokenParams& params)
const TransactionReceipt txReceipt =
tokenCreateTransaction.execute(SdkClient::getClient()).getReceipt(SdkClient::getClient());
return {
{ "tokenId", txReceipt.mTokenId->toString() },
{ "status", gStatusToString.at(txReceipt.mStatus) }
{"tokenId", txReceipt.mTokenId->toString() },
{ "status", gStatusToString.at(txReceipt.mStatus)}
};
}

//-----
nlohmann::json pauseToken(const PauseTokenParams& params)
{
TokenPauseTransaction tokenPauseTransaction;
tokenPauseTransaction.setGrpcDeadline(SdkClient::DEFAULT_TCK_REQUEST_TIMEOUT);

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

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

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

Expand Down

0 comments on commit a18b745

Please sign in to comment.