Skip to content

Commit 1520c14

Browse files
authored
feat(TCK): NftInfoQuery implementation (#2624)
Signed-off-by: Mustafa Uzun <mustafa.uzun@limechain.tech>
1 parent a236e96 commit 1520c14

4 files changed

Lines changed: 92 additions & 0 deletions

File tree

tck/src/main/java/com/hedera/hashgraph/tck/methods/sdk/TokenService.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import com.hedera.hashgraph.tck.methods.sdk.response.token.*;
1010
import com.hedera.hashgraph.tck.util.QueryBuilders;
1111
import com.hedera.hashgraph.tck.util.TransactionBuilders;
12+
import java.util.List;
1213
import java.util.Map;
14+
import org.bouncycastle.util.encoders.Hex;
1315

1416
/**
1517
* TokenService for token related methods
@@ -23,6 +25,23 @@ public TokenService(SdkService sdkService) {
2325
this.sdkService = sdkService;
2426
}
2527

28+
@JSONRPC2Method("getTokenNftInfo")
29+
public NftInfoResponse getNftInfo(final NftInfoQueryParams params) throws Exception {
30+
TokenNftInfoQuery query = QueryBuilders.TokenBuilder.buildNftInfo(params);
31+
Client client = sdkService.getClient(params.getSessionId());
32+
33+
List<TokenNftInfo> txResponse = query.execute(client);
34+
TokenNftInfo tokenNftInfo = txResponse.get(0);
35+
36+
return new NftInfoResponse(
37+
tokenNftInfo.nftId.toString(),
38+
tokenNftInfo.accountId.toString(),
39+
String.valueOf(tokenNftInfo.creationTime.getEpochSecond()),
40+
Hex.toHexString(tokenNftInfo.metadata),
41+
tokenNftInfo.ledgerId.toString(),
42+
tokenNftInfo.spenderId != null ? tokenNftInfo.spenderId.toString() : null);
43+
}
44+
2645
@JSONRPC2Method("getTokenInfo")
2746
public TokenInfoResponse getTokenInfo(final TokenInfoQueryParams params) throws Exception {
2847
TokenInfoQuery query = QueryBuilders.TokenBuilder.buildTokenInfo(params);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
package com.hedera.hashgraph.tck.methods.sdk.param.token;
3+
4+
import com.hedera.hashgraph.tck.methods.JSONRPC2Param;
5+
import com.hedera.hashgraph.tck.util.JSONRPCParamParser;
6+
import java.util.Map;
7+
import lombok.AllArgsConstructor;
8+
import lombok.Getter;
9+
import lombok.NoArgsConstructor;
10+
11+
@Getter
12+
@AllArgsConstructor
13+
@NoArgsConstructor
14+
public class NftInfoQueryParams extends JSONRPC2Param {
15+
private String nftId;
16+
private String sessionId;
17+
18+
@Override
19+
public JSONRPC2Param parse(Map<String, Object> jrpcParams) throws Exception {
20+
var parsedNftId = (String) jrpcParams.get("nftId");
21+
return new NftInfoQueryParams(parsedNftId, JSONRPCParamParser.parseSessionId(jrpcParams));
22+
}
23+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
package com.hedera.hashgraph.tck.methods.sdk.response.token;
3+
4+
import javax.annotation.Nullable;
5+
import lombok.Data;
6+
7+
@Data
8+
public class NftInfoResponse {
9+
10+
/**
11+
* The ID of the NFT
12+
*/
13+
public final String nftId;
14+
15+
/**
16+
* The current owner of the NFT
17+
*/
18+
public final String accountId;
19+
20+
/**
21+
* The effective consensus timestamp at which the NFT was minted
22+
*/
23+
public final String creationTime;
24+
25+
/**
26+
* Represents the unique metadata of the NFT
27+
*/
28+
public final String metadata;
29+
30+
/**
31+
* The ledger ID the response was returned from; please see <a href="https://github.com/hashgraph/hedera-improvement-proposal/blob/master/HIP/hip-198.md">HIP-198</a> for the network-specific IDs.
32+
*/
33+
public final String ledgerId;
34+
35+
/**
36+
* If an allowance is granted for the NFT, its corresponding spender account
37+
*/
38+
@Nullable
39+
public final String spenderId;
40+
}

tck/src/main/java/com/hedera/hashgraph/tck/util/QueryBuilders.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
import com.hedera.hashgraph.sdk.FileContentsQuery;
88
import com.hedera.hashgraph.sdk.FileId;
99
import com.hedera.hashgraph.sdk.Hbar;
10+
import com.hedera.hashgraph.sdk.NftId;
1011
import com.hedera.hashgraph.sdk.TokenId;
1112
import com.hedera.hashgraph.sdk.TokenInfoQuery;
13+
import com.hedera.hashgraph.sdk.TokenNftInfoQuery;
1214
import com.hedera.hashgraph.tck.methods.sdk.param.account.AccountBalanceQueryParams;
1315
import com.hedera.hashgraph.tck.methods.sdk.param.file.FileContentsParams;
16+
import com.hedera.hashgraph.tck.methods.sdk.param.token.NftInfoQueryParams;
1417
import com.hedera.hashgraph.tck.methods.sdk.param.token.TokenInfoQueryParams;
1518
import java.time.Duration;
1619

@@ -29,6 +32,13 @@ public static TokenInfoQuery buildTokenInfo(TokenInfoQueryParams params) {
2932

3033
return query;
3134
}
35+
36+
public static TokenNftInfoQuery buildNftInfo(NftInfoQueryParams params) {
37+
TokenNftInfoQuery query = new TokenNftInfoQuery().setGrpcDeadline((DEFAULT_GRPC_DEADLINE));
38+
query.setNftId(NftId.fromString(params.getNftId()));
39+
40+
return query;
41+
}
3242
}
3343

3444
/**

0 commit comments

Comments
 (0)