github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/file_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 // FileInfoQuery is a query which can be used to get all of the information about a file, except for its contents. 30 // When a file expires, it no longer exists, and there will be no info about it, and the fileInfo field will be blank. 31 // If a transaction or smart contract deletes the file, but it has not yet expired, then the 32 // fileInfo field will be non-empty, the deleted field will be true, its size will be 0, 33 // and its contents will be empty. Note that each file has a FileID, but does not have a filename. 34 type FileInfoQuery struct { 35 Query 36 fileID *FileID 37 } 38 39 // NewFileInfoQuery creates a FileInfoQuery which can be used to get all of the information about a file, except for its contents. 40 func NewFileInfoQuery() *FileInfoQuery { 41 header := services.QueryHeader{} 42 return &FileInfoQuery{ 43 Query: _NewQuery(true, &header), 44 } 45 } 46 47 // When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.) 48 func (q *FileInfoQuery) SetGrpcDeadline(deadline *time.Duration) *FileInfoQuery { 49 q.Query.SetGrpcDeadline(deadline) 50 return q 51 } 52 53 // SetFileID sets the FileID of the file whose info is requested. 54 func (q *FileInfoQuery) SetFileID(fileID FileID) *FileInfoQuery { 55 q.fileID = &fileID 56 return q 57 } 58 59 // GetFileID returns the FileID of the file whose info is requested. 60 func (q *FileInfoQuery) GetFileID() FileID { 61 if q.fileID == nil { 62 return FileID{} 63 } 64 65 return *q.fileID 66 } 67 68 func (q *FileInfoQuery) GetCost(client *Client) (Hbar, error) { 69 return q.Query.getCost(client, q) 70 } 71 72 // Execute executes the Query with the provided client 73 func (q *FileInfoQuery) Execute(client *Client) (FileInfo, error) { 74 resp, err := q.Query.execute(client, q) 75 76 if err != nil { 77 return FileInfo{}, err 78 } 79 80 info, err := _FileInfoFromProtobuf(resp.GetFileGetInfo().FileInfo) 81 if err != nil { 82 return FileInfo{}, err 83 } 84 85 return info, nil 86 } 87 88 // SetMaxQueryPayment sets the maximum payment allowed for this Query. 89 func (q *FileInfoQuery) SetMaxQueryPayment(maxPayment Hbar) *FileInfoQuery { 90 q.Query.SetMaxQueryPayment(maxPayment) 91 return q 92 } 93 94 // SetQueryPayment sets the payment amount for this Query. 95 func (q *FileInfoQuery) SetQueryPayment(paymentAmount Hbar) *FileInfoQuery { 96 q.Query.SetQueryPayment(paymentAmount) 97 return q 98 } 99 100 // SetNodeAccountIDs sets the _Node AccountID for this FileInfoQuery. 101 func (q *FileInfoQuery) SetNodeAccountIDs(accountID []AccountID) *FileInfoQuery { 102 q.Query.SetNodeAccountIDs(accountID) 103 return q 104 } 105 106 // SetMaxRetry sets the max number of errors before execution will fail. 107 func (q *FileInfoQuery) SetMaxRetry(count int) *FileInfoQuery { 108 q.Query.SetMaxRetry(count) 109 return q 110 } 111 112 // SetMaxBackoff The maximum amount of time to wait between retries. 113 // Every retry attempt will increase the wait time exponentially until it reaches this time. 114 func (q *FileInfoQuery) SetMaxBackoff(max time.Duration) *FileInfoQuery { 115 q.Query.SetMaxBackoff(max) 116 return q 117 } 118 119 // SetMinBackoff sets the minimum amount of time to wait between retries. 120 func (q *FileInfoQuery) SetMinBackoff(min time.Duration) *FileInfoQuery { 121 q.Query.SetMinBackoff(min) 122 return q 123 } 124 125 // SetPaymentTransactionID assigns the payment transaction id. 126 func (q *FileInfoQuery) SetPaymentTransactionID(transactionID TransactionID) *FileInfoQuery { 127 q.Query.SetPaymentTransactionID(transactionID) 128 return q 129 } 130 131 func (q *FileInfoQuery) SetLogLevel(level LogLevel) *FileInfoQuery { 132 q.Query.SetLogLevel(level) 133 return q 134 } 135 136 // ---------- Parent functions specific implementation ---------- 137 138 func (q *FileInfoQuery) getMethod(channel *_Channel) _Method { 139 return _Method{ 140 query: channel._GetFile().GetFileInfo, 141 } 142 } 143 144 func (q *FileInfoQuery) getName() string { 145 return "FileInfoQuery" 146 } 147 148 func (q *FileInfoQuery) buildQuery() *services.Query { 149 body := &services.FileGetInfoQuery{ 150 Header: q.pbHeader, 151 } 152 153 if q.fileID != nil { 154 body.FileID = q.fileID._ToProtobuf() 155 } 156 157 return &services.Query{ 158 Query: &services.Query_FileGetInfo{ 159 FileGetInfo: body, 160 }, 161 } 162 } 163 164 func (q *FileInfoQuery) validateNetworkOnIDs(client *Client) error { 165 if client == nil || !client.autoValidateChecksums { 166 return nil 167 } 168 169 if q.fileID != nil { 170 if err := q.fileID.ValidateChecksum(client); err != nil { 171 return err 172 } 173 } 174 175 return nil 176 } 177 178 func (q *FileInfoQuery) getQueryResponse(response *services.Response) queryResponse { 179 return response.GetFileGetInfo() 180 }