Skip to content

Commit ff0e5b0

Browse files
authored
TCK implement ScheduleSignTransaction (#2485)
Signed-off-by: emiliyank <e.kadiyski@gmail.com>
1 parent 8d85ef6 commit ff0e5b0

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.hedera.hashgraph.tck.annotation.JSONRPC2Service;
77
import com.hedera.hashgraph.tck.methods.AbstractJSONRPC2Service;
88
import com.hedera.hashgraph.tck.methods.sdk.param.schedule.ScheduleCreateParams;
9+
import com.hedera.hashgraph.tck.methods.sdk.param.schedule.ScheduleSignParams;
910
import com.hedera.hashgraph.tck.methods.sdk.response.ScheduleResponse;
1011
import com.hedera.hashgraph.tck.util.KeyUtils;
1112
import com.hedera.hashgraph.tck.util.TransactionBuilders;
@@ -78,6 +79,33 @@ public ScheduleResponse createSchedule(final ScheduleCreateParams params) throws
7879
return new ScheduleResponse(scheduleId, transactionId, receipt.status);
7980
}
8081

82+
@JSONRPC2Method("signSchedule")
83+
public ScheduleResponse signSchedule(final ScheduleSignParams params) throws Exception {
84+
ScheduleSignTransaction transaction = new ScheduleSignTransaction().setGrpcDeadline(DEFAULT_GRPC_DEADLINE);
85+
86+
params.getScheduleId()
87+
.ifPresent(scheduleIdStr -> transaction.setScheduleId(ScheduleId.fromString(scheduleIdStr)));
88+
89+
params.getCommonTransactionParams()
90+
.ifPresent(common -> common.fillOutTransaction(transaction, sdkService.getClient()));
91+
92+
TransactionResponse txResponse = transaction.execute(sdkService.getClient());
93+
TransactionReceipt receipt = txResponse.getReceipt(sdkService.getClient());
94+
95+
String scheduleId = "";
96+
String transactionId = "";
97+
if (receipt.status == Status.SUCCESS) {
98+
if (params.getScheduleId().isPresent()) {
99+
scheduleId = params.getScheduleId().get();
100+
}
101+
if (receipt.scheduledTransactionId != null) {
102+
transactionId = receipt.scheduledTransactionId.toString();
103+
}
104+
}
105+
106+
return new ScheduleResponse(scheduleId, transactionId, receipt.status);
107+
}
108+
81109
/**
82110
* Builds a scheduled transaction from method name and parameters
83111
*/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.methods.sdk.param.CommonTransactionParams;
6+
import com.hedera.hashgraph.tck.util.JSONRPCParamParser;
7+
import java.util.Map;
8+
import java.util.Optional;
9+
import lombok.AllArgsConstructor;
10+
import lombok.Getter;
11+
import lombok.NoArgsConstructor;
12+
13+
/**
14+
* ScheduleSignParams for sign schedule method
15+
*/
16+
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
17+
@Getter
18+
@AllArgsConstructor
19+
@NoArgsConstructor
20+
public class ScheduleSignParams extends JSONRPC2Param {
21+
private Optional<String> scheduleId;
22+
private Optional<CommonTransactionParams> commonTransactionParams;
23+
24+
@Override
25+
public ScheduleSignParams parse(Map<String, Object> jrpcParams) throws Exception {
26+
var parsedScheduleId = Optional.ofNullable((String) jrpcParams.get("scheduleId"));
27+
var parsedCommonTransactionParams = JSONRPCParamParser.parseCommonTransactionParams(jrpcParams);
28+
29+
return new ScheduleSignParams(parsedScheduleId, parsedCommonTransactionParams);
30+
}
31+
}

0 commit comments

Comments
 (0)