forked from TrueCloudLab/neoneo-go
rpc: refactor CreateTxFromScript signature
Make cosigners non-variadic.
This commit is contained in:
parent
4a9ca253d3
commit
b1b9a8cf66
5 changed files with 11 additions and 11 deletions
|
@ -579,7 +579,7 @@ func invokeInternal(ctx *cli.Context, signAndPush bool) error {
|
||||||
fmt.Fprintln(ctx.App.Writer, errText+". Sending transaction...")
|
fmt.Fprintln(ctx.App.Writer, errText+". Sending transaction...")
|
||||||
}
|
}
|
||||||
if out := ctx.String("out"); out != "" {
|
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 {
|
if err != nil {
|
||||||
return cli.NewExitError(fmt.Errorf("failed to create tx: %w", err), 1)
|
return cli.NewExitError(fmt.Errorf("failed to create tx: %w", err), 1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,10 +108,10 @@ func handleCandidate(ctx *cli.Context, method string, sysGas int64) error {
|
||||||
w := io.NewBufBinWriter()
|
w := io.NewBufBinWriter()
|
||||||
emit.AppCall(w.BinWriter, neoContractHash, method, callflag.States, acc.PrivateKey().PublicKey().Bytes())
|
emit.AppCall(w.BinWriter, neoContractHash, method, callflag.States, acc.PrivateKey().PublicKey().Bytes())
|
||||||
emit.Opcodes(w.BinWriter, opcode.ASSERT)
|
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(),
|
Account: acc.Contract.ScriptHash(),
|
||||||
Scopes: transaction.CalledByEntry,
|
Scopes: transaction.CalledByEntry,
|
||||||
})
|
}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
} else if err = acc.SignTx(tx); err != nil {
|
} 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.AppCall(w.BinWriter, neoContractHash, "vote", callflag.States, addr.BytesBE(), pubArg)
|
||||||
emit.Opcodes(w.BinWriter, opcode.ASSERT)
|
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(),
|
Account: acc.Contract.ScriptHash(),
|
||||||
Scopes: transaction.CalledByEntry,
|
Scopes: transaction.CalledByEntry,
|
||||||
})
|
}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,17 +140,17 @@ func (c *Client) CreateNEP17MultiTransferTx(acc *wallet.Account, gas int64, reci
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("bad account address: %v", err)
|
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,
|
Account: accAddr,
|
||||||
Scopes: transaction.CalledByEntry,
|
Scopes: transaction.CalledByEntry,
|
||||||
})
|
}})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
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 ...transaction.Signer) (*transaction.Transaction, error) {
|
cosigners []transaction.Signer) (*transaction.Transaction, error) {
|
||||||
from, err := address.StringToUint160(acc.Address)
|
from, err := address.StringToUint160(acc.Address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("bad account address: %v", err)
|
return nil, fmt.Errorf("bad account address: %v", err)
|
||||||
|
|
|
@ -526,7 +526,7 @@ func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sys
|
||||||
var txHash util.Uint256
|
var txHash util.Uint256
|
||||||
var err error
|
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 {
|
if err != nil {
|
||||||
return txHash, fmt.Errorf("failed to create tx: %w", err)
|
return txHash, fmt.Errorf("failed to create tx: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,7 +347,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)
|
tx, err := c.CreateTxFromScript([]byte{byte(opcode.PUSH1)}, acc, -1, 10, nil)
|
||||||
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
|
||||||
|
@ -355,7 +355,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)
|
tx, err := c.CreateTxFromScript([]byte{byte(opcode.PUSH1)}, acc, 123, 10, nil)
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue