github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_nft_transfer.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  	"github.com/hashgraph/hedera-protobufs-go/services"
    25  	protobuf "google.golang.org/protobuf/proto"
    26  )
    27  
    28  // _TokenNftTransfer is the information about a NFT transfer
    29  type _TokenNftTransfer struct {
    30  	SenderAccountID   AccountID
    31  	ReceiverAccountID AccountID
    32  	SerialNumber      int64
    33  	IsApproved        bool
    34  }
    35  
    36  func _NftTransferFromProtobuf(pb *services.NftTransfer) _TokenNftTransfer {
    37  	if pb == nil {
    38  		return _TokenNftTransfer{}
    39  	}
    40  
    41  	senderAccountID := AccountID{}
    42  	if pb.SenderAccountID != nil {
    43  		senderAccountID = *_AccountIDFromProtobuf(pb.SenderAccountID)
    44  	}
    45  
    46  	receiverAccountID := AccountID{}
    47  	if pb.ReceiverAccountID != nil {
    48  		receiverAccountID = *_AccountIDFromProtobuf(pb.ReceiverAccountID)
    49  	}
    50  
    51  	return _TokenNftTransfer{
    52  		SenderAccountID:   senderAccountID,
    53  		ReceiverAccountID: receiverAccountID,
    54  		SerialNumber:      pb.SerialNumber,
    55  		IsApproved:        pb.IsApproval,
    56  	}
    57  }
    58  
    59  func (transfer *_TokenNftTransfer) _ToProtobuf() *services.NftTransfer {
    60  	return &services.NftTransfer{
    61  		SenderAccountID:   transfer.SenderAccountID._ToProtobuf(),
    62  		ReceiverAccountID: transfer.ReceiverAccountID._ToProtobuf(),
    63  		SerialNumber:      transfer.SerialNumber,
    64  		IsApproval:        transfer.IsApproved,
    65  	}
    66  }
    67  
    68  // ToBytes returns the byte representation of the TokenNftTransfer
    69  func (transfer _TokenNftTransfer) ToBytes() []byte {
    70  	data, err := protobuf.Marshal(transfer._ToProtobuf())
    71  	if err != nil {
    72  		return make([]byte, 0)
    73  	}
    74  
    75  	return data
    76  }
    77  
    78  // TokenNftTransfersFromBytes returns the TokenNftTransfer from a raw protobuf bytes representation
    79  func NftTransferFromBytes(data []byte) (_TokenNftTransfer, error) {
    80  	if data == nil {
    81  		return _TokenNftTransfer{}, errByteArrayNull
    82  	}
    83  	pb := services.NftTransfer{}
    84  	err := protobuf.Unmarshal(data, &pb)
    85  	if err != nil {
    86  		return _TokenNftTransfer{}, err
    87  	}
    88  
    89  	return _NftTransferFromProtobuf(&pb), nil
    90  }