diff --git a/pkg/morph/client/fee.go b/pkg/morph/client/fee.go index 98016b9b..e7059da2 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 f33dba48..963d64ce 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 ccc805f7..856f3d5b 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)