Skip to content

Commit

Permalink
feat(accountDeleteTransaction): Implement JSON-RPC endpoint for `Acco…
Browse files Browse the repository at this point in the history
…untDeleteTransaction` (#748)

Signed-off-by: Rob Walworth <[email protected]>
  • Loading branch information
rwalworth authored Aug 7, 2024
1 parent 6edeba5 commit d5dc577
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/tck/include/SdkClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ nlohmann::json createAccount(const std::optional<std::string>& key,
const std::optional<std::string>& alias,
const std::optional<CommonTransactionParams>& 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<std::string>& deleteAccountId,
const std::optional<std::string>& transferAccountId,
const std::optional<CommonTransactionParams>& commonTxParams);

/**
* Generate a Key.
*
Expand Down
29 changes: 29 additions & 0 deletions src/tck/src/SdkClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
#include "SdkClient.h"
#include "AccountCreateTransaction.h"
#include "AccountDeleteTransaction.h"
#include "AccountId.h"
#include "AccountUpdateTransaction.h"
#include "Client.h"
Expand Down Expand Up @@ -128,6 +129,34 @@ nlohmann::json SdkClient::createAccount(const std::optional<std::string>& key,
};
}

//-----
nlohmann::json SdkClient::deleteAccount(const std::optional<std::string>& deleteAccountId,
const std::optional<std::string>& transferAccountId,
const std::optional<CommonTransactionParams>& 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<std::string>& fromKey,
Expand Down
3 changes: 3 additions & 0 deletions src/tck/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit d5dc577

Please sign in to comment.