github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_nft_info.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 protobuf "google.golang.org/protobuf/proto" 28 ) 29 30 // TokenNftInfo is the information about a NFT 31 type TokenNftInfo struct { 32 NftID NftID 33 AccountID AccountID 34 CreationTime time.Time 35 Metadata []byte 36 LedgerID LedgerID 37 SpenderID AccountID 38 } 39 40 func _TokenNftInfoFromProtobuf(pb *services.TokenNftInfo) TokenNftInfo { 41 if pb == nil { 42 return TokenNftInfo{} 43 } 44 45 accountID := AccountID{} 46 if pb.AccountID != nil { 47 accountID = *_AccountIDFromProtobuf(pb.AccountID) 48 } 49 50 spenderID := AccountID{} 51 if pb.SpenderId != nil { 52 spenderID = *_AccountIDFromProtobuf(pb.SpenderId) 53 } 54 55 return TokenNftInfo{ 56 NftID: _NftIDFromProtobuf(pb.NftID), 57 AccountID: accountID, 58 CreationTime: _TimeFromProtobuf(pb.CreationTime), 59 Metadata: pb.Metadata, 60 LedgerID: LedgerID{pb.LedgerId}, 61 SpenderID: spenderID, 62 } 63 } 64 65 func (tokenNftInfo *TokenNftInfo) _ToProtobuf() *services.TokenNftInfo { 66 return &services.TokenNftInfo{ 67 NftID: tokenNftInfo.NftID._ToProtobuf(), 68 AccountID: tokenNftInfo.AccountID._ToProtobuf(), 69 CreationTime: _TimeToProtobuf(tokenNftInfo.CreationTime), 70 Metadata: tokenNftInfo.Metadata, 71 LedgerId: tokenNftInfo.LedgerID.ToBytes(), 72 SpenderId: tokenNftInfo.SpenderID._ToProtobuf(), 73 } 74 } 75 76 // ToBytes returns the byte representation of the TokenNftInfo 77 func (tokenNftInfo *TokenNftInfo) ToBytes() []byte { 78 data, err := protobuf.Marshal(tokenNftInfo._ToProtobuf()) 79 if err != nil { 80 return make([]byte, 0) 81 } 82 83 return data 84 } 85 86 // TokenNftInfoFromBytes returns the TokenNftInfo from a byte array representation 87 func TokenNftInfoFromBytes(data []byte) (TokenNftInfo, error) { 88 if data == nil { 89 return TokenNftInfo{}, errByteArrayNull 90 } 91 pb := services.TokenNftInfo{} 92 err := protobuf.Unmarshal(data, &pb) 93 if err != nil { 94 return TokenNftInfo{}, err 95 } 96 97 return _TokenNftInfoFromProtobuf(&pb), nil 98 }