Skip to content

Commit

Permalink
feat: implement token delete
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Ivanov <[email protected]>
  • Loading branch information
0xivanov committed Nov 19, 2024
1 parent 554c71c commit fcbb0e8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<String> tokenId;
private Optional<CommonTransactionParams> commonTransactionParams;

@Override
public JSONRPC2Param parse(Map<String, Object> jrpcParams) throws Exception {
var parsedTokenId = Optional.ofNullable((String) jrpcParams.get("tokenId"));
Optional<CommonTransactionParams> parsedCommonTransactionParams = Optional.empty();
if (jrpcParams.containsKey("commonTransactionParams")) {
JSONObject jsonObject = (JSONObject) jrpcParams.get("commonTransactionParams");
parsedCommonTransactionParams = Optional.of(CommonTransactionParams.parse(jsonObject));
}

return new TokenDeleteParams(parsedTokenId, parsedCommonTransactionParams);
}
}

0 comments on commit fcbb0e8

Please sign in to comment.