Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TCK): Add AccountDelete method #2497

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion tck/methods/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Hbar,
AccountId,
AccountUpdateTransaction,
AccountDeleteTransaction,
} from "@hashgraph/sdk";

import { sdk } from "../sdk_data";
Expand All @@ -11,7 +12,11 @@ import { AccountResponse } from "../response/account";
import { getKeyFromString } from "../utils/key";
import { DEFAULT_GRPC_DEADLINE } from "../utils/constants/config";

import { CreateAccountParams, UpdateAccountParams } from "../params/account";
import {
CreateAccountParams,
DeleteAccountParams,
UpdateAccountParams,
} from "../params/account";
import { applyCommonTransactionParams } from "../params/common-tx-params";

export const createAccount = async ({
Expand Down Expand Up @@ -165,3 +170,38 @@ export const updateAccount = async ({
status: receipt.status.toString(),
};
};

export const deleteAccount = async ({
deleteAccountId,
transferAccountId,
commonTransactionParams,
}: DeleteAccountParams): Promise<AccountResponse> => {
let transaction = new AccountDeleteTransaction().setGrpcDeadline(
DEFAULT_GRPC_DEADLINE,
);

if (deleteAccountId != null) {
transaction.setAccountId(AccountId.fromString(deleteAccountId));
}

if (transferAccountId != null) {
transaction.setTransferAccountId(
AccountId.fromString(transferAccountId),
);
}

if (commonTransactionParams != null) {
applyCommonTransactionParams(
commonTransactionParams,
transaction,
sdk.getClient(),
);
}

const txResponse = await transaction.execute(sdk.getClient());
const receipt = await txResponse.getReceipt(sdk.getClient());

return {
status: receipt.status.toString(),
};
};
6 changes: 6 additions & 0 deletions tck/params/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ export interface UpdateAccountParams {
readonly declineStakingReward?: boolean;
readonly commonTransactionParams?: Record<string, any>;
}

export interface DeleteAccountParams {
readonly deleteAccountId?: string;
readonly transferAccountId?: string;
readonly commonTransactionParams?: Record<string, any>;
}