Skip to content

Commit

Permalink
feat: Added accountDelete JSONRPC method in the TCK and the relevant …
Browse files Browse the repository at this point in the history
…interfaces (#2497)

Signed-off-by: ivaylogarnev-limechain <ivaylo.garnev@limechain.tech>
  • Loading branch information
ivaylogarnev-limechain authored Sep 2, 2024
1 parent dd8431c commit e717d4f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
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>;
}

0 comments on commit e717d4f

Please sign in to comment.