forked from TrueCloudLab/frostfs-node
[#1560] morph/client: Remove customFees
type
It is private, is a simple map and there is no complex logic to be wrapped in methods. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
0ccea802e9
commit
f699e82ea7
3 changed files with 12 additions and 23 deletions
|
@ -9,21 +9,12 @@ import "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
|||
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
|
||||
func (x *fees) setFeeForMethod(method string, fee fixedn.Fixed8) {
|
||||
if x.customFees == nil {
|
||||
x.customFees = make(map[string]fixedn.Fixed8, 1)
|
||||
}
|
||||
|
||||
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
|
||||
x.customFees[method] = fee
|
||||
}
|
||||
|
||||
// fees represents source of per-operation fees.
|
||||
|
@ -33,19 +24,17 @@ func (x customFees) feeForMethod(method string) (fixedn.Fixed8, bool) {
|
|||
type fees struct {
|
||||
defaultFee fixedn.Fixed8
|
||||
|
||||
customFees
|
||||
}
|
||||
|
||||
// sets default fee for all operations.
|
||||
func (x *fees) setDefault(fee fixedn.Fixed8) {
|
||||
x.defaultFee = fee
|
||||
// customFees represents source of customized per-operation fees.
|
||||
customFees map[string]fixedn.Fixed8
|
||||
}
|
||||
|
||||
// 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
|
||||
if x.customFees != nil {
|
||||
if fee, ok := x.customFees[method]; ok {
|
||||
return fee
|
||||
}
|
||||
}
|
||||
|
||||
return x.defaultFee
|
||||
|
|
|
@ -17,7 +17,7 @@ func TestFees(t *testing.T) {
|
|||
def = fixedn.Fixed8(13)
|
||||
)
|
||||
|
||||
v.setDefault(def)
|
||||
v.defaultFee = def
|
||||
|
||||
fee = v.feeForMethod(method)
|
||||
require.True(t, fee.Equal(def))
|
||||
|
|
|
@ -63,7 +63,7 @@ func NewStatic(client *Client, scriptHash util.Uint160, fee fixedn.Fixed8, opts
|
|||
scScriptHash: scriptHash,
|
||||
}
|
||||
|
||||
c.fees.setDefault(fee)
|
||||
c.fees.defaultFee = fee
|
||||
|
||||
for i := range opts {
|
||||
opts[i](&c.staticOpts)
|
||||
|
|
Loading…
Reference in a new issue