forked from TrueCloudLab/frostfs-node
[#342] morph: Remove unused toStackParameter()
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
02c02974b3
commit
6055b18362
2 changed files with 0 additions and 116 deletions
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue