forked from TrueCloudLab/frostfs-node
[#1141] morph/client: Allow to use more integer types as arguments
Also, use `*big.Int` as integer value, see nspcc-dev/neo-go#2413. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
57200e18cd
commit
9349f422fd
12 changed files with 30 additions and 16 deletions
|
@ -126,7 +126,7 @@ func (s *Server) voteForSidechainValidator(prm governance.VoteValidatorPrm) erro
|
||||||
}
|
}
|
||||||
|
|
||||||
s.contracts.alphabet.iterate(func(letter GlagoliticLetter, contract util.Uint160) {
|
s.contracts.alphabet.iterate(func(letter GlagoliticLetter, contract util.Uint160) {
|
||||||
err := s.morphClient.NotaryInvoke(contract, s.feeConfig.SideChainFee(), nonce, vubP, voteMethod, int64(epoch), validators)
|
err := s.morphClient.NotaryInvoke(contract, s.feeConfig.SideChainFee(), nonce, vubP, voteMethod, epoch, validators)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log.Warn("can't invoke vote method in alphabet contract",
|
s.log.Warn("can't invoke vote method in alphabet contract",
|
||||||
zap.Int8("alphabet_index", int8(letter)),
|
zap.Int8("alphabet_index", int8(letter)),
|
||||||
|
|
|
@ -25,7 +25,7 @@ func (c *Client) ListAllAuditResultID() ([]ResultID, error) {
|
||||||
func (c *Client) ListAuditResultIDByEpoch(epoch uint64) ([]ResultID, error) {
|
func (c *Client) ListAuditResultIDByEpoch(epoch uint64) ([]ResultID, error) {
|
||||||
prm := client.TestInvokePrm{}
|
prm := client.TestInvokePrm{}
|
||||||
prm.SetMethod(listByEpochResultsMethod)
|
prm.SetMethod(listByEpochResultsMethod)
|
||||||
prm.SetArgs(int64(epoch))
|
prm.SetArgs(epoch)
|
||||||
|
|
||||||
items, err := c.client.TestInvoke(prm)
|
items, err := c.client.TestInvoke(prm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -44,7 +44,7 @@ func (c *Client) ListAuditResultIDByCID(epoch uint64, cid *cid.ID) ([]ResultID,
|
||||||
|
|
||||||
prm := client.TestInvokePrm{}
|
prm := client.TestInvokePrm{}
|
||||||
prm.SetMethod(listByCIDResultsMethod)
|
prm.SetMethod(listByCIDResultsMethod)
|
||||||
prm.SetArgs(int64(epoch), v2.GetValue())
|
prm.SetArgs(epoch, v2.GetValue())
|
||||||
|
|
||||||
items, err := c.client.TestInvoke(prm)
|
items, err := c.client.TestInvoke(prm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -63,7 +63,7 @@ func (c *Client) ListAuditResultIDByNode(epoch uint64, cid *cid.ID, nodeKey []by
|
||||||
|
|
||||||
prm := client.TestInvokePrm{}
|
prm := client.TestInvokePrm{}
|
||||||
prm.SetMethod(listByNodeResultsMethod)
|
prm.SetMethod(listByNodeResultsMethod)
|
||||||
prm.SetArgs(int64(epoch), v2.GetValue(), nodeKey)
|
prm.SetArgs(epoch, v2.GetValue(), nodeKey)
|
||||||
|
|
||||||
items, err := c.client.TestInvoke(prm)
|
items, err := c.client.TestInvoke(prm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -445,12 +446,18 @@ func toStackParameter(value interface{}) (sc.Parameter, error) {
|
||||||
Value: value,
|
Value: value,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: #1141 add more types
|
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
case []byte:
|
case []byte:
|
||||||
result.Type = sc.ByteArrayType
|
result.Type = sc.ByteArrayType
|
||||||
|
case int:
|
||||||
|
result.Type = sc.IntegerType
|
||||||
|
result.Value = big.NewInt(int64(v))
|
||||||
case int64:
|
case int64:
|
||||||
result.Type = sc.IntegerType
|
result.Type = sc.IntegerType
|
||||||
|
result.Value = big.NewInt(v)
|
||||||
|
case uint64:
|
||||||
|
result.Type = sc.IntegerType
|
||||||
|
result.Value = new(big.Int).SetUint64(v)
|
||||||
case [][]byte:
|
case [][]byte:
|
||||||
arr := make([]sc.Parameter, 0, len(v))
|
arr := make([]sc.Parameter, 0, len(v))
|
||||||
for i := range v {
|
for i := range v {
|
||||||
|
@ -471,7 +478,7 @@ func toStackParameter(value interface{}) (sc.Parameter, error) {
|
||||||
result.Value = v.BytesBE()
|
result.Value = v.BytesBE()
|
||||||
case noderoles.Role:
|
case noderoles.Role:
|
||||||
result.Type = sc.IntegerType
|
result.Type = sc.IntegerType
|
||||||
result.Value = int64(v)
|
result.Value = big.NewInt(int64(v))
|
||||||
case keys.PublicKeys:
|
case keys.PublicKeys:
|
||||||
arr := make([][]byte, 0, len(v))
|
arr := make([][]byte, 0, len(v))
|
||||||
for i := range v {
|
for i := range v {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
sc "github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
sc "github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
|
@ -20,6 +21,12 @@ func TestToStackParameter(t *testing.T) {
|
||||||
{
|
{
|
||||||
value: int64(100),
|
value: int64(100),
|
||||||
expType: sc.IntegerType,
|
expType: sc.IntegerType,
|
||||||
|
expVal: big.NewInt(100),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: uint64(100),
|
||||||
|
expType: sc.IntegerType,
|
||||||
|
expVal: big.NewInt(100),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "hello world",
|
value: "hello world",
|
||||||
|
|
|
@ -31,7 +31,7 @@ func (p *commonEstimationPrm) SetEpoch(epoch uint64) {
|
||||||
func (c *Client) StartEstimation(p StartEstimationPrm) error {
|
func (c *Client) StartEstimation(p StartEstimationPrm) error {
|
||||||
prm := client.InvokePrm{}
|
prm := client.InvokePrm{}
|
||||||
prm.SetMethod(startEstimationMethod)
|
prm.SetMethod(startEstimationMethod)
|
||||||
prm.SetArgs(int64(p.epoch))
|
prm.SetArgs(p.epoch)
|
||||||
prm.InvokePrmOptional = p.InvokePrmOptional
|
prm.InvokePrmOptional = p.InvokePrmOptional
|
||||||
|
|
||||||
if err := c.client.Invoke(prm); err != nil {
|
if err := c.client.Invoke(prm); err != nil {
|
||||||
|
@ -44,7 +44,7 @@ func (c *Client) StartEstimation(p StartEstimationPrm) error {
|
||||||
func (c *Client) StopEstimation(p StopEstimationPrm) error {
|
func (c *Client) StopEstimation(p StopEstimationPrm) error {
|
||||||
prm := client.InvokePrm{}
|
prm := client.InvokePrm{}
|
||||||
prm.SetMethod(stopEstimationMethod)
|
prm.SetMethod(stopEstimationMethod)
|
||||||
prm.SetArgs(int64(p.epoch))
|
prm.SetArgs(p.epoch)
|
||||||
prm.InvokePrmOptional = p.InvokePrmOptional
|
prm.InvokePrmOptional = p.InvokePrmOptional
|
||||||
|
|
||||||
if err := c.client.Invoke(prm); err != nil {
|
if err := c.client.Invoke(prm); err != nil {
|
||||||
|
|
|
@ -39,7 +39,7 @@ func (c *Client) AnnounceLoad(p AnnounceLoadPrm) error {
|
||||||
|
|
||||||
prm := client.InvokePrm{}
|
prm := client.InvokePrm{}
|
||||||
prm.SetMethod(putSizeMethod)
|
prm.SetMethod(putSizeMethod)
|
||||||
prm.SetArgs(int64(p.a.Epoch()), v2.GetValue(), int64(p.a.UsedSpace()), p.key)
|
prm.SetArgs(p.a.Epoch(), v2.GetValue(), p.a.UsedSpace(), p.key)
|
||||||
prm.InvokePrmOptional = p.InvokePrmOptional
|
prm.InvokePrmOptional = p.InvokePrmOptional
|
||||||
|
|
||||||
err := c.client.Invoke(prm)
|
err := c.client.Invoke(prm)
|
||||||
|
@ -57,7 +57,7 @@ type EstimationID []byte
|
||||||
func (c *Client) ListLoadEstimationsByEpoch(epoch uint64) ([]EstimationID, error) {
|
func (c *Client) ListLoadEstimationsByEpoch(epoch uint64) ([]EstimationID, error) {
|
||||||
invokePrm := client.TestInvokePrm{}
|
invokePrm := client.TestInvokePrm{}
|
||||||
invokePrm.SetMethod(listSizesMethod)
|
invokePrm.SetMethod(listSizesMethod)
|
||||||
invokePrm.SetArgs(int64(epoch))
|
invokePrm.SetArgs(epoch)
|
||||||
|
|
||||||
prms, err := c.client.TestInvoke(invokePrm)
|
prms, err := c.client.TestInvoke(invokePrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -34,7 +34,7 @@ const (
|
||||||
func (c *Client) GetNetMapByEpoch(epoch uint64) (*netmap.Netmap, error) {
|
func (c *Client) GetNetMapByEpoch(epoch uint64) (*netmap.Netmap, error) {
|
||||||
invokePrm := client.TestInvokePrm{}
|
invokePrm := client.TestInvokePrm{}
|
||||||
invokePrm.SetMethod(epochSnapshotMethod)
|
invokePrm.SetMethod(epochSnapshotMethod)
|
||||||
invokePrm.SetArgs(int64(epoch))
|
invokePrm.SetArgs(epoch)
|
||||||
|
|
||||||
res, err := c.client.TestInvoke(invokePrm)
|
res, err := c.client.TestInvoke(invokePrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
func (c *Client) NewEpoch(epoch uint64) error {
|
func (c *Client) NewEpoch(epoch uint64) error {
|
||||||
prm := client.InvokePrm{}
|
prm := client.InvokePrm{}
|
||||||
prm.SetMethod(newEpochMethod)
|
prm.SetMethod(newEpochMethod)
|
||||||
prm.SetArgs(int64(epoch))
|
prm.SetArgs(epoch)
|
||||||
|
|
||||||
if err := c.client.Invoke(prm); err != nil {
|
if err := c.client.Invoke(prm); err != nil {
|
||||||
return fmt.Errorf("could not invoke method (%s): %w", newEpochMethod, err)
|
return fmt.Errorf("could not invoke method (%s): %w", newEpochMethod, err)
|
||||||
|
|
|
@ -25,7 +25,7 @@ func (c *Client) Snapshot() (*netmap.Netmap, error) {
|
||||||
func (c *Client) getNetMap(diff uint64) (*netmap.Netmap, error) {
|
func (c *Client) getNetMap(diff uint64) (*netmap.Netmap, error) {
|
||||||
prm := client.TestInvokePrm{}
|
prm := client.TestInvokePrm{}
|
||||||
prm.SetMethod(snapshotMethod)
|
prm.SetMethod(snapshotMethod)
|
||||||
prm.SetArgs(int64(diff))
|
prm.SetArgs(diff)
|
||||||
|
|
||||||
res, err := c.client.TestInvoke(prm)
|
res, err := c.client.TestInvoke(prm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -41,7 +41,7 @@ func (g *GetByIDPrm) SetID(v ID) {
|
||||||
func (c *Client) Get(p GetPrm) ([]reputation.GlobalTrust, error) {
|
func (c *Client) Get(p GetPrm) ([]reputation.GlobalTrust, error) {
|
||||||
invokePrm := client.TestInvokePrm{}
|
invokePrm := client.TestInvokePrm{}
|
||||||
invokePrm.SetMethod(getMethod)
|
invokePrm.SetMethod(getMethod)
|
||||||
invokePrm.SetArgs(int64(p.epoch), p.peerID.ToV2().GetPublicKey())
|
invokePrm.SetArgs(p.epoch, p.peerID.ToV2().GetPublicKey())
|
||||||
|
|
||||||
res, err := c.client.TestInvoke(invokePrm)
|
res, err := c.client.TestInvoke(invokePrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -27,7 +27,7 @@ func (l *ListByEpochArgs) SetEpoch(v uint64) {
|
||||||
func (c *Client) ListByEpoch(p ListByEpochArgs) ([]ID, error) {
|
func (c *Client) ListByEpoch(p ListByEpochArgs) ([]ID, error) {
|
||||||
invokePrm := client.TestInvokePrm{}
|
invokePrm := client.TestInvokePrm{}
|
||||||
invokePrm.SetMethod(listByEpochMethod)
|
invokePrm.SetMethod(listByEpochMethod)
|
||||||
invokePrm.SetArgs(int64(p.epoch))
|
invokePrm.SetArgs(p.epoch)
|
||||||
|
|
||||||
prms, err := c.client.TestInvoke(invokePrm)
|
prms, err := c.client.TestInvoke(invokePrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -42,7 +42,7 @@ func (c *Client) Put(p PutPrm) error {
|
||||||
|
|
||||||
prm := client.InvokePrm{}
|
prm := client.InvokePrm{}
|
||||||
prm.SetMethod(putMethod)
|
prm.SetMethod(putMethod)
|
||||||
prm.SetArgs(int64(p.epoch), p.peerID.ToV2().GetPublicKey(), data)
|
prm.SetArgs(p.epoch, p.peerID.ToV2().GetPublicKey(), data)
|
||||||
|
|
||||||
err = c.client.Invoke(prm)
|
err = c.client.Invoke(prm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue