rpcclient: add deprecation warnings
This commit is contained in:
parent
d9feec2be5
commit
afef8b85d9
7 changed files with 34 additions and 21 deletions
|
@ -295,7 +295,7 @@ func signAndSendNEP11Transfer(ctx *cli.Context, c *rpcclient.Client, acc *wallet
|
||||||
return cli.NewExitError(err, 1)
|
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 {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -667,7 +667,7 @@ func signAndSendNEP17Transfer(ctx *cli.Context, c *rpcclient.Client, acc *wallet
|
||||||
return cli.NewExitError(err, 1)
|
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 {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ func handleCandidate(ctx *cli.Context, method string, sysGas int64) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
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{
|
Signer: transaction.Signer{
|
||||||
Account: acc.Contract.ScriptHash(),
|
Account: acc.Contract.ScriptHash(),
|
||||||
Scopes: transaction.CalledByEntry,
|
Scopes: transaction.CalledByEntry,
|
||||||
|
@ -184,7 +184,7 @@ func handleVote(ctx *cli.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
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{
|
Signer: transaction.Signer{
|
||||||
Account: acc.Contract.ScriptHash(),
|
Account: acc.Contract.ScriptHash(),
|
||||||
Scopes: transaction.CalledByEntry,
|
Scopes: transaction.CalledByEntry,
|
||||||
|
|
|
@ -97,6 +97,9 @@ func (c *Client) CreateNEP17MultiTransferTx(acc *wallet.Account, gas int64,
|
||||||
// CreateTxFromScript creates transaction and properly sets cosigners and NetworkFee.
|
// CreateTxFromScript creates transaction and properly sets cosigners and NetworkFee.
|
||||||
// If sysFee <= 0, it is determined via result of `invokescript` RPC. You should
|
// If sysFee <= 0, it is determined via result of `invokescript` RPC. You should
|
||||||
// initialize network magic with Init before calling CreateTxFromScript.
|
// 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,
|
func (c *Client) CreateTxFromScript(script []byte, acc *wallet.Account, sysFee, netFee int64,
|
||||||
cosigners []SignerAccount) (*transaction.Transaction, error) {
|
cosigners []SignerAccount) (*transaction.Transaction, error) {
|
||||||
signers, accounts, err := getSigners(acc, cosigners)
|
signers, accounts, err := getSigners(acc, cosigners)
|
||||||
|
|
|
@ -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
|
// 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
|
// invocation transaction and an error. If one of the cosigners accounts is
|
||||||
// neither contract-based nor unlocked, an error is returned.
|
// 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) {
|
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)
|
tx, err := c.CreateTxFromScript(script, acc, sysfee, int64(netfee), cosigners)
|
||||||
if err != nil {
|
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
|
// 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
|
// the cosigners accounts is neither contract-based nor unlocked, an error is
|
||||||
// returned.
|
// 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) {
|
func (c *Client) SignAndPushTx(tx *transaction.Transaction, acc *wallet.Account, cosigners []SignerAccount) (util.Uint256, error) {
|
||||||
var (
|
var (
|
||||||
txHash util.Uint256
|
txHash util.Uint256
|
||||||
|
@ -1042,6 +1048,9 @@ func (c *Client) CalculateValidUntilBlock() (uint32, error) {
|
||||||
|
|
||||||
// AddNetworkFee adds network fee for each witness script and optional extra
|
// AddNetworkFee adds network fee for each witness script and optional extra
|
||||||
// network fee to transaction. `accs` is an array signer's accounts.
|
// 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 {
|
func (c *Client) AddNetworkFee(tx *transaction.Transaction, extraFee int64, accs ...*wallet.Account) error {
|
||||||
if len(tx.Signers) != len(accs) {
|
if len(tx.Signers) != len(accs) {
|
||||||
return errors.New("number of signers must match number of scripts")
|
return errors.New("number of signers must match number of scripts")
|
||||||
|
|
|
@ -116,7 +116,7 @@ func TestAddNetworkFeeCalculateNetworkFee(t *testing.T) {
|
||||||
Account: accs[0].PrivateKey().GetScriptHash(),
|
Account: accs[0].PrivateKey().GetScriptHash(),
|
||||||
Scopes: transaction.CalledByEntry,
|
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) {
|
t.Run("Simple", func(t *testing.T) {
|
||||||
acc0 := wallet.NewAccountFromPrivateKey(testchain.PrivateKeyByID(0))
|
acc0 := wallet.NewAccountFromPrivateKey(testchain.PrivateKeyByID(0))
|
||||||
|
@ -137,7 +137,7 @@ func TestAddNetworkFeeCalculateNetworkFee(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
tx.Scripts = nil
|
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
|
actual := tx.NetworkFee
|
||||||
|
|
||||||
require.NoError(t, acc0.SignTx(testchain.Network(), tx))
|
require.NoError(t, acc0.SignTx(testchain.Network(), tx))
|
||||||
|
@ -203,7 +203,7 @@ func TestAddNetworkFeeCalculateNetworkFee(t *testing.T) {
|
||||||
|
|
||||||
tx.Scripts = nil
|
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
|
actual := tx.NetworkFee
|
||||||
|
|
||||||
require.NoError(t, acc0.SignTx(testchain.Network(), tx))
|
require.NoError(t, acc0.SignTx(testchain.Network(), tx))
|
||||||
|
@ -276,7 +276,7 @@ func TestAddNetworkFeeCalculateNetworkFee(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tx.Scripts = nil
|
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))
|
require.NoError(t, acc0.SignTx(testchain.Network(), tx))
|
||||||
tx.Scripts = append(tx.Scripts, transaction.Witness{})
|
tx.Scripts = append(tx.Scripts, transaction.Witness{})
|
||||||
require.Equal(t, tx.NetworkFee, actual+extraFee)
|
require.Equal(t, tx.NetworkFee, actual+extraFee)
|
||||||
|
@ -315,7 +315,7 @@ func TestAddNetworkFeeCalculateNetworkFee(t *testing.T) {
|
||||||
Scopes: transaction.Global,
|
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) {
|
t.Run("InvalidContract", func(t *testing.T) {
|
||||||
tx := newTx(t)
|
tx := newTx(t)
|
||||||
|
@ -330,7 +330,7 @@ func TestAddNetworkFeeCalculateNetworkFee(t *testing.T) {
|
||||||
Scopes: transaction.Global,
|
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("good", func(t *testing.T) {
|
||||||
t.Run("signer0: sig", 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{
|
Signer: transaction.Signer{
|
||||||
Account: priv0.GetScriptHash(),
|
Account: priv0.GetScriptHash(),
|
||||||
|
@ -471,7 +471,7 @@ func TestSignAndPushInvocationTx(t *testing.T) {
|
||||||
check(t, h)
|
check(t, h)
|
||||||
})
|
})
|
||||||
t.Run("signer0: sig; signer1: sig", func(t *testing.T) {
|
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{
|
Signer: transaction.Signer{
|
||||||
Account: priv0.GetScriptHash(),
|
Account: priv0.GetScriptHash(),
|
||||||
|
@ -491,7 +491,7 @@ func TestSignAndPushInvocationTx(t *testing.T) {
|
||||||
check(t, h)
|
check(t, h)
|
||||||
})
|
})
|
||||||
t.Run("signer0: sig; signer1: contract-based paramless", func(t *testing.T) {
|
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{
|
Signer: transaction.Signer{
|
||||||
Account: priv0.GetScriptHash(),
|
Account: priv0.GetScriptHash(),
|
||||||
|
@ -513,7 +513,7 @@ func TestSignAndPushInvocationTx(t *testing.T) {
|
||||||
})
|
})
|
||||||
t.Run("error", func(t *testing.T) {
|
t.Run("error", func(t *testing.T) {
|
||||||
t.Run("signer0: sig; signer1: contract-based with params", 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{
|
Signer: transaction.Signer{
|
||||||
Account: priv0.GetScriptHash(),
|
Account: priv0.GetScriptHash(),
|
||||||
|
@ -541,7 +541,7 @@ func TestSignAndPushInvocationTx(t *testing.T) {
|
||||||
Parameters: []wallet.ContractParam{{Name: "parameter0", Type: smartcontract.SignatureType}},
|
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{
|
Signer: transaction.Signer{
|
||||||
Account: priv0.GetScriptHash(),
|
Account: priv0.GetScriptHash(),
|
||||||
|
@ -693,7 +693,7 @@ func TestCreateTxFromScript(t *testing.T) {
|
||||||
priv := testchain.PrivateKey(0)
|
priv := testchain.PrivateKey(0)
|
||||||
acc := wallet.NewAccountFromPrivateKey(priv)
|
acc := wallet.NewAccountFromPrivateKey(priv)
|
||||||
t.Run("NoSystemFee", func(t *testing.T) {
|
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.NoError(t, err)
|
||||||
require.True(t, tx.ValidUntilBlock > chain.BlockHeight())
|
require.True(t, tx.ValidUntilBlock > chain.BlockHeight())
|
||||||
require.EqualValues(t, 30, tx.SystemFee) // PUSH1
|
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)
|
require.Equal(t, acc.PrivateKey().GetScriptHash(), tx.Signers[0].Account)
|
||||||
})
|
})
|
||||||
t.Run("ProvideSystemFee", func(t *testing.T) {
|
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.NoError(t, err)
|
||||||
require.True(t, tx.ValidUntilBlock > chain.BlockHeight())
|
require.True(t, tx.ValidUntilBlock > chain.BlockHeight())
|
||||||
require.EqualValues(t, 123, tx.SystemFee)
|
require.EqualValues(t, 123, tx.SystemFee)
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"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"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
|
@ -34,8 +34,8 @@ func ExampleBuilder() {
|
||||||
|
|
||||||
w, _ := wallet.NewWalletFromFile("somewhere")
|
w, _ := wallet.NewWalletFromFile("somewhere")
|
||||||
// Assuming there is one Account inside
|
// Assuming there is one Account inside
|
||||||
acc := w.Accounts[0]
|
a, _ := actor.NewSimple(c, w.Accounts[0])
|
||||||
from, _ := address.StringToUint160(acc.Address)
|
from := w.Accounts[0].Contract.ScriptHash() // Assuming Contract is present.
|
||||||
|
|
||||||
// Multiple transfers in a single script. If any of them fail whole script fails.
|
// Multiple transfers in a single script. If any of them fail whole script fails.
|
||||||
b.InvokeWithAssert(neoHash, "transfer", from, util.Uint160{0x70}, 1, nil)
|
b.InvokeWithAssert(neoHash, "transfer", from, util.Uint160{0x70}, 1, nil)
|
||||||
|
@ -44,6 +44,7 @@ func ExampleBuilder() {
|
||||||
script, _ = b.Script()
|
script, _ = b.Script()
|
||||||
|
|
||||||
// The script can then be used to create transaction or to invoke via RPC.
|
// 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
|
_ = txid
|
||||||
|
_ = vub
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue