github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_relationship.go (about) 1 package hedera 2 3 import ( 4 "github.com/hashgraph/hedera-protobufs-go/services" 5 "github.com/pkg/errors" 6 protobuf "google.golang.org/protobuf/proto" 7 ) 8 9 /*- 10 * 11 * Hedera Go SDK 12 * 13 * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC 14 * 15 * Licensed under the Apache License, Version 2.0 (the "License"); 16 * you may not use this file except in compliance with the License. 17 * You may obtain a copy of the License at 18 * 19 * http://www.apache.org/licenses/LICENSE-2.0 20 * 21 * Unless required by applicable law or agreed to in writing, software 22 * distributed under the License is distributed on an "AS IS" BASIS, 23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 * See the License for the specific language governing permissions and 25 * limitations under the License. 26 * 27 */ 28 29 // TokenRelationship is the information about a token relationship 30 type TokenRelationship struct { 31 TokenID TokenID 32 Symbol string 33 Balance uint64 34 KycStatus *bool 35 FreezeStatus *bool 36 Decimals uint32 37 AutomaticAssociation bool 38 } 39 40 func _TokenRelationshipFromProtobuf(pb *services.TokenRelationship) *TokenRelationship { 41 if pb == nil { 42 return &TokenRelationship{} 43 } 44 45 tokenID := TokenID{} 46 if pb.TokenId != nil { 47 tokenID = *_TokenIDFromProtobuf(pb.TokenId) 48 } 49 50 return &TokenRelationship{ 51 TokenID: tokenID, 52 Symbol: pb.Symbol, 53 Balance: pb.Balance, 54 KycStatus: _KycStatusFromProtobuf(pb.KycStatus), 55 FreezeStatus: _FreezeStatusFromProtobuf(pb.FreezeStatus), 56 Decimals: pb.Decimals, 57 AutomaticAssociation: pb.AutomaticAssociation, 58 } 59 } 60 61 func (relationship *TokenRelationship) _ToProtobuf() *services.TokenRelationship { 62 var freezeStatus services.TokenFreezeStatus 63 switch *relationship.FreezeStatus { 64 case true: 65 freezeStatus = 1 66 case false: 67 freezeStatus = 2 68 default: 69 freezeStatus = 0 70 } 71 72 var kycStatus services.TokenKycStatus 73 switch *relationship.KycStatus { 74 case true: 75 kycStatus = 1 76 case false: 77 kycStatus = 2 78 default: 79 kycStatus = 0 80 } 81 82 return &services.TokenRelationship{ 83 TokenId: relationship.TokenID._ToProtobuf(), 84 Symbol: relationship.Symbol, 85 Balance: relationship.Balance, 86 KycStatus: kycStatus, 87 FreezeStatus: freezeStatus, 88 Decimals: relationship.Decimals, 89 AutomaticAssociation: relationship.AutomaticAssociation, 90 } 91 } 92 93 func (relationship TokenRelationship) ToBytes() []byte { 94 data, err := protobuf.Marshal(relationship._ToProtobuf()) 95 if err != nil { 96 return make([]byte, 0) 97 } 98 99 return data 100 } 101 102 func _TokenRelationshipsFromProtobuf(rels []*services.TokenRelationship) []*TokenRelationship { 103 tokenRelationships := make([]*TokenRelationship, 0) 104 for _, tokenRelationship := range rels { 105 tokenRelationships = append(tokenRelationships, _TokenRelationshipFromProtobuf(tokenRelationship)) 106 } 107 return tokenRelationships 108 } 109 110 func TokenRelationshipFromBytes(data []byte) (*TokenRelationship, error) { 111 if data == nil { 112 return &TokenRelationship{}, errors.New("byte array can't be null") 113 } 114 pb := services.TokenRelationship{} 115 err := protobuf.Unmarshal(data, &pb) 116 if err != nil { 117 return &TokenRelationship{}, err 118 } 119 120 return _TokenRelationshipFromProtobuf(&pb), nil 121 }