2021-12-07 09:54:21 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
|
|
|
|
|
|
|
// setFeeForMethod sets fee for the operation executed using specified contract method.
|
2022-06-29 13:02:07 +00:00
|
|
|
func (x *fees) setFeeForMethod(method string, fee fixedn.Fixed8) {
|
|
|
|
if x.customFees == nil {
|
|
|
|
x.customFees = make(map[string]fixedn.Fixed8, 1)
|
2021-12-07 09:54:21 +00:00
|
|
|
}
|
|
|
|
|
2022-06-29 13:02:07 +00:00
|
|
|
x.customFees[method] = fee
|
2021-12-07 09:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// fees represents source of per-operation fees.
|
|
|
|
// Can be initialized using var declaration.
|
|
|
|
//
|
|
|
|
// Instances are not thread-safe, so they mean initially filling, and then only reading.
|
|
|
|
type fees struct {
|
|
|
|
defaultFee fixedn.Fixed8
|
|
|
|
|
2022-06-29 13:02:07 +00:00
|
|
|
// customFees represents source of customized per-operation fees.
|
|
|
|
customFees map[string]fixedn.Fixed8
|
2021-12-07 09:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// returns fee for the operation executed using specified contract method.
|
|
|
|
// Returns customized value if it is set. Otherwise, returns default value.
|
|
|
|
func (x fees) feeForMethod(method string) fixedn.Fixed8 {
|
2022-06-29 13:02:07 +00:00
|
|
|
if x.customFees != nil {
|
|
|
|
if fee, ok := x.customFees[method]; ok {
|
|
|
|
return fee
|
|
|
|
}
|
2021-12-07 09:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return x.defaultFee
|
|
|
|
}
|