Skip to content

Commit 3e2ca9d

Browse files
committed
feat: schedule sign
Signed-off-by: Ivan Ivanov <ivanivanov.ii726@gmail.com>
1 parent 5d43263 commit 3e2ca9d

4 files changed

Lines changed: 48 additions & 6 deletions

File tree

tck/cmd/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func main() {
8787
"updateContract": postHandler(HandleError, handler.New(contractService.UpdateContract)),
8888
"deleteContract": postHandler(HandleError, handler.New(contractService.DeleteContract)),
8989
"createSchedule": postHandler(HandleError, handler.New(scheduleService.CreateSchedule)),
90+
"signSchedule": postHandler(HandleError, handler.New(scheduleService.SignSchedule)),
9091
"generateKey": postHandler(HandleError, handler.New(methods.GenerateKey)),
9192
}
9293

tck/methods/schedule.go

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ func (s *ScheduleService) CreateSchedule(_ context.Context, params param.Schedul
5151
if err != nil {
5252
return nil, fmt.Errorf("failed to parse payer account ID: %w", err)
5353
}
54-
fmt.Println("asdf")
5554
transaction.SetPayerAccountID(payerAccountID)
5655
}
5756

@@ -78,7 +77,7 @@ func (s *ScheduleService) CreateSchedule(_ context.Context, params param.Schedul
7877
if err != nil {
7978
return nil, err
8079
}
81-
receipt, err := txResponse.GetReceipt(s.sdkService.Client)
80+
receipt, err := txResponse.SetValidateStatus(true).GetReceipt(s.sdkService.Client)
8281
if err != nil {
8382
return nil, err
8483
}
@@ -88,9 +87,44 @@ func (s *ScheduleService) CreateSchedule(_ context.Context, params param.Schedul
8887
scheduleId = receipt.ScheduleID.String()
8988
}
9089

90+
fmt.Println(receipt.ScheduledTransactionID)
9191
return &response.ScheduleResponse{
92-
ScheduleId: scheduleId,
93-
Status: receipt.Status.String(),
92+
ScheduleId: scheduleId,
93+
TransactionId: receipt.ScheduledTransactionID.String(),
94+
Status: receipt.Status.String(),
95+
}, nil
96+
}
97+
98+
// SignSchedule jRPC method for signSchedule
99+
func (s *ScheduleService) SignSchedule(_ context.Context, params param.ScheduleSignParams) (*response.ScheduleResponse, error) {
100+
transaction := hiero.NewScheduleSignTransaction().SetGrpcDeadline(&threeSecondsDuration)
101+
102+
if params.ScheduleId != nil {
103+
scheduleID, err := hiero.ScheduleIDFromString(*params.ScheduleId)
104+
if err != nil {
105+
return nil, fmt.Errorf("failed to parse schedule ID: %w", err)
106+
}
107+
transaction.SetScheduleID(scheduleID)
108+
}
109+
110+
if params.CommonTransactionParams != nil {
111+
err := params.CommonTransactionParams.FillOutTransaction(transaction, s.sdkService.Client)
112+
if err != nil {
113+
return nil, err
114+
}
115+
}
116+
117+
txResponse, err := transaction.Execute(s.sdkService.Client)
118+
if err != nil {
119+
return nil, err
120+
}
121+
receipt, err := txResponse.SetValidateStatus(true).GetReceipt(s.sdkService.Client)
122+
if err != nil {
123+
return nil, err
124+
}
125+
126+
return &response.ScheduleResponse{
127+
Status: receipt.Status.String(),
94128
}, nil
95129
}
96130

tck/param/schedule.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ type ScheduleCreateParams struct {
2020
WaitForExpiry *bool `json:"waitForExpiry,omitempty"`
2121
CommonTransactionParams *CommonTransactionParams `json:"commonTransactionParams,omitempty"`
2222
}
23+
24+
// ScheduleSignParams represents the parameters for signing a schedule
25+
type ScheduleSignParams struct {
26+
ScheduleId *string `json:"scheduleId,omitempty"`
27+
CommonTransactionParams *CommonTransactionParams `json:"commonTransactionParams,omitempty"`
28+
}

tck/response/schedule.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package response
44

55
// ScheduleResponse represents the response from schedule-related operations
66
type ScheduleResponse struct {
7-
ScheduleId string `json:"scheduleId,omitempty"`
8-
Status string `json:"status"`
7+
ScheduleId string `json:"scheduleId,omitempty"`
8+
TransactionId string `json:"transactionId,omitempty"`
9+
Status string `json:"status"`
910
}

0 commit comments

Comments
 (0)