forked from hiero-ledger/hiero-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_fee_limit.go
More file actions
98 lines (80 loc) · 2.58 KB
/
Copy pathcustom_fee_limit.go
File metadata and controls
98 lines (80 loc) · 2.58 KB
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
package hiero
import "strings"
import "github.com/hiero-ledger/hiero-sdk-go/v2/proto/services"
// SPDX-License-Identifier: Apache-2.0
// A maximum custom fee that the user is willing to pay.
// See HIP-991 for more information hips.hedera.com/hip/hip-991
type CustomFeeLimit struct {
PayerId *AccountID
CustomFees []*CustomFixedFee
}
func NewCustomFeeLimit() *CustomFeeLimit {
return &CustomFeeLimit{}
}
func customFeeLimitFromProtobuf(customFeeLimit *services.CustomFeeLimit) *CustomFeeLimit {
if customFeeLimit == nil {
return &CustomFeeLimit{}
}
var payerId *AccountID
if customFeeLimit.AccountId != nil {
payerId = _AccountIDFromProtobuf(customFeeLimit.AccountId)
}
var customFees []*CustomFixedFee
for _, customFee := range customFeeLimit.Fees {
customFixedFee := _CustomFixedFeeFromProtobuf(customFee, CustomFee{})
customFees = append(customFees, customFixedFee)
}
return &CustomFeeLimit{
PayerId: payerId,
CustomFees: customFees,
}
}
// SetPayerId sets the account ID of the payer.
func (feeLimit *CustomFeeLimit) SetPayerId(payerId AccountID) *CustomFeeLimit {
feeLimit.PayerId = &payerId
return feeLimit
}
// GetPayerId returns the account ID of the payer.
func (feeLimit *CustomFeeLimit) GetPayerId() AccountID {
return *feeLimit.PayerId
}
// SetCustomFees sets the custom fees.
func (feeLimit *CustomFeeLimit) SetCustomFees(customFees []*CustomFixedFee) *CustomFeeLimit {
feeLimit.CustomFees = customFees
return feeLimit
}
// AddCustomFee adds a custom fee.
func (feeLimit *CustomFeeLimit) AddCustomFee(customFee *CustomFixedFee) *CustomFeeLimit {
feeLimit.CustomFees = append(feeLimit.CustomFees, customFee)
return feeLimit
}
// GetCustomFees returns the custom fees.
func (feeLimit *CustomFeeLimit) GetCustomFees() []*CustomFixedFee {
return feeLimit.CustomFees
}
func (feeLimit *CustomFeeLimit) toProtobuf() *services.CustomFeeLimit {
var fees []*services.FixedFee
for _, customFee := range feeLimit.CustomFees {
fees = append(fees, customFee._ToProtobuf().GetFixedFee())
}
var payerId *services.AccountID
if feeLimit.PayerId != nil {
payerId = feeLimit.PayerId._ToProtobuf()
}
return &services.CustomFeeLimit{
AccountId: payerId,
Fees: fees,
}
}
func (feeLimit *CustomFeeLimit) String() string {
var customFeesStr strings.Builder
customFeesStr.WriteString("[")
for i, fee := range feeLimit.CustomFees {
if i > 0 {
customFeesStr.WriteString(", ")
}
customFeesStr.WriteString(fee.String())
}
customFeesStr.WriteString("]")
return "CustomFeeLimit{PayerId: " + feeLimit.PayerId.String() + ", CustomFees: " + customFeesStr.String() + "}"
}