Skip to content

Commit 0aa2b12

Browse files
authored
feat(TCK): Implemented Schedule Info Query (#2615)
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
1 parent eab3bbc commit 0aa2b12

5 files changed

Lines changed: 182 additions & 2 deletions

File tree

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
import com.hedera.hashgraph.tck.methods.AbstractJSONRPC2Service;
88
import com.hedera.hashgraph.tck.methods.sdk.param.schedule.ScheduleCreateParams;
99
import com.hedera.hashgraph.tck.methods.sdk.param.schedule.ScheduleDeleteParams;
10+
import com.hedera.hashgraph.tck.methods.sdk.param.schedule.ScheduleInfoParams;
1011
import com.hedera.hashgraph.tck.methods.sdk.param.schedule.ScheduleSignParams;
11-
import com.hedera.hashgraph.tck.methods.sdk.response.ScheduleResponse;
12+
import com.hedera.hashgraph.tck.methods.sdk.response.schedule.ScheduleInfoResponse;
13+
import com.hedera.hashgraph.tck.methods.sdk.response.schedule.ScheduleResponse;
1214
import com.hedera.hashgraph.tck.util.KeyUtils;
15+
import com.hedera.hashgraph.tck.util.QueryBuilders;
1316
import com.hedera.hashgraph.tck.util.TransactionBuilders;
1417
import java.time.Duration;
1518
import java.util.Collections;
1619
import java.util.HashMap;
20+
import java.util.List;
1721
import java.util.Map;
1822
import java.util.function.Function;
1923

@@ -190,4 +194,47 @@ private Transaction<?> buildScheduledTransaction(
190194
}
191195
return builder.apply(params);
192196
}
197+
198+
@JSONRPC2Method("getScheduleInfo")
199+
public ScheduleInfoResponse getScheduleInfo(final ScheduleInfoParams params) throws Exception {
200+
ScheduleInfoQuery query = QueryBuilders.ScheduleBuilder.buildScheduleInfoQuery(params);
201+
Client client = sdkService.getClient(params.getSessionId());
202+
203+
if (params.getGetCost()) {
204+
Hbar cost = query.getCost(client);
205+
return ScheduleInfoResponse.forCostOnly(String.valueOf(cost.toTinybars()));
206+
}
207+
208+
ScheduleInfo result = query.execute(client);
209+
return mapScheduleInfoResponse(result);
210+
}
211+
212+
/**
213+
* Map ScheduleInfo from SDK to ScheduleInfoResponse for JSON-RPC
214+
*/
215+
private ScheduleInfoResponse mapScheduleInfoResponse(ScheduleInfo scheduleInfo) {
216+
String adminKey = scheduleInfo.adminKey != null ? scheduleInfo.adminKey.toString() : null;
217+
String scheduleTransactionId =
218+
scheduleInfo.scheduledTransactionId != null ? scheduleInfo.scheduledTransactionId.toString() : null;
219+
String expirationTime = scheduleInfo.expirationTime != null ? scheduleInfo.expirationTime.toString() : null;
220+
String executedAt = scheduleInfo.executedAt != null ? scheduleInfo.executedAt.toString() : null;
221+
String deletedAt = scheduleInfo.deletedAt != null ? scheduleInfo.deletedAt.toString() : null;
222+
223+
List<String> signers =
224+
scheduleInfo.signatories.stream().map(key -> key.toString()).toList();
225+
226+
return new ScheduleInfoResponse(
227+
scheduleInfo.scheduleId.toString(),
228+
scheduleInfo.creatorAccountId.toString(),
229+
scheduleInfo.payerAccountId.toString(),
230+
adminKey,
231+
signers,
232+
scheduleInfo.memo,
233+
expirationTime,
234+
executedAt,
235+
deletedAt,
236+
scheduleTransactionId,
237+
scheduleInfo.waitForExpiry,
238+
null);
239+
}
193240
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
package com.hedera.hashgraph.tck.methods.sdk.param.schedule;
3+
4+
import com.hedera.hashgraph.tck.methods.JSONRPC2Param;
5+
import com.hedera.hashgraph.tck.util.JSONRPCParamParser;
6+
import java.util.Map;
7+
import java.util.Objects;
8+
import lombok.AllArgsConstructor;
9+
import lombok.Getter;
10+
import lombok.NoArgsConstructor;
11+
12+
@Getter
13+
@AllArgsConstructor
14+
@NoArgsConstructor
15+
public class ScheduleInfoParams extends JSONRPC2Param {
16+
private String scheduleId;
17+
private String queryPayment;
18+
private String maxQueryPayment;
19+
private Boolean getCost;
20+
private String sessionId;
21+
22+
@Override
23+
public JSONRPC2Param parse(Map<String, Object> jrpcParams) throws Exception {
24+
Objects.requireNonNull(jrpcParams, "jrpcParams must not be null");
25+
26+
var parsedScheduleId = (String) jrpcParams.get("scheduleId");
27+
var parsedQueryPayment = (String) jrpcParams.get("queryPayment");
28+
var parsedMaxQueryPayment = (String) jrpcParams.get("maxQueryPayment");
29+
var parsedGetCost = (Boolean) jrpcParams.get("getCost");
30+
31+
return new ScheduleInfoParams(
32+
parsedScheduleId,
33+
parsedQueryPayment,
34+
parsedMaxQueryPayment,
35+
parsedGetCost != null ? parsedGetCost : false,
36+
JSONRPCParamParser.parseSessionId(jrpcParams));
37+
}
38+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
package com.hedera.hashgraph.tck.methods.sdk.response.schedule;
3+
4+
import jakarta.annotation.Nullable;
5+
import java.util.List;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Data;
8+
import net.minidev.json.JSONAware;
9+
import net.minidev.json.JSONObject;
10+
11+
@Data
12+
@AllArgsConstructor
13+
public class ScheduleInfoResponse implements JSONAware {
14+
private String scheduleId;
15+
private String creatorAccountId;
16+
private String payerAccountId;
17+
18+
@Nullable
19+
private String adminKey;
20+
21+
private List<String> signers;
22+
private String scheduleMemo;
23+
24+
@Nullable
25+
private String expirationTime;
26+
27+
@Nullable
28+
private String executed;
29+
30+
@Nullable
31+
private String deleted;
32+
33+
@Nullable
34+
private String scheduledTransactionId;
35+
36+
private Boolean waitForExpiry;
37+
38+
@Nullable
39+
private String cost;
40+
41+
public static ScheduleInfoResponse forCostOnly(String cost) {
42+
return new ScheduleInfoResponse(null, null, null, null, null, null, null, null, null, null, null, cost);
43+
}
44+
45+
@Override
46+
public String toJSONString() {
47+
JSONObject json = new JSONObject();
48+
putIfNotNull(json, "scheduleId", scheduleId);
49+
putIfNotNull(json, "creatorAccountId", creatorAccountId);
50+
putIfNotNull(json, "payerAccountId", payerAccountId);
51+
putIfNotNull(json, "adminKey", adminKey);
52+
putIfNotNull(json, "signers", signers);
53+
putIfNotNull(json, "scheduleMemo", scheduleMemo);
54+
putIfNotNull(json, "expirationTime", expirationTime);
55+
putIfNotNull(json, "executed", executed);
56+
putIfNotNull(json, "deleted", deleted);
57+
putIfNotNull(json, "scheduledTransactionId", scheduledTransactionId);
58+
putIfNotNull(json, "waitForExpiry", waitForExpiry);
59+
putIfNotNull(json, "cost", cost);
60+
return json.toJSONString();
61+
}
62+
63+
private void putIfNotNull(JSONObject json, String key, Object value) {
64+
if (value != null) {
65+
json.put(key, value);
66+
}
67+
}
68+
}

tck/src/main/java/com/hedera/hashgraph/tck/methods/sdk/response/ScheduleResponse.java renamed to tck/src/main/java/com/hedera/hashgraph/tck/methods/sdk/response/schedule/ScheduleResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
package com.hedera.hashgraph.tck.methods.sdk.response;
2+
package com.hedera.hashgraph.tck.methods.sdk.response.schedule;
33

44
import com.hedera.hashgraph.sdk.Status;
55
import lombok.Data;

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
import com.hedera.hashgraph.sdk.FileId;
1111
import com.hedera.hashgraph.sdk.Hbar;
1212
import com.hedera.hashgraph.sdk.NftId;
13+
import com.hedera.hashgraph.sdk.ScheduleId;
14+
import com.hedera.hashgraph.sdk.ScheduleInfoQuery;
1315
import com.hedera.hashgraph.sdk.TokenId;
1416
import com.hedera.hashgraph.sdk.TokenInfoQuery;
1517
import com.hedera.hashgraph.sdk.TokenNftInfoQuery;
1618
import com.hedera.hashgraph.tck.methods.sdk.param.account.AccountBalanceQueryParams;
1719
import com.hedera.hashgraph.tck.methods.sdk.param.contract.ContractByteCodeQueryParams;
1820
import com.hedera.hashgraph.tck.methods.sdk.param.contract.ContractCallQueryParams;
1921
import com.hedera.hashgraph.tck.methods.sdk.param.file.FileContentsParams;
22+
import com.hedera.hashgraph.tck.methods.sdk.param.schedule.ScheduleInfoParams;
2023
import com.hedera.hashgraph.tck.methods.sdk.param.token.NftInfoQueryParams;
2124
import com.hedera.hashgraph.tck.methods.sdk.param.token.TokenInfoQueryParams;
2225
import java.time.Duration;
@@ -61,6 +64,30 @@ public static AccountBalanceQuery buildAccountBalanceQuery(AccountBalanceQueryPa
6164
}
6265
}
6366

67+
/**
68+
* Schedule-related query builders
69+
*/
70+
public static class ScheduleBuilder {
71+
72+
public static ScheduleInfoQuery buildScheduleInfoQuery(ScheduleInfoParams params) {
73+
ScheduleInfoQuery query = new ScheduleInfoQuery().setGrpcDeadline((DEFAULT_GRPC_DEADLINE));
74+
75+
if (params.getScheduleId() != null) {
76+
query.setScheduleId(ScheduleId.fromString(params.getScheduleId()));
77+
}
78+
79+
if (params.getQueryPayment() != null) {
80+
query.setQueryPayment(Hbar.fromTinybars(Long.parseLong(params.getQueryPayment())));
81+
}
82+
83+
if (params.getMaxQueryPayment() != null) {
84+
query.setMaxQueryPayment(Hbar.fromTinybars(Long.parseLong(params.getMaxQueryPayment())));
85+
}
86+
87+
return query;
88+
}
89+
}
90+
6491
/**
6592
* File-related query builders
6693
*/

0 commit comments

Comments
 (0)