From fcbb0e8c3fd19b14cf0290e6970b79838e89cf48 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Tue, 19 Nov 2024 17:02:28 +0200 Subject: [PATCH] feat: implement token delete Signed-off-by: Ivan Ivanov --- .../tck/methods/sdk/TokenService.java | 18 +++++++ .../methods/sdk/param/TokenDeleteParams.java | 52 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 tck/src/main/java/com/hedera/hashgraph/tck/methods/sdk/param/TokenDeleteParams.java diff --git a/tck/src/main/java/com/hedera/hashgraph/tck/methods/sdk/TokenService.java b/tck/src/main/java/com/hedera/hashgraph/tck/methods/sdk/TokenService.java index b49a5cf7e..832678f27 100644 --- a/tck/src/main/java/com/hedera/hashgraph/tck/methods/sdk/TokenService.java +++ b/tck/src/main/java/com/hedera/hashgraph/tck/methods/sdk/TokenService.java @@ -27,6 +27,7 @@ import com.hedera.hashgraph.sdk.CustomRoyaltyFee; import com.hedera.hashgraph.sdk.Status; import com.hedera.hashgraph.sdk.TokenCreateTransaction; +import com.hedera.hashgraph.sdk.TokenDeleteTransaction; import com.hedera.hashgraph.sdk.TokenId; import com.hedera.hashgraph.sdk.TokenSupplyType; import com.hedera.hashgraph.sdk.TokenType; @@ -36,6 +37,7 @@ import com.hedera.hashgraph.tck.annotation.JSONRPC2Service; import com.hedera.hashgraph.tck.methods.AbstractJSONRPC2Service; import com.hedera.hashgraph.tck.methods.sdk.param.TokenCreateParams; +import com.hedera.hashgraph.tck.methods.sdk.param.TokenDeleteParams; import com.hedera.hashgraph.tck.methods.sdk.param.TokenUpdateParams; import com.hedera.hashgraph.tck.methods.sdk.response.TokenResponse; import com.hedera.hashgraph.tck.util.KeyUtils; @@ -338,4 +340,20 @@ public TokenResponse updateToken(final TokenUpdateParams params) throws Exceptio return new TokenResponse("", transactionReceipt.status); } + + @JSONRPC2Method("deleteToken") + public TokenResponse deleteToken(final TokenDeleteParams params) throws Exception { + TokenDeleteTransaction tokenDeleteTransaction = new TokenDeleteTransaction(); + + params.getTokenId().ifPresent(tokenId -> tokenDeleteTransaction.setTokenId(TokenId.fromString(tokenId))); + + params.getCommonTransactionParams() + .ifPresent(commonTransactionParams -> + commonTransactionParams.fillOutTransaction(tokenDeleteTransaction, sdkService.getClient())); + + TransactionReceipt transactionReceipt = + tokenDeleteTransaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient()); + + return new TokenResponse("", transactionReceipt.status); + } } diff --git a/tck/src/main/java/com/hedera/hashgraph/tck/methods/sdk/param/TokenDeleteParams.java b/tck/src/main/java/com/hedera/hashgraph/tck/methods/sdk/param/TokenDeleteParams.java new file mode 100644 index 000000000..b65dd5d7e --- /dev/null +++ b/tck/src/main/java/com/hedera/hashgraph/tck/methods/sdk/param/TokenDeleteParams.java @@ -0,0 +1,52 @@ +/*- + * + * Hedera Java SDK + * + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.hedera.hashgraph.tck.methods.sdk.param; + +import com.hedera.hashgraph.tck.methods.JSONRPC2Param; +import java.util.Map; +import java.util.Optional; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import net.minidev.json.JSONObject; + +/** + * TokenDeleteParams for token delete method + */ +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class TokenDeleteParams extends JSONRPC2Param { + private Optional tokenId; + private Optional commonTransactionParams; + + @Override + public JSONRPC2Param parse(Map jrpcParams) throws Exception { + var parsedTokenId = Optional.ofNullable((String) jrpcParams.get("tokenId")); + Optional parsedCommonTransactionParams = Optional.empty(); + if (jrpcParams.containsKey("commonTransactionParams")) { + JSONObject jsonObject = (JSONObject) jrpcParams.get("commonTransactionParams"); + parsedCommonTransactionParams = Optional.of(CommonTransactionParams.parse(jsonObject)); + } + + return new TokenDeleteParams(parsedTokenId, parsedCommonTransactionParams); + } +}