github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/schedule_info_query.go (about) 1 package hedera 2 3 /*- 4 * 5 * Hedera Go SDK 6 * 7 * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 */ 22 23 import ( 24 "time" 25 26 "github.com/hashgraph/hedera-protobufs-go/services" 27 ) 28 29 // ScheduleInfoQuery Gets information about a schedule in the network's action queue. 30 type ScheduleInfoQuery struct { 31 Query 32 scheduleID *ScheduleID 33 } 34 35 // NewScheduleInfoQuery creates ScheduleInfoQuery which gets information about a schedule in the network's action queue. 36 func NewScheduleInfoQuery() *ScheduleInfoQuery { 37 header := services.QueryHeader{} 38 return &ScheduleInfoQuery{ 39 Query: _NewQuery(true, &header), 40 } 41 } 42 43 // When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.) 44 func (q *ScheduleInfoQuery) SetGrpcDeadline(deadline *time.Duration) *ScheduleInfoQuery { 45 q.Query.SetGrpcDeadline(deadline) 46 return q 47 } 48 49 // SetScheduleID Sets the id of the schedule to interrogate 50 func (q *ScheduleInfoQuery) SetScheduleID(scheduleID ScheduleID) *ScheduleInfoQuery { 51 q.scheduleID = &scheduleID 52 return q 53 } 54 55 // GetScheduleID returns the id of the schedule to interrogate 56 func (q *ScheduleInfoQuery) GetScheduleID() ScheduleID { 57 if q.scheduleID == nil { 58 return ScheduleID{} 59 } 60 61 return *q.scheduleID 62 } 63 64 func (q *ScheduleInfoQuery) GetCost(client *Client) (Hbar, error) { 65 return q.Query.getCost(client, q) 66 } 67 68 // Execute executes the Query with the provided client 69 func (q *ScheduleInfoQuery) Execute(client *Client) (ScheduleInfo, error) { 70 resp, err := q.Query.execute(client, q) 71 72 if err != nil { 73 return ScheduleInfo{}, err 74 } 75 76 return _ScheduleInfoFromProtobuf(resp.GetScheduleGetInfo().ScheduleInfo), nil 77 } 78 79 // SetMaxQueryPayment sets the maximum payment allowed for this Query. 80 func (q *ScheduleInfoQuery) SetMaxQueryPayment(maxPayment Hbar) *ScheduleInfoQuery { 81 q.Query.SetMaxQueryPayment(maxPayment) 82 return q 83 } 84 85 // SetQueryPayment sets the payment amount for this Query. 86 func (q *ScheduleInfoQuery) SetQueryPayment(paymentAmount Hbar) *ScheduleInfoQuery { 87 q.Query.SetQueryPayment(paymentAmount) 88 return q 89 } 90 91 // SetNodeAccountIDs sets the _Node AccountID for this ScheduleInfoQuery. 92 func (q *ScheduleInfoQuery) SetNodeAccountIDs(accountID []AccountID) *ScheduleInfoQuery { 93 q.Query.SetNodeAccountIDs(accountID) 94 return q 95 } 96 97 // SetMaxRetry sets the max number of errors before execution will fail. 98 func (q *ScheduleInfoQuery) SetMaxRetry(count int) *ScheduleInfoQuery { 99 q.Query.SetMaxRetry(count) 100 return q 101 } 102 103 // SetMaxBackoff The maximum amount of time to wait between retries. 104 // Every retry attempt will increase the wait time exponentially until it reaches this time. 105 func (q *ScheduleInfoQuery) SetMaxBackoff(max time.Duration) *ScheduleInfoQuery { 106 q.Query.SetMaxBackoff(max) 107 return q 108 } 109 110 // SetMinBackoff sets the minimum amount of time to wait between retries. 111 func (q *ScheduleInfoQuery) SetMinBackoff(min time.Duration) *ScheduleInfoQuery { 112 q.Query.SetMinBackoff(min) 113 return q 114 } 115 116 func (q *ScheduleInfoQuery) SetPaymentTransactionID(transactionID TransactionID) *ScheduleInfoQuery { 117 q.Query.SetPaymentTransactionID(transactionID) 118 return q 119 } 120 121 func (q *ScheduleInfoQuery) SetLogLevel(level LogLevel) *ScheduleInfoQuery { 122 q.Query.SetLogLevel(level) 123 return q 124 } 125 126 // ---------- Parent functions specific implementation ---------- 127 128 func (q *ScheduleInfoQuery) getMethod(channel *_Channel) _Method { 129 return _Method{ 130 query: channel._GetSchedule().GetScheduleInfo, 131 } 132 } 133 134 func (q *ScheduleInfoQuery) getName() string { 135 return "ScheduleInfoQuery" 136 } 137 138 func (q *ScheduleInfoQuery) buildQuery() *services.Query { 139 body := &services.ScheduleGetInfoQuery{ 140 Header: q.pbHeader, 141 } 142 143 if q.scheduleID != nil { 144 body.ScheduleID = q.scheduleID._ToProtobuf() 145 } 146 147 return &services.Query{ 148 Query: &services.Query_ScheduleGetInfo{ 149 ScheduleGetInfo: body, 150 }, 151 } 152 } 153 154 func (q *ScheduleInfoQuery) validateNetworkOnIDs(client *Client) error { 155 if client == nil || !client.autoValidateChecksums { 156 return nil 157 } 158 159 if q.scheduleID != nil { 160 if err := q.scheduleID.ValidateChecksum(client); err != nil { 161 return err 162 } 163 } 164 165 return nil 166 } 167 168 func (q *ScheduleInfoQuery) getQueryResponse(response *services.Response) queryResponse { 169 return response.GetScheduleGetInfo() 170 }