github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_nft_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  // TokenNftInfoQuery
    30  // Applicable only to tokens of type NON_FUNGIBLE_UNIQUE.
    31  // Gets info on a NFT for a given TokenID (of type NON_FUNGIBLE_UNIQUE) and serial number
    32  type TokenNftInfoQuery struct {
    33  	Query
    34  	nftID *NftID
    35  }
    36  
    37  // NewTokenNftInfoQuery creates TokenNftInfoQuery which
    38  // gets info on a NFT for a given TokenID (of type NON_FUNGIBLE_UNIQUE) and serial number
    39  // Applicable only to tokens of type NON_FUNGIBLE_UNIQUE.
    40  func NewTokenNftInfoQuery() *TokenNftInfoQuery {
    41  	header := services.QueryHeader{}
    42  	return &TokenNftInfoQuery{
    43  		Query: _NewQuery(true, &header),
    44  		nftID: nil,
    45  	}
    46  }
    47  
    48  // When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.)
    49  func (q *TokenNftInfoQuery) SetGrpcDeadline(deadline *time.Duration) *TokenNftInfoQuery {
    50  	q.Query.SetGrpcDeadline(deadline)
    51  	return q
    52  }
    53  
    54  // SetNftID Sets the ID of the NFT
    55  func (q *TokenNftInfoQuery) SetNftID(nftID NftID) *TokenNftInfoQuery {
    56  	q.nftID = &nftID
    57  	return q
    58  }
    59  
    60  // GetNftID returns the ID of the NFT
    61  func (q *TokenNftInfoQuery) GetNftID() NftID {
    62  	if q.nftID == nil {
    63  		return NftID{}
    64  	}
    65  
    66  	return *q.nftID
    67  }
    68  
    69  // Deprecated
    70  func (q *TokenNftInfoQuery) SetTokenID(id TokenID) *TokenNftInfoQuery {
    71  	return q
    72  }
    73  
    74  // Deprecated
    75  func (q *TokenNftInfoQuery) GetTokenID() TokenID {
    76  	return TokenID{}
    77  }
    78  
    79  // Deprecated
    80  func (q *TokenNftInfoQuery) SetAccountID(id AccountID) *TokenNftInfoQuery {
    81  	return q
    82  }
    83  
    84  // Deprecated
    85  func (q *TokenNftInfoQuery) GetAccountID() AccountID {
    86  	return AccountID{}
    87  }
    88  
    89  // Deprecated
    90  func (q *TokenNftInfoQuery) SetStart(start int64) *TokenNftInfoQuery {
    91  	return q
    92  }
    93  
    94  // Deprecated
    95  func (q *TokenNftInfoQuery) GetStart() int64 {
    96  	return 0
    97  }
    98  
    99  // Deprecated
   100  func (q *TokenNftInfoQuery) SetEnd(end int64) *TokenNftInfoQuery {
   101  	return q
   102  }
   103  
   104  // Deprecated
   105  func (q *TokenNftInfoQuery) GetEnd() int64 {
   106  	return 0
   107  }
   108  
   109  // Deprecated
   110  func (q *TokenNftInfoQuery) ByNftID(id NftID) *TokenNftInfoQuery {
   111  	q.nftID = &id
   112  	return q
   113  }
   114  
   115  // Deprecated
   116  func (q *TokenNftInfoQuery) ByTokenID(id TokenID) *TokenNftInfoQuery {
   117  	return q
   118  }
   119  
   120  // Deprecated
   121  func (q *TokenNftInfoQuery) ByAccountID(id AccountID) *TokenNftInfoQuery {
   122  	return q
   123  }
   124  
   125  func (q *TokenNftInfoQuery) GetCost(client *Client) (Hbar, error) {
   126  	return q.Query.getCost(client, q)
   127  }
   128  
   129  // Execute executes the Query with the provided client
   130  func (q *TokenNftInfoQuery) Execute(client *Client) ([]TokenNftInfo, error) {
   131  	resp, err := q.Query.execute(client, q)
   132  
   133  	if err != nil {
   134  		return []TokenNftInfo{}, err
   135  	}
   136  
   137  	tokenInfos := make([]TokenNftInfo, 0)
   138  	tokenInfos = append(tokenInfos, _TokenNftInfoFromProtobuf(resp.GetTokenGetNftInfo().GetNft()))
   139  	return tokenInfos, nil
   140  }
   141  
   142  // SetMaxQueryPayment sets the maximum payment allowed for this Query.
   143  func (q *TokenNftInfoQuery) SetMaxQueryPayment(maxPayment Hbar) *TokenNftInfoQuery {
   144  	q.Query.SetMaxQueryPayment(maxPayment)
   145  	return q
   146  }
   147  
   148  // SetQueryPayment sets the payment amount for this Query.
   149  func (q *TokenNftInfoQuery) SetQueryPayment(paymentAmount Hbar) *TokenNftInfoQuery {
   150  	q.Query.SetQueryPayment(paymentAmount)
   151  	return q
   152  }
   153  
   154  // SetNodeAccountIDs sets the _Node AccountID for this TokenNftInfoQuery.
   155  func (q *TokenNftInfoQuery) SetNodeAccountIDs(accountID []AccountID) *TokenNftInfoQuery {
   156  	q.Query.SetNodeAccountIDs(accountID)
   157  	return q
   158  }
   159  
   160  // SetMaxRetry sets the max number of errors before execution will fail.
   161  func (q *TokenNftInfoQuery) SetMaxRetry(count int) *TokenNftInfoQuery {
   162  	q.Query.SetMaxRetry(count)
   163  	return q
   164  }
   165  
   166  // SetMaxBackoff The maximum amount of time to wait between retries.
   167  // Every retry attempt will increase the wait time exponentially until it reaches this time.
   168  func (q *TokenNftInfoQuery) SetMaxBackoff(max time.Duration) *TokenNftInfoQuery {
   169  	q.Query.SetMaxBackoff(max)
   170  	return q
   171  }
   172  
   173  // SetMinBackoff sets the minimum amount of time to wait between retries.
   174  func (q *TokenNftInfoQuery) SetMinBackoff(min time.Duration) *TokenNftInfoQuery {
   175  	q.Query.SetMinBackoff(min)
   176  	return q
   177  }
   178  
   179  // SetPaymentTransactionID assigns the payment transaction id.
   180  func (q *TokenNftInfoQuery) SetPaymentTransactionID(transactionID TransactionID) *TokenNftInfoQuery {
   181  	q.paymentTransactionIDs._Clear()._Push(transactionID)._SetLocked(true)
   182  	return q
   183  }
   184  
   185  func (q *TokenNftInfoQuery) SetLogLevel(level LogLevel) *TokenNftInfoQuery {
   186  	q.Query.SetLogLevel(level)
   187  	return q
   188  }
   189  
   190  // ---------- Parent functions specific implementation ----------
   191  
   192  func (q *TokenNftInfoQuery) getMethod(channel *_Channel) _Method {
   193  	return _Method{
   194  		query: channel._GetToken().GetTokenNftInfo,
   195  	}
   196  }
   197  
   198  func (q *TokenNftInfoQuery) getName() string {
   199  	return "TokenNftInfoQuery"
   200  }
   201  
   202  func (q *TokenNftInfoQuery) buildQuery() *services.Query {
   203  	body := &services.TokenGetNftInfoQuery{
   204  		Header: q.pbHeader,
   205  	}
   206  
   207  	if q.nftID != nil {
   208  		body.NftID = q.nftID._ToProtobuf()
   209  	}
   210  
   211  	return &services.Query{
   212  		Query: &services.Query_TokenGetNftInfo{
   213  			TokenGetNftInfo: body,
   214  		},
   215  	}
   216  }
   217  
   218  func (q *TokenNftInfoQuery) validateNetworkOnIDs(client *Client) error {
   219  	if client == nil || !client.autoValidateChecksums {
   220  		return nil
   221  	}
   222  
   223  	if q.nftID != nil {
   224  		if err := q.nftID.Validate(client); err != nil {
   225  			return err
   226  		}
   227  	}
   228  
   229  	return nil
   230  }
   231  
   232  func (q *TokenNftInfoQuery) getQueryResponse(response *services.Response) queryResponse {
   233  	return response.GetTokenGetNftInfo()
   234  }