From f699e82ea7c47857fdcba8190effcc3339126a6a Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 29 Jun 2022 16:02:07 +0300 Subject: [PATCH] [#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 --- pkg/morph/client/fee.go | 31 ++++++++++--------------------- pkg/morph/client/fee_test.go | 2 +- pkg/morph/client/static.go | 2 +- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/pkg/morph/client/fee.go b/pkg/morph/client/fee.go index 98016b9b3..e7059da23 100644 --- a/pkg/morph/client/fee.go +++ b/pkg/morph/client/fee.go @@ -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 diff --git a/pkg/morph/client/fee_test.go b/pkg/morph/client/fee_test.go index f33dba489..963d64ce4 100644 --- a/pkg/morph/client/fee_test.go +++ b/pkg/morph/client/fee_test.go @@ -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)) diff --git a/pkg/morph/client/static.go b/pkg/morph/client/static.go index ccc805f74..856f3d5b9 100644 --- a/pkg/morph/client/static.go +++ b/pkg/morph/client/static.go @@ -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)