[#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:
Evgenii Stratonikov 2022-06-29 16:02:07 +03:00 committed by fyrchik
parent 0ccea802e9
commit f699e82ea7
3 changed files with 12 additions and 23 deletions

View file

@ -9,21 +9,12 @@ import "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
type customFees map[string]fixedn.Fixed8 type customFees map[string]fixedn.Fixed8
// setFeeForMethod sets fee for the operation executed using specified contract method. // setFeeForMethod sets fee for the operation executed using specified contract method.
func (x *customFees) setFeeForMethod(method string, fee fixedn.Fixed8) { func (x *fees) setFeeForMethod(method string, fee fixedn.Fixed8) {
m := *x if x.customFees == nil {
if m == nil { x.customFees = make(map[string]fixedn.Fixed8, 1)
m = make(map[string]fixedn.Fixed8, 1)
*x = m
} }
m[method] = fee x.customFees[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. // fees represents source of per-operation fees.
@ -33,20 +24,18 @@ func (x customFees) feeForMethod(method string) (fixedn.Fixed8, bool) {
type fees struct { type fees struct {
defaultFee fixedn.Fixed8 defaultFee fixedn.Fixed8
customFees // customFees represents source of customized per-operation fees.
} customFees map[string]fixedn.Fixed8
// 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 fee for the operation executed using specified contract method.
// Returns customized value if it is set. Otherwise, returns default value. // Returns customized value if it is set. Otherwise, returns default value.
func (x fees) feeForMethod(method string) fixedn.Fixed8 { func (x fees) feeForMethod(method string) fixedn.Fixed8 {
if fee, ok := x.customFees.feeForMethod(method); ok { if x.customFees != nil {
if fee, ok := x.customFees[method]; ok {
return fee return fee
} }
}
return x.defaultFee return x.defaultFee
} }

View file

@ -17,7 +17,7 @@ func TestFees(t *testing.T) {
def = fixedn.Fixed8(13) def = fixedn.Fixed8(13)
) )
v.setDefault(def) v.defaultFee = def
fee = v.feeForMethod(method) fee = v.feeForMethod(method)
require.True(t, fee.Equal(def)) require.True(t, fee.Equal(def))

View file

@ -63,7 +63,7 @@ func NewStatic(client *Client, scriptHash util.Uint160, fee fixedn.Fixed8, opts
scScriptHash: scriptHash, scScriptHash: scriptHash,
} }
c.fees.setDefault(fee) c.fees.defaultFee = fee
for i := range opts { for i := range opts {
opts[i](&c.staticOpts) opts[i](&c.staticOpts)