Skip to content

Commit

Permalink
chore(TCK): Added account allowance delete endpoint (#2858)
Browse files Browse the repository at this point in the history
* feat: Draft account allowance transaction added

Signed-off-by: ivaylogarnev-limechain <ivaylo.garnev@limechain.tech>

* fix: Some fixing in the approveAllowence method

Signed-off-by: ivaylogarnev-limechain <ivaylo.garnev@limechain.tech>

* fix: Fixing conditions inside approveAllowance method

Signed-off-by: ivaylogarnev-limechain <ivaylo.garnev@limechain.tech>

* fix: Added delegateSpenderAccountId check

Signed-off-by: ivaylogarnev-limechain <ivaylo.garnev@limechain.tech>

* refactor: Refactored the accountAlowance method and put some of the logic in helper function

Signed-off-by: ivaylogarnev-limechain <ivaylo.garnev@limechain.tech>

* fix: Added multiple allowances functionallity

Signed-off-by: ivaylogarnev-limechain <ivaylo.garnev@limechain.tech>

---------

Signed-off-by: ivaylogarnev-limechain <ivaylo.garnev@limechain.tech>
  • Loading branch information
ivaylogarnev-limechain authored Feb 12, 2025
1 parent 26695f1 commit d1651eb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tck/methods/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
AccountDeleteTransaction,
Timestamp,
AccountAllowanceApproveTransaction,
AccountAllowanceDeleteTransaction,
NftId,
TokenId,
} from "@hashgraph/sdk";
import Long from "long";
Expand All @@ -21,6 +23,7 @@ import {
AccountAllowanceApproveParams,
CreateAccountParams,
DeleteAccountParams,
DeleteAllowanceParams,
UpdateAccountParams,
} from "../params/account";
import { applyCommonTransactionParams } from "../params/common-tx-params";
Expand Down Expand Up @@ -263,3 +266,41 @@ export const approveAllowance = async ({
status: receipt.status.toString(),
};
};

export const deleteAllowance = async ({
allowances,
commonTransactionParams,
}: DeleteAllowanceParams): Promise<AccountResponse> => {
let transaction = new AccountAllowanceDeleteTransaction().setGrpcDeadline(
DEFAULT_GRPC_DEADLINE,
);

for (const allowance of allowances) {
const owner = AccountId.fromString(allowance.ownerAccountId);
const tokenId = AccountId.fromString(allowance.tokenId);

for (const serialNumber of allowance.serialNumbers) {
const nftId = new NftId(
new TokenId(tokenId),
Long.fromString(serialNumber),
);

transaction.deleteAllTokenNftAllowances(nftId, owner);
}
}

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(),
};
};
10 changes: 10 additions & 0 deletions tck/params/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ export interface AccountAllowanceApproveParams {
readonly allowances: AllowanceParams[];
readonly commonTransactionParams?: Record<string, any>;
}
export interface DeleteAllowanceParams {
readonly allowances: RemoveAllowancesParams[];
readonly commonTransactionParams?: Record<string, any>;
}

export interface RemoveAllowancesParams {
readonly tokenId: string;
readonly ownerAccountId: string;
readonly serialNumbers?: string[];
}

0 comments on commit d1651eb

Please sign in to comment.