frostfs-node/pkg/morph/client/fee.go
Leonard Lyubich feb0a65efb [] ir/container: Customize fee for named container registration
In notary disabled environment, approval of container creation with nice
name attribute takes much more additional GAS than other operations
(due to NNS invocation).

Morph library changes:
  * add the ability to specify per-op fees using `StaticClient` options;
  * add the ability to customize fee for `Put` operation with named
    container in container morph client.

Inner Ring changes:
  * add `fee.named_container_register` config value which specifies
    additional GAS fee for the approvals of the named container
    registrations;
  * pass the config value to `WithCustomFeeForNamedPut` option of
    container morph client.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-12-08 13:57:01 +03:00

52 lines
1.4 KiB
Go

package client
import "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
// customFees represents source of customized per-operation fees.
// Can be initialized using var declaration.
//
// Instances are not thread-safe, so they mean initially filling, and then only reading.
type customFees map[string]fixedn.Fixed8
// setFeeForMethod sets fee for the operation executed using specified contract method.
func (x *customFees) setFeeForMethod(method string, fee fixedn.Fixed8) {
m := *x
if m == nil {
m = make(map[string]fixedn.Fixed8, 1)
*x = m
}
m[method] = fee
}
// returns customized for the operation executed using specified contract method.
// Returns false if fee is not customized.
func (x customFees) feeForMethod(method string) (fixedn.Fixed8, bool) {
v, ok := x[method]
return v, ok
}
// 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
customFees
}
// sets default fee for all operations.
func (x *fees) setDefault(fee fixedn.Fixed8) {
x.defaultFee = fee
}
// 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 {
if fee, ok := x.customFees.feeForMethod(method); ok {
return fee
}
return x.defaultFee
}