From 6055b183620da920d821053f69b02e7dc55e4215 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 12 May 2023 13:24:08 +0300 Subject: [PATCH] [#342] morph: Remove unused toStackParameter() Signed-off-by: Evgenii Stratonikov --- pkg/morph/client/client.go | 59 --------------------------------- pkg/morph/client/client_test.go | 57 ------------------------------- 2 files changed, 116 deletions(-) delete mode 100644 pkg/morph/client/client_test.go diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index 284e065fb..c9ff14a66 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -21,7 +21,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17" "github.com/nspcc-dev/neo-go/pkg/rpcclient/rolemgmt" "github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap" - sc "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" @@ -444,64 +443,6 @@ func (c *Client) roleList(r noderoles.Role) (keys.PublicKeys, error) { return c.rolemgmt.GetDesignatedByRole(r, height) } -// tries to resolve sc.Parameter from the arg. -// -// Wraps any error to frostfsError. -func toStackParameter(value any) (sc.Parameter, error) { - var res = sc.Parameter{ - Value: value, - } - - switch v := value.(type) { - case []byte: - res.Type = sc.ByteArrayType - case int: - res.Type = sc.IntegerType - res.Value = big.NewInt(int64(v)) - case int64: - res.Type = sc.IntegerType - res.Value = big.NewInt(v) - case uint64: - res.Type = sc.IntegerType - res.Value = new(big.Int).SetUint64(v) - case [][]byte: - arr := make([]sc.Parameter, 0, len(v)) - for i := range v { - elem, err := toStackParameter(v[i]) - if err != nil { - return res, err - } - - arr = append(arr, elem) - } - - res.Type = sc.ArrayType - res.Value = arr - case string: - res.Type = sc.StringType - case util.Uint160: - res.Type = sc.ByteArrayType - res.Value = v.BytesBE() - case noderoles.Role: - res.Type = sc.IntegerType - res.Value = big.NewInt(int64(v)) - case keys.PublicKeys: - arr := make([][]byte, 0, len(v)) - for i := range v { - arr = append(arr, v[i].Bytes()) - } - - return toStackParameter(arr) - case bool: - res.Type = sc.BoolType - res.Value = v - default: - return res, wrapFrostFSError(fmt.Errorf("chain/client: unsupported parameter %v", value)) - } - - return res, nil -} - // MagicNumber returns the magic number of the network // to which the underlying RPC node client is connected. func (c *Client) MagicNumber() (uint64, error) { diff --git a/pkg/morph/client/client_test.go b/pkg/morph/client/client_test.go deleted file mode 100644 index a448c2cf4..000000000 --- a/pkg/morph/client/client_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package client - -import ( - "math/big" - "testing" - - sc "github.com/nspcc-dev/neo-go/pkg/smartcontract" - "github.com/stretchr/testify/require" -) - -func TestToStackParameter(t *testing.T) { - items := []struct { - value any - expType sc.ParamType - expVal any - }{ - { - value: []byte{1, 2, 3}, - expType: sc.ByteArrayType, - }, - { - value: int64(100), - expType: sc.IntegerType, - expVal: big.NewInt(100), - }, - { - value: uint64(100), - expType: sc.IntegerType, - expVal: big.NewInt(100), - }, - { - value: "hello world", - expType: sc.StringType, - }, - { - value: false, - expType: sc.BoolType, - }, - { - value: true, - expType: sc.BoolType, - }, - } - - for _, item := range items { - t.Run(item.expType.String()+" to stack parameter", func(t *testing.T) { - res, err := toStackParameter(item.value) - require.NoError(t, err) - require.Equal(t, item.expType, res.Type) - if item.expVal != nil { - require.Equal(t, item.expVal, res.Value) - } else { - require.Equal(t, item.value, res.Value) - } - }) - } -}