From b1b9a8cf668eaf1c31424ace1f2433b365f034ab Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 2 Mar 2021 13:58:53 +0300 Subject: [PATCH] rpc: refactor CreateTxFromScript signature Make cosigners non-variadic. --- cli/smartcontract/smart_contract.go | 2 +- cli/wallet/validator.go | 8 ++++---- pkg/rpc/client/nep17.go | 6 +++--- pkg/rpc/client/rpc.go | 2 +- pkg/rpc/server/client_test.go | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index 908c7f676..0feecfcce 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -579,7 +579,7 @@ func invokeInternal(ctx *cli.Context, signAndPush bool) error { fmt.Fprintln(ctx.App.Writer, errText+". Sending transaction...") } if out := ctx.String("out"); out != "" { - tx, err := c.CreateTxFromScript(resp.Script, acc, resp.GasConsumed, int64(gas), cosigners...) + tx, err := c.CreateTxFromScript(resp.Script, acc, resp.GasConsumed, int64(gas), cosigners) if err != nil { return cli.NewExitError(fmt.Errorf("failed to create tx: %w", err), 1) } diff --git a/cli/wallet/validator.go b/cli/wallet/validator.go index d2c7e2b7d..7da15f0e7 100644 --- a/cli/wallet/validator.go +++ b/cli/wallet/validator.go @@ -108,10 +108,10 @@ func handleCandidate(ctx *cli.Context, method string, sysGas int64) error { w := io.NewBufBinWriter() emit.AppCall(w.BinWriter, neoContractHash, method, callflag.States, acc.PrivateKey().PublicKey().Bytes()) emit.Opcodes(w.BinWriter, opcode.ASSERT) - tx, err := c.CreateTxFromScript(w.Bytes(), acc, sysGas, int64(gas), transaction.Signer{ + tx, err := c.CreateTxFromScript(w.Bytes(), acc, sysGas, int64(gas), []transaction.Signer{{ Account: acc.Contract.ScriptHash(), Scopes: transaction.CalledByEntry, - }) + }}) if err != nil { return cli.NewExitError(err, 1) } else if err = acc.SignTx(tx); err != nil { @@ -171,10 +171,10 @@ func handleVote(ctx *cli.Context) error { emit.AppCall(w.BinWriter, neoContractHash, "vote", callflag.States, addr.BytesBE(), pubArg) emit.Opcodes(w.BinWriter, opcode.ASSERT) - tx, err := c.CreateTxFromScript(w.Bytes(), acc, -1, int64(gas), transaction.Signer{ + tx, err := c.CreateTxFromScript(w.Bytes(), acc, -1, int64(gas), []transaction.Signer{{ Account: acc.Contract.ScriptHash(), Scopes: transaction.CalledByEntry, - }) + }}) if err != nil { return cli.NewExitError(err, 1) } diff --git a/pkg/rpc/client/nep17.go b/pkg/rpc/client/nep17.go index 80567808a..2d9f031a8 100644 --- a/pkg/rpc/client/nep17.go +++ b/pkg/rpc/client/nep17.go @@ -140,17 +140,17 @@ func (c *Client) CreateNEP17MultiTransferTx(acc *wallet.Account, gas int64, reci if err != nil { return nil, fmt.Errorf("bad account address: %v", err) } - return c.CreateTxFromScript(w.Bytes(), acc, -1, gas, transaction.Signer{ + return c.CreateTxFromScript(w.Bytes(), acc, -1, gas, []transaction.Signer{{ Account: accAddr, Scopes: transaction.CalledByEntry, - }) + }}) } // CreateTxFromScript creates transaction and properly sets cosigners and NetworkFee. // If sysFee <= 0, it is determined via result of `invokescript` RPC. You should // initialize network magic with Init before calling CreateTxFromScript. func (c *Client) CreateTxFromScript(script []byte, acc *wallet.Account, sysFee, netFee int64, - cosigners ...transaction.Signer) (*transaction.Transaction, error) { + cosigners []transaction.Signer) (*transaction.Transaction, error) { from, err := address.StringToUint160(acc.Address) if err != nil { return nil, fmt.Errorf("bad account address: %v", err) diff --git a/pkg/rpc/client/rpc.go b/pkg/rpc/client/rpc.go index c699832b0..66aaa0c79 100644 --- a/pkg/rpc/client/rpc.go +++ b/pkg/rpc/client/rpc.go @@ -526,7 +526,7 @@ func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sys var txHash util.Uint256 var err error - tx, err := c.CreateTxFromScript(script, acc, sysfee, int64(netfee), cosigners...) + tx, err := c.CreateTxFromScript(script, acc, sysfee, int64(netfee), cosigners) if err != nil { return txHash, fmt.Errorf("failed to create tx: %w", err) } diff --git a/pkg/rpc/server/client_test.go b/pkg/rpc/server/client_test.go index acca59101..f36da87dd 100644 --- a/pkg/rpc/server/client_test.go +++ b/pkg/rpc/server/client_test.go @@ -347,7 +347,7 @@ func TestCreateTxFromScript(t *testing.T) { priv := testchain.PrivateKey(0) acc := wallet.NewAccountFromPrivateKey(priv) t.Run("NoSystemFee", func(t *testing.T) { - tx, err := c.CreateTxFromScript([]byte{byte(opcode.PUSH1)}, acc, -1, 10) + tx, err := c.CreateTxFromScript([]byte{byte(opcode.PUSH1)}, acc, -1, 10, nil) require.NoError(t, err) require.True(t, tx.ValidUntilBlock > chain.BlockHeight()) require.EqualValues(t, 30, tx.SystemFee) // PUSH1 @@ -355,7 +355,7 @@ func TestCreateTxFromScript(t *testing.T) { require.Equal(t, acc.PrivateKey().GetScriptHash(), tx.Signers[0].Account) }) t.Run("ProvideSystemFee", func(t *testing.T) { - tx, err := c.CreateTxFromScript([]byte{byte(opcode.PUSH1)}, acc, 123, 10) + tx, err := c.CreateTxFromScript([]byte{byte(opcode.PUSH1)}, acc, 123, 10, nil) require.NoError(t, err) require.True(t, tx.ValidUntilBlock > chain.BlockHeight()) require.EqualValues(t, 123, tx.SystemFee)