From 1e8391d216e6b0f699c0138dfb9af342b6efb564 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 11 Mar 2022 12:28:34 +0300 Subject: [PATCH] [#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 --- pkg/innerring/state.go | 2 +- pkg/morph/client/audit/list_results.go | 6 +++--- pkg/morph/client/client.go | 11 +++++++++-- pkg/morph/client/client_test.go | 7 +++++++ pkg/morph/client/container/estimations.go | 4 ++-- pkg/morph/client/container/load.go | 4 ++-- pkg/morph/client/netmap/netmap.go | 2 +- pkg/morph/client/netmap/new_epoch.go | 2 +- pkg/morph/client/netmap/snapshot.go | 2 +- pkg/morph/client/reputation/get.go | 2 +- pkg/morph/client/reputation/list.go | 2 +- pkg/morph/client/reputation/put.go | 2 +- 12 files changed, 30 insertions(+), 16 deletions(-) diff --git a/pkg/innerring/state.go b/pkg/innerring/state.go index 37de3a9a..da65afb8 100644 --- a/pkg/innerring/state.go +++ b/pkg/innerring/state.go @@ -126,7 +126,7 @@ func (s *Server) voteForSidechainValidator(prm governance.VoteValidatorPrm) erro } 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 { s.log.Warn("can't invoke vote method in alphabet contract", zap.Int8("alphabet_index", int8(letter)), diff --git a/pkg/morph/client/audit/list_results.go b/pkg/morph/client/audit/list_results.go index 30b18755..7a15a0cf 100644 --- a/pkg/morph/client/audit/list_results.go +++ b/pkg/morph/client/audit/list_results.go @@ -25,7 +25,7 @@ func (c *Client) ListAllAuditResultID() ([]ResultID, error) { func (c *Client) ListAuditResultIDByEpoch(epoch uint64) ([]ResultID, error) { prm := client.TestInvokePrm{} prm.SetMethod(listByEpochResultsMethod) - prm.SetArgs(int64(epoch)) + prm.SetArgs(epoch) items, err := c.client.TestInvoke(prm) if err != nil { @@ -44,7 +44,7 @@ func (c *Client) ListAuditResultIDByCID(epoch uint64, cid *cid.ID) ([]ResultID, prm := client.TestInvokePrm{} prm.SetMethod(listByCIDResultsMethod) - prm.SetArgs(int64(epoch), v2.GetValue()) + prm.SetArgs(epoch, v2.GetValue()) items, err := c.client.TestInvoke(prm) if err != nil { @@ -63,7 +63,7 @@ func (c *Client) ListAuditResultIDByNode(epoch uint64, cid *cid.ID, nodeKey []by prm := client.TestInvokePrm{} prm.SetMethod(listByNodeResultsMethod) - prm.SetArgs(int64(epoch), v2.GetValue(), nodeKey) + prm.SetArgs(epoch, v2.GetValue(), nodeKey) items, err := c.client.TestInvoke(prm) if err != nil { diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index dc4829f4..847e7ebe 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "math/big" "sync" "time" @@ -445,12 +446,18 @@ func toStackParameter(value interface{}) (sc.Parameter, error) { Value: value, } - // TODO: #1141 add more types switch v := value.(type) { case []byte: result.Type = sc.ByteArrayType + case int: + result.Type = sc.IntegerType + result.Value = big.NewInt(int64(v)) case int64: result.Type = sc.IntegerType + result.Value = big.NewInt(v) + case uint64: + result.Type = sc.IntegerType + result.Value = new(big.Int).SetUint64(v) case [][]byte: arr := make([]sc.Parameter, 0, len(v)) for i := range v { @@ -471,7 +478,7 @@ func toStackParameter(value interface{}) (sc.Parameter, error) { result.Value = v.BytesBE() case noderoles.Role: result.Type = sc.IntegerType - result.Value = int64(v) + result.Value = big.NewInt(int64(v)) case keys.PublicKeys: arr := make([][]byte, 0, len(v)) for i := range v { diff --git a/pkg/morph/client/client_test.go b/pkg/morph/client/client_test.go index 321811a8..ab26f9c7 100644 --- a/pkg/morph/client/client_test.go +++ b/pkg/morph/client/client_test.go @@ -1,6 +1,7 @@ package client import ( + "math/big" "testing" sc "github.com/nspcc-dev/neo-go/pkg/smartcontract" @@ -20,6 +21,12 @@ func TestToStackParameter(t *testing.T) { { value: int64(100), expType: sc.IntegerType, + expVal: big.NewInt(100), + }, + { + value: uint64(100), + expType: sc.IntegerType, + expVal: big.NewInt(100), }, { value: "hello world", diff --git a/pkg/morph/client/container/estimations.go b/pkg/morph/client/container/estimations.go index 87c8a25e..51e4b5b2 100644 --- a/pkg/morph/client/container/estimations.go +++ b/pkg/morph/client/container/estimations.go @@ -31,7 +31,7 @@ func (p *commonEstimationPrm) SetEpoch(epoch uint64) { func (c *Client) StartEstimation(p StartEstimationPrm) error { prm := client.InvokePrm{} prm.SetMethod(startEstimationMethod) - prm.SetArgs(int64(p.epoch)) + prm.SetArgs(p.epoch) prm.InvokePrmOptional = p.InvokePrmOptional 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 { prm := client.InvokePrm{} prm.SetMethod(stopEstimationMethod) - prm.SetArgs(int64(p.epoch)) + prm.SetArgs(p.epoch) prm.InvokePrmOptional = p.InvokePrmOptional if err := c.client.Invoke(prm); err != nil { diff --git a/pkg/morph/client/container/load.go b/pkg/morph/client/container/load.go index 4184650a..202125ad 100644 --- a/pkg/morph/client/container/load.go +++ b/pkg/morph/client/container/load.go @@ -39,7 +39,7 @@ func (c *Client) AnnounceLoad(p AnnounceLoadPrm) error { prm := client.InvokePrm{} 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 err := c.client.Invoke(prm) @@ -57,7 +57,7 @@ type EstimationID []byte func (c *Client) ListLoadEstimationsByEpoch(epoch uint64) ([]EstimationID, error) { invokePrm := client.TestInvokePrm{} invokePrm.SetMethod(listSizesMethod) - invokePrm.SetArgs(int64(epoch)) + invokePrm.SetArgs(epoch) prms, err := c.client.TestInvoke(invokePrm) if err != nil { diff --git a/pkg/morph/client/netmap/netmap.go b/pkg/morph/client/netmap/netmap.go index 2b67fd50..0af7e22c 100644 --- a/pkg/morph/client/netmap/netmap.go +++ b/pkg/morph/client/netmap/netmap.go @@ -34,7 +34,7 @@ const ( func (c *Client) GetNetMapByEpoch(epoch uint64) (*netmap.Netmap, error) { invokePrm := client.TestInvokePrm{} invokePrm.SetMethod(epochSnapshotMethod) - invokePrm.SetArgs(int64(epoch)) + invokePrm.SetArgs(epoch) res, err := c.client.TestInvoke(invokePrm) if err != nil { diff --git a/pkg/morph/client/netmap/new_epoch.go b/pkg/morph/client/netmap/new_epoch.go index 7a8a672f..3f3fcd50 100644 --- a/pkg/morph/client/netmap/new_epoch.go +++ b/pkg/morph/client/netmap/new_epoch.go @@ -11,7 +11,7 @@ import ( func (c *Client) NewEpoch(epoch uint64) error { prm := client.InvokePrm{} prm.SetMethod(newEpochMethod) - prm.SetArgs(int64(epoch)) + prm.SetArgs(epoch) if err := c.client.Invoke(prm); err != nil { return fmt.Errorf("could not invoke method (%s): %w", newEpochMethod, err) diff --git a/pkg/morph/client/netmap/snapshot.go b/pkg/morph/client/netmap/snapshot.go index 9cecf281..0f6df286 100644 --- a/pkg/morph/client/netmap/snapshot.go +++ b/pkg/morph/client/netmap/snapshot.go @@ -25,7 +25,7 @@ func (c *Client) Snapshot() (*netmap.Netmap, error) { func (c *Client) getNetMap(diff uint64) (*netmap.Netmap, error) { prm := client.TestInvokePrm{} prm.SetMethod(snapshotMethod) - prm.SetArgs(int64(diff)) + prm.SetArgs(diff) res, err := c.client.TestInvoke(prm) if err != nil { diff --git a/pkg/morph/client/reputation/get.go b/pkg/morph/client/reputation/get.go index c004dec1..e04c8e5c 100644 --- a/pkg/morph/client/reputation/get.go +++ b/pkg/morph/client/reputation/get.go @@ -41,7 +41,7 @@ func (g *GetByIDPrm) SetID(v ID) { func (c *Client) Get(p GetPrm) ([]reputation.GlobalTrust, error) { invokePrm := client.TestInvokePrm{} 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) if err != nil { diff --git a/pkg/morph/client/reputation/list.go b/pkg/morph/client/reputation/list.go index 164faecf..6ccb9926 100644 --- a/pkg/morph/client/reputation/list.go +++ b/pkg/morph/client/reputation/list.go @@ -27,7 +27,7 @@ func (l *ListByEpochArgs) SetEpoch(v uint64) { func (c *Client) ListByEpoch(p ListByEpochArgs) ([]ID, error) { invokePrm := client.TestInvokePrm{} invokePrm.SetMethod(listByEpochMethod) - invokePrm.SetArgs(int64(p.epoch)) + invokePrm.SetArgs(p.epoch) prms, err := c.client.TestInvoke(invokePrm) if err != nil { diff --git a/pkg/morph/client/reputation/put.go b/pkg/morph/client/reputation/put.go index 718cc892..233110f5 100644 --- a/pkg/morph/client/reputation/put.go +++ b/pkg/morph/client/reputation/put.go @@ -42,7 +42,7 @@ func (c *Client) Put(p PutPrm) error { prm := client.InvokePrm{} 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) if err != nil {