From d5dc577eeab7467dfe5de2300ff0fb7021988060 Mon Sep 17 00:00:00 2001 From: Rob Walworth <110835868+rwalworth@users.noreply.github.com> Date: Wed, 7 Aug 2024 09:36:49 -0500 Subject: [PATCH] feat(accountDeleteTransaction): Implement JSON-RPC endpoint for `AccountDeleteTransaction` (#748) Signed-off-by: Rob Walworth --- src/tck/include/SdkClient.h | 12 ++++++++++++ src/tck/src/SdkClient.cc | 29 +++++++++++++++++++++++++++++ src/tck/src/main.cc | 3 +++ 3 files changed, 44 insertions(+) diff --git a/src/tck/include/SdkClient.h b/src/tck/include/SdkClient.h index 27ec5922b..f8ae9ef24 100644 --- a/src/tck/include/SdkClient.h +++ b/src/tck/include/SdkClient.h @@ -58,6 +58,18 @@ nlohmann::json createAccount(const std::optional& key, const std::optional& alias, const std::optional& commonTxParams); +/** + * Delete an account. + * + * @param deleteAccountId The ID of the account to delete. + * @param transferAccountId The ID of the account to which to transfer remaining balances. + * @param commonTxParams Any parameters common to all transaction types. + * @return A JSON response containing the status of the account deletion. + */ +nlohmann::json deleteAccount(const std::optional& deleteAccountId, + const std::optional& transferAccountId, + const std::optional& commonTxParams); + /** * Generate a Key. * diff --git a/src/tck/src/SdkClient.cc b/src/tck/src/SdkClient.cc index cc2d0ce23..9b5a9eb71 100644 --- a/src/tck/src/SdkClient.cc +++ b/src/tck/src/SdkClient.cc @@ -19,6 +19,7 @@ */ #include "SdkClient.h" #include "AccountCreateTransaction.h" +#include "AccountDeleteTransaction.h" #include "AccountId.h" #include "AccountUpdateTransaction.h" #include "Client.h" @@ -128,6 +129,34 @@ nlohmann::json SdkClient::createAccount(const std::optional& key, }; } +//----- +nlohmann::json SdkClient::deleteAccount(const std::optional& deleteAccountId, + const std::optional& transferAccountId, + const std::optional& commonTxParams) +{ + AccountDeleteTransaction accountDeleteTransaction; + accountDeleteTransaction.setGrpcDeadline(std::chrono::seconds(DEFAULT_TCK_REQUEST_TIMEOUT)); + + if (deleteAccountId.has_value()) + { + accountDeleteTransaction.setDeleteAccountId(AccountId::fromString(deleteAccountId.value())); + } + + if (transferAccountId.has_value()) + { + accountDeleteTransaction.setTransferAccountId(AccountId::fromString(transferAccountId.value())); + } + + if (commonTxParams.has_value()) + { + commonTxParams->fillOutTransaction(accountDeleteTransaction, mClient); + } + + return { + {"status", gStatusToString.at(accountDeleteTransaction.execute(mClient).getReceipt(mClient).mStatus)} + }; +} + //----- nlohmann::json SdkClient::generateKey(const std::string& type, const std::optional& fromKey, diff --git a/src/tck/src/main.cc b/src/tck/src/main.cc index 1212d543f..7b21aacf3 100644 --- a/src/tck/src/main.cc +++ b/src/tck/src/main.cc @@ -44,6 +44,9 @@ int main(int argc, char** argv) "declineStakingReward", "alias", "commonTransactionParams" }); + tckServer.add("deleteAccount", + getHandle(&SdkClient::deleteAccount), + { "deleteAccountId", "transferAccountId", "commonTransactionParams" }); tckServer.add("generateKey", getHandle(&SdkClient::generateKey), { "type", "fromKey", "threshold", "keys" }); tckServer.add("setup", getHandle(&SdkClient::setup),