forked from hiero-ledger/hiero-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_royalty_fee.go
152 lines (131 loc) · 4.69 KB
/
custom_royalty_fee.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package hedera
/*-
*
* Hedera Go SDK
*
* Copyright (C) 2020 - 2022 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import (
"github.com/hashgraph/hedera-protobufs-go/services"
)
// A royalty fee is a fractional fee that is assessed each time the ownership of an NFT is transferred from
// person A to person B. The fee collector account ID defined in the royalty fee schedule will receive the
// royalty fee each time. The royalty fee charged is a fraction of the value exchanged for the NFT.
type CustomRoyaltyFee struct {
CustomFee
Numerator int64
Denominator int64
FallbackFee *CustomFixedFee
}
// A royalty fee is a fractional fee that is assessed each time the ownership of an NFT is transferred from
// person A to person B. The fee collector account ID defined in the royalty fee schedule will receive the
// royalty fee each time. The royalty fee charged is a fraction of the value exchanged for the NFT.
func NewCustomRoyaltyFee() *CustomRoyaltyFee {
return &CustomRoyaltyFee{
CustomFee: CustomFee{},
Numerator: 0,
Denominator: 0,
FallbackFee: nil,
}
}
// SetFeeCollectorAccountID sets the account ID that will receive the custom fee
func (fee *CustomRoyaltyFee) SetFeeCollectorAccountID(accountID AccountID) *CustomRoyaltyFee {
fee.FeeCollectorAccountID = &accountID
return fee
}
// SetNumerator sets the numerator of the fractional fee
func (fee *CustomRoyaltyFee) SetNumerator(numerator int64) *CustomRoyaltyFee {
fee.Numerator = numerator
return fee
}
// SetDenominator sets the denominator of the fractional fee
func (fee *CustomRoyaltyFee) SetDenominator(denominator int64) *CustomRoyaltyFee {
fee.Denominator = denominator
return fee
}
// SetFallbackFee If present, the fixed fee to assess to the NFT receiver when no fungible value is exchanged with the sender
func (fee *CustomRoyaltyFee) SetFallbackFee(fallbackFee *CustomFixedFee) *CustomRoyaltyFee {
fee.FallbackFee = fallbackFee
return fee
}
// GetFeeCollectorAccountID returns the account ID that will receive the custom fee
func (fee *CustomRoyaltyFee) GetFeeCollectorAccountID() AccountID {
if fee.FeeCollectorAccountID != nil {
return *fee.FeeCollectorAccountID
}
return AccountID{}
}
// GetNumerator returns the numerator of the fee
func (fee *CustomRoyaltyFee) GetNumerator() int64 {
return fee.Numerator
}
// GetDenominator returns the denominator of the fee
func (fee *CustomRoyaltyFee) GetDenominator() int64 {
return fee.Denominator
}
// GetFallbackFee returns the fallback fee
func (fee *CustomRoyaltyFee) GetFallbackFee() CustomFixedFee {
if fee.FallbackFee != nil {
return *fee.FallbackFee
}
return CustomFixedFee{}
}
// SetAllCollectorsAreExempt sets whether all collectors are exempt from the fee
func (fee *CustomRoyaltyFee) SetAllCollectorsAreExempt(exempt bool) *CustomRoyaltyFee {
fee.AllCollectorsAreExempt = exempt
return fee
}
func _CustomRoyaltyFeeFromProtobuf(royalty *services.RoyaltyFee, fee CustomFee) CustomRoyaltyFee {
var fallback CustomFixedFee
if royalty.FallbackFee != nil {
fallback = _CustomFixedFeeFromProtobuf(royalty.FallbackFee, fee)
}
return CustomRoyaltyFee{
CustomFee: fee,
Numerator: royalty.ExchangeValueFraction.Numerator,
Denominator: royalty.ExchangeValueFraction.Denominator,
FallbackFee: &fallback,
}
}
func (fee CustomRoyaltyFee) _ValidateNetworkOnIDs(client *Client) error {
if client == nil || !client.autoValidateChecksums || fee.FallbackFee == nil {
return nil
}
return fee.FallbackFee._ValidateNetworkOnIDs(client)
}
func (fee CustomRoyaltyFee) _ToProtobuf() *services.CustomFee {
var fallback *services.FixedFee
if fee.FallbackFee != nil {
fallback = fee.FallbackFee._ToProtobuf().GetFixedFee()
}
var FeeCollectorAccountID *services.AccountID
if fee.FeeCollectorAccountID != nil {
FeeCollectorAccountID = fee.CustomFee.FeeCollectorAccountID._ToProtobuf()
}
return &services.CustomFee{
Fee: &services.CustomFee_RoyaltyFee{
RoyaltyFee: &services.RoyaltyFee{
ExchangeValueFraction: &services.Fraction{
Numerator: fee.Numerator,
Denominator: fee.Denominator,
},
FallbackFee: fallback,
},
},
FeeCollectorAccountId: FeeCollectorAccountID,
AllCollectorsAreExempt: fee.AllCollectorsAreExempt,
}
}