diff --git a/cli/wallet/nep11.go b/cli/wallet/nep11.go index e910966b8..e1b18e8ca 100644 --- a/cli/wallet/nep11.go +++ b/cli/wallet/nep11.go @@ -295,7 +295,7 @@ func signAndSendNEP11Transfer(ctx *cli.Context, c *rpcclient.Client, acc *wallet return cli.NewExitError(err, 1) } } - _, err := c.SignAndPushTx(tx, acc, cosigners) + _, err := c.SignAndPushTx(tx, acc, cosigners) //nolint:staticcheck // SA1019: c.SignAndPushTx is deprecated if err != nil { return cli.NewExitError(err, 1) } diff --git a/cli/wallet/nep17.go b/cli/wallet/nep17.go index 1591f980f..d00066ebf 100644 --- a/cli/wallet/nep17.go +++ b/cli/wallet/nep17.go @@ -667,7 +667,7 @@ func signAndSendNEP17Transfer(ctx *cli.Context, c *rpcclient.Client, acc *wallet return cli.NewExitError(err, 1) } } - _, err := c.SignAndPushTx(tx, acc, cosigners) + _, err := c.SignAndPushTx(tx, acc, cosigners) //nolint:staticcheck // SA1019: c.SignAndPushTx is deprecated if err != nil { return cli.NewExitError(err, 1) } diff --git a/cli/wallet/validator.go b/cli/wallet/validator.go index 9426bd14c..a063edb74 100644 --- a/cli/wallet/validator.go +++ b/cli/wallet/validator.go @@ -123,7 +123,7 @@ func handleCandidate(ctx *cli.Context, method string, sysGas int64) error { if err != nil { return cli.NewExitError(err, 1) } - res, err := c.SignAndPushInvocationTx(script, acc, sysGas, gas, []rpcclient.SignerAccount{{ + res, err := c.SignAndPushInvocationTx(script, acc, sysGas, gas, []rpcclient.SignerAccount{{ //nolint:staticcheck // SA1019: c.SignAndPushInvocationTx is deprecated Signer: transaction.Signer{ Account: acc.Contract.ScriptHash(), Scopes: transaction.CalledByEntry, @@ -184,7 +184,7 @@ func handleVote(ctx *cli.Context) error { if err != nil { return cli.NewExitError(err, 1) } - res, err := c.SignAndPushInvocationTx(script, acc, -1, gas, []rpcclient.SignerAccount{{ + res, err := c.SignAndPushInvocationTx(script, acc, -1, gas, []rpcclient.SignerAccount{{ //nolint:staticcheck // SA1019: c.SignAndPushInvocationTx is deprecated Signer: transaction.Signer{ Account: acc.Contract.ScriptHash(), Scopes: transaction.CalledByEntry, diff --git a/pkg/rpcclient/nep17.go b/pkg/rpcclient/nep17.go index 06d0a4209..329f88fca 100644 --- a/pkg/rpcclient/nep17.go +++ b/pkg/rpcclient/nep17.go @@ -97,6 +97,9 @@ func (c *Client) CreateNEP17MultiTransferTx(acc *wallet.Account, gas int64, // 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. +// +// Deprecated: please use actor.Actor API, this method will be removed in future +// versions. func (c *Client) CreateTxFromScript(script []byte, acc *wallet.Account, sysFee, netFee int64, cosigners []SignerAccount) (*transaction.Transaction, error) { signers, accounts, err := getSigners(acc, cosigners) diff --git a/pkg/rpcclient/rpc.go b/pkg/rpcclient/rpc.go index b278997ba..60ef93835 100644 --- a/pkg/rpcclient/rpc.go +++ b/pkg/rpcclient/rpc.go @@ -755,6 +755,9 @@ func (c *Client) SubmitRawOracleResponse(ps []interface{}) error { // possible. It spends the amount of gas specified. It returns a hash of the // invocation transaction and an error. If one of the cosigners accounts is // neither contract-based nor unlocked, an error is returned. +// +// Deprecated: please use actor.Actor API, this method will be removed in future +// versions. func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sysfee int64, netfee fixedn.Fixed8, cosigners []SignerAccount) (util.Uint256, error) { tx, err := c.CreateTxFromScript(script, acc, sysfee, int64(netfee), cosigners) if err != nil { @@ -767,6 +770,9 @@ func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sys // it to the chain. It returns a hash of the transaction and an error. If one of // the cosigners accounts is neither contract-based nor unlocked, an error is // returned. +// +// Deprecated: please use actor.Actor API, this method will be removed in future +// versions. func (c *Client) SignAndPushTx(tx *transaction.Transaction, acc *wallet.Account, cosigners []SignerAccount) (util.Uint256, error) { var ( txHash util.Uint256 @@ -1042,6 +1048,9 @@ func (c *Client) CalculateValidUntilBlock() (uint32, error) { // AddNetworkFee adds network fee for each witness script and optional extra // network fee to transaction. `accs` is an array signer's accounts. +// +// Deprecated: please use CalculateNetworkFee or actor.Actor. This method will +// be removed in future versions. func (c *Client) AddNetworkFee(tx *transaction.Transaction, extraFee int64, accs ...*wallet.Account) error { if len(tx.Signers) != len(accs) { return errors.New("number of signers must match number of scripts") diff --git a/pkg/services/rpcsrv/client_test.go b/pkg/services/rpcsrv/client_test.go index a53ce077f..354bf38d8 100644 --- a/pkg/services/rpcsrv/client_test.go +++ b/pkg/services/rpcsrv/client_test.go @@ -116,7 +116,7 @@ func TestAddNetworkFeeCalculateNetworkFee(t *testing.T) { Account: accs[0].PrivateKey().GetScriptHash(), Scopes: transaction.CalledByEntry, }} - require.Error(t, c.AddNetworkFee(tx, extraFee, accs[0], accs[1])) + require.Error(t, c.AddNetworkFee(tx, extraFee, accs[0], accs[1])) //nolint:staticcheck // SA1019: c.AddNetworkFee is deprecated }) t.Run("Simple", func(t *testing.T) { acc0 := wallet.NewAccountFromPrivateKey(testchain.PrivateKeyByID(0)) @@ -137,7 +137,7 @@ func TestAddNetworkFeeCalculateNetworkFee(t *testing.T) { require.NoError(t, err) tx.Scripts = nil - require.NoError(t, c.AddNetworkFee(tx, extraFee, acc0)) + require.NoError(t, c.AddNetworkFee(tx, extraFee, acc0)) //nolint:staticcheck // SA1019: c.AddNetworkFee is deprecated actual := tx.NetworkFee require.NoError(t, acc0.SignTx(testchain.Network(), tx)) @@ -203,7 +203,7 @@ func TestAddNetworkFeeCalculateNetworkFee(t *testing.T) { tx.Scripts = nil - require.NoError(t, c.AddNetworkFee(tx, extraFee, acc0, acc1)) + require.NoError(t, c.AddNetworkFee(tx, extraFee, acc0, acc1)) //nolint:staticcheck // SA1019: c.AddNetworkFee is deprecated actual := tx.NetworkFee require.NoError(t, acc0.SignTx(testchain.Network(), tx)) @@ -276,7 +276,7 @@ func TestAddNetworkFeeCalculateNetworkFee(t *testing.T) { require.NoError(t, err) tx.Scripts = nil - require.NoError(t, c.AddNetworkFee(tx, extraFee, acc0, acc1)) + require.NoError(t, c.AddNetworkFee(tx, extraFee, acc0, acc1)) //nolint:staticcheck // SA1019: c.AddNetworkFee is deprecated require.NoError(t, acc0.SignTx(testchain.Network(), tx)) tx.Scripts = append(tx.Scripts, transaction.Witness{}) require.Equal(t, tx.NetworkFee, actual+extraFee) @@ -315,7 +315,7 @@ func TestAddNetworkFeeCalculateNetworkFee(t *testing.T) { Scopes: transaction.Global, }, } - require.Error(t, c.AddNetworkFee(tx, 10, acc0, acc1)) + require.Error(t, c.AddNetworkFee(tx, 10, acc0, acc1)) //nolint:staticcheck // SA1019: c.AddNetworkFee is deprecated }) t.Run("InvalidContract", func(t *testing.T) { tx := newTx(t) @@ -330,7 +330,7 @@ func TestAddNetworkFeeCalculateNetworkFee(t *testing.T) { Scopes: transaction.Global, }, } - require.Error(t, c.AddNetworkFee(tx, 10, acc0, acc1)) + require.Error(t, c.AddNetworkFee(tx, 10, acc0, acc1)) //nolint:staticcheck // SA1019: c.AddNetworkFee is deprecated }) }) } @@ -458,7 +458,7 @@ func TestSignAndPushInvocationTx(t *testing.T) { t.Run("good", func(t *testing.T) { t.Run("signer0: sig", func(t *testing.T) { - h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{ + h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{ //nolint:staticcheck // SA1019: c.SignAndPushInvocationTx is deprecated { Signer: transaction.Signer{ Account: priv0.GetScriptHash(), @@ -471,7 +471,7 @@ func TestSignAndPushInvocationTx(t *testing.T) { check(t, h) }) t.Run("signer0: sig; signer1: sig", func(t *testing.T) { - h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{ + h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{ //nolint:staticcheck // SA1019: c.SignAndPushInvocationTx is deprecated { Signer: transaction.Signer{ Account: priv0.GetScriptHash(), @@ -491,7 +491,7 @@ func TestSignAndPushInvocationTx(t *testing.T) { check(t, h) }) t.Run("signer0: sig; signer1: contract-based paramless", func(t *testing.T) { - h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{ + h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{ //nolint:staticcheck // SA1019: c.SignAndPushInvocationTx is deprecated { Signer: transaction.Signer{ Account: priv0.GetScriptHash(), @@ -513,7 +513,7 @@ func TestSignAndPushInvocationTx(t *testing.T) { }) t.Run("error", func(t *testing.T) { t.Run("signer0: sig; signer1: contract-based with params", func(t *testing.T) { - _, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{ + _, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{ //nolint:staticcheck // SA1019: c.SignAndPushInvocationTx is deprecated { Signer: transaction.Signer{ Account: priv0.GetScriptHash(), @@ -541,7 +541,7 @@ func TestSignAndPushInvocationTx(t *testing.T) { Parameters: []wallet.ContractParam{{Name: "parameter0", Type: smartcontract.SignatureType}}, }, } - _, err = c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{ + _, err = c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{ //nolint:staticcheck // SA1019: c.SignAndPushInvocationTx is deprecated { Signer: transaction.Signer{ Account: priv0.GetScriptHash(), @@ -693,7 +693,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, nil) + tx, err := c.CreateTxFromScript([]byte{byte(opcode.PUSH1)}, acc, -1, 10, nil) //nolint:staticcheck // SA1019: c.CreateTxFromScript is deprecated require.NoError(t, err) require.True(t, tx.ValidUntilBlock > chain.BlockHeight()) require.EqualValues(t, 30, tx.SystemFee) // PUSH1 @@ -701,7 +701,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, nil) + tx, err := c.CreateTxFromScript([]byte{byte(opcode.PUSH1)}, acc, 123, 10, nil) //nolint:staticcheck // SA1019: c.CreateTxFromScript is deprecated require.NoError(t, err) require.True(t, tx.ValidUntilBlock > chain.BlockHeight()) require.EqualValues(t, 123, tx.SystemFee) diff --git a/pkg/smartcontract/doc_test.go b/pkg/smartcontract/doc_test.go index d1b7fe8cc..4dfdda4ca 100644 --- a/pkg/smartcontract/doc_test.go +++ b/pkg/smartcontract/doc_test.go @@ -5,8 +5,8 @@ import ( "encoding/hex" "github.com/nspcc-dev/neo-go/pkg/core/transaction" - "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/rpcclient" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/actor" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/wallet" @@ -34,8 +34,8 @@ func ExampleBuilder() { w, _ := wallet.NewWalletFromFile("somewhere") // Assuming there is one Account inside - acc := w.Accounts[0] - from, _ := address.StringToUint160(acc.Address) + a, _ := actor.NewSimple(c, w.Accounts[0]) + from := w.Accounts[0].Contract.ScriptHash() // Assuming Contract is present. // Multiple transfers in a single script. If any of them fail whole script fails. b.InvokeWithAssert(neoHash, "transfer", from, util.Uint160{0x70}, 1, nil) @@ -44,6 +44,7 @@ func ExampleBuilder() { script, _ = b.Script() // The script can then be used to create transaction or to invoke via RPC. - txid, _ := c.SignAndPushInvocationTx(script, acc, -1, 0, nil) + txid, vub, _ := a.SendRun(script) _ = txid + _ = vub }