Skip to content

Commit d5dc577

Browse files
authored
feat(accountDeleteTransaction): Implement JSON-RPC endpoint for AccountDeleteTransaction (#748)
Signed-off-by: Rob Walworth <robert.walworth@swirldslabs.com>
1 parent 6edeba5 commit d5dc577

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/tck/include/SdkClient.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ nlohmann::json createAccount(const std::optional<std::string>& key,
5858
const std::optional<std::string>& alias,
5959
const std::optional<CommonTransactionParams>& commonTxParams);
6060

61+
/**
62+
* Delete an account.
63+
*
64+
* @param deleteAccountId The ID of the account to delete.
65+
* @param transferAccountId The ID of the account to which to transfer remaining balances.
66+
* @param commonTxParams Any parameters common to all transaction types.
67+
* @return A JSON response containing the status of the account deletion.
68+
*/
69+
nlohmann::json deleteAccount(const std::optional<std::string>& deleteAccountId,
70+
const std::optional<std::string>& transferAccountId,
71+
const std::optional<CommonTransactionParams>& commonTxParams);
72+
6173
/**
6274
* Generate a Key.
6375
*

src/tck/src/SdkClient.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
#include "SdkClient.h"
2121
#include "AccountCreateTransaction.h"
22+
#include "AccountDeleteTransaction.h"
2223
#include "AccountId.h"
2324
#include "AccountUpdateTransaction.h"
2425
#include "Client.h"
@@ -128,6 +129,34 @@ nlohmann::json SdkClient::createAccount(const std::optional<std::string>& key,
128129
};
129130
}
130131

132+
//-----
133+
nlohmann::json SdkClient::deleteAccount(const std::optional<std::string>& deleteAccountId,
134+
const std::optional<std::string>& transferAccountId,
135+
const std::optional<CommonTransactionParams>& commonTxParams)
136+
{
137+
AccountDeleteTransaction accountDeleteTransaction;
138+
accountDeleteTransaction.setGrpcDeadline(std::chrono::seconds(DEFAULT_TCK_REQUEST_TIMEOUT));
139+
140+
if (deleteAccountId.has_value())
141+
{
142+
accountDeleteTransaction.setDeleteAccountId(AccountId::fromString(deleteAccountId.value()));
143+
}
144+
145+
if (transferAccountId.has_value())
146+
{
147+
accountDeleteTransaction.setTransferAccountId(AccountId::fromString(transferAccountId.value()));
148+
}
149+
150+
if (commonTxParams.has_value())
151+
{
152+
commonTxParams->fillOutTransaction(accountDeleteTransaction, mClient);
153+
}
154+
155+
return {
156+
{"status", gStatusToString.at(accountDeleteTransaction.execute(mClient).getReceipt(mClient).mStatus)}
157+
};
158+
}
159+
131160
//-----
132161
nlohmann::json SdkClient::generateKey(const std::string& type,
133162
const std::optional<std::string>& fromKey,

src/tck/src/main.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ int main(int argc, char** argv)
4444
"declineStakingReward",
4545
"alias",
4646
"commonTransactionParams" });
47+
tckServer.add("deleteAccount",
48+
getHandle(&SdkClient::deleteAccount),
49+
{ "deleteAccountId", "transferAccountId", "commonTransactionParams" });
4750
tckServer.add("generateKey", getHandle(&SdkClient::generateKey), { "type", "fromKey", "threshold", "keys" });
4851
tckServer.add("setup",
4952
getHandle(&SdkClient::setup),

0 commit comments

Comments
 (0)