github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/custom_royalty_fee.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 ) 26 27 // A royalty fee is a fractional fee that is assessed each time the ownership of an NFT is transferred from 28 // person A to person B. The fee collector account ID defined in the royalty fee schedule will receive the 29 // royalty fee each time. The royalty fee charged is a fraction of the value exchanged for the NFT. 30 type CustomRoyaltyFee struct { 31 CustomFee 32 Numerator int64 33 Denominator int64 34 FallbackFee *CustomFixedFee 35 } 36 37 // A royalty fee is a fractional fee that is assessed each time the ownership of an NFT is transferred from 38 // person A to person B. The fee collector account ID defined in the royalty fee schedule will receive the 39 // royalty fee each time. The royalty fee charged is a fraction of the value exchanged for the NFT. 40 func NewCustomRoyaltyFee() *CustomRoyaltyFee { 41 return &CustomRoyaltyFee{ 42 CustomFee: CustomFee{}, 43 Numerator: 0, 44 Denominator: 0, 45 FallbackFee: nil, 46 } 47 } 48 49 // SetFeeCollectorAccountID sets the account ID that will receive the custom fee 50 func (fee *CustomRoyaltyFee) SetFeeCollectorAccountID(accountID AccountID) *CustomRoyaltyFee { 51 fee.FeeCollectorAccountID = &accountID 52 return fee 53 } 54 55 // SetNumerator sets the numerator of the fractional fee 56 func (fee *CustomRoyaltyFee) SetNumerator(numerator int64) *CustomRoyaltyFee { 57 fee.Numerator = numerator 58 return fee 59 } 60 61 // SetDenominator sets the denominator of the fractional fee 62 func (fee *CustomRoyaltyFee) SetDenominator(denominator int64) *CustomRoyaltyFee { 63 fee.Denominator = denominator 64 return fee 65 } 66 67 // SetFallbackFee If present, the fixed fee to assess to the NFT receiver when no fungible value is exchanged with the sender 68 func (fee *CustomRoyaltyFee) SetFallbackFee(fallbackFee *CustomFixedFee) *CustomRoyaltyFee { 69 fee.FallbackFee = fallbackFee 70 return fee 71 } 72 73 // GetFeeCollectorAccountID returns the account ID that will receive the custom fee 74 func (fee *CustomRoyaltyFee) GetFeeCollectorAccountID() AccountID { 75 if fee.FeeCollectorAccountID != nil { 76 return *fee.FeeCollectorAccountID 77 } 78 79 return AccountID{} 80 } 81 82 // GetNumerator returns the numerator of the fee 83 func (fee *CustomRoyaltyFee) GetNumerator() int64 { 84 return fee.Numerator 85 } 86 87 // GetDenominator returns the denominator of the fee 88 func (fee *CustomRoyaltyFee) GetDenominator() int64 { 89 return fee.Denominator 90 } 91 92 // GetFallbackFee returns the fallback fee 93 func (fee *CustomRoyaltyFee) GetFallbackFee() CustomFixedFee { 94 if fee.FallbackFee != nil { 95 return *fee.FallbackFee 96 } 97 98 return CustomFixedFee{} 99 } 100 101 // SetAllCollectorsAreExempt sets whether all collectors are exempt from the fee 102 func (fee *CustomRoyaltyFee) SetAllCollectorsAreExempt(exempt bool) *CustomRoyaltyFee { 103 fee.AllCollectorsAreExempt = exempt 104 return fee 105 } 106 107 func _CustomRoyaltyFeeFromProtobuf(royalty *services.RoyaltyFee, fee CustomFee) CustomRoyaltyFee { 108 var fallback CustomFixedFee 109 if royalty.FallbackFee != nil { 110 fallback = _CustomFixedFeeFromProtobuf(royalty.FallbackFee, fee) 111 } 112 return CustomRoyaltyFee{ 113 CustomFee: fee, 114 Numerator: royalty.ExchangeValueFraction.Numerator, 115 Denominator: royalty.ExchangeValueFraction.Denominator, 116 FallbackFee: &fallback, 117 } 118 } 119 120 func (fee CustomRoyaltyFee) validateNetworkOnIDs(client *Client) error { 121 if client == nil || !client.autoValidateChecksums || fee.FallbackFee == nil { 122 return nil 123 } 124 125 return fee.FallbackFee.validateNetworkOnIDs(client) 126 } 127 128 func (fee CustomRoyaltyFee) _ToProtobuf() *services.CustomFee { 129 var fallback *services.FixedFee 130 if fee.FallbackFee != nil { 131 fallback = fee.FallbackFee._ToProtobuf().GetFixedFee() 132 } 133 134 var FeeCollectorAccountID *services.AccountID 135 if fee.FeeCollectorAccountID != nil { 136 FeeCollectorAccountID = fee.CustomFee.FeeCollectorAccountID._ToProtobuf() 137 } 138 139 return &services.CustomFee{ 140 Fee: &services.CustomFee_RoyaltyFee{ 141 RoyaltyFee: &services.RoyaltyFee{ 142 ExchangeValueFraction: &services.Fraction{ 143 Numerator: fee.Numerator, 144 Denominator: fee.Denominator, 145 }, 146 FallbackFee: fallback, 147 }, 148 }, 149 FeeCollectorAccountId: FeeCollectorAccountID, 150 AllCollectorsAreExempt: fee.AllCollectorsAreExempt, 151 } 152 }