From 1d3a297a6b270b872893948a380b9d9692f91cc5 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 16 Apr 2021 13:54:23 +0300 Subject: [PATCH] rpc: add Data field to NEP17 TransferTarget It's a part of transfer, thus it should be passed along with the other transfer parameters. --- cli/wallet/nep17.go | 4 +++- pkg/rpc/client/nep17.go | 21 ++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/cli/wallet/nep17.go b/cli/wallet/nep17.go index 76096bb94..68c3606f7 100644 --- a/cli/wallet/nep17.go +++ b/cli/wallet/nep17.go @@ -411,6 +411,7 @@ func multiTransferNEP17(ctx *cli.Context) error { Token: token.Hash, Address: addr, Amount: amount.Int64(), + Data: nil, }) } @@ -462,13 +463,14 @@ func transferNEP17(ctx *cli.Context) error { Token: token.Hash, Address: to, Amount: amount.Int64(), + Data: nil, }}) } func signAndSendTransfer(ctx *cli.Context, c *client.Client, acc *wallet.Account, recipients []client.TransferTarget) error { gas := flags.Fixed8FromContext(ctx, "gas") - tx, err := c.CreateNEP17MultiTransferTx(acc, int64(gas), recipients, nil) + tx, err := c.CreateNEP17MultiTransferTx(acc, int64(gas), recipients) if err != nil { return cli.NewExitError(err, 1) } diff --git a/pkg/rpc/client/nep17.go b/pkg/rpc/client/nep17.go index 51d7b5ed7..3b27ebf54 100644 --- a/pkg/rpc/client/nep17.go +++ b/pkg/rpc/client/nep17.go @@ -13,11 +13,12 @@ import ( "github.com/nspcc-dev/neo-go/pkg/wallet" ) -// TransferTarget represents target address and token amount for transfer. +// TransferTarget represents target address, token amount and data for transfer. type TransferTarget struct { Token util.Uint160 Address util.Uint160 Amount int64 + Data interface{} } // SignerAccount represents combination of the transaction.Signer and the @@ -73,28 +74,22 @@ func (c *Client) CreateNEP17TransferTx(acc *wallet.Account, to util.Uint160, tok {Token: token, Address: to, Amount: amount, + Data: data, }, - }, []interface{}{data}) + }) } // CreateNEP17MultiTransferTx creates an invocation transaction for performing NEP17 transfers // from a single sender to multiple recipients with the given data. -func (c *Client) CreateNEP17MultiTransferTx(acc *wallet.Account, gas int64, recipients []TransferTarget, data []interface{}) (*transaction.Transaction, error) { +func (c *Client) CreateNEP17MultiTransferTx(acc *wallet.Account, gas int64, recipients []TransferTarget) (*transaction.Transaction, error) { from, err := address.StringToUint160(acc.Address) if err != nil { return nil, fmt.Errorf("bad account address: %w", err) } - if data == nil { - data = make([]interface{}, len(recipients)) - } else { - if len(data) != len(recipients) { - return nil, fmt.Errorf("data and recipients number mismatch: %d vs %d", len(data), len(recipients)) - } - } w := io.NewBufBinWriter() for i := range recipients { emit.AppCall(w.BinWriter, recipients[i].Token, "transfer", callflag.All, - from, recipients[i].Address, recipients[i].Amount, data[i]) + from, recipients[i].Address, recipients[i].Amount, recipients[i].Data) emit.Opcodes(w.BinWriter, opcode.ASSERT) } if w.Err != nil { @@ -167,12 +162,12 @@ func (c *Client) TransferNEP17(acc *wallet.Account, to util.Uint160, token util. } // MultiTransferNEP17 is similar to TransferNEP17, buf allows to have multiple recipients. -func (c *Client) MultiTransferNEP17(acc *wallet.Account, gas int64, recipients []TransferTarget, data []interface{}) (util.Uint256, error) { +func (c *Client) MultiTransferNEP17(acc *wallet.Account, gas int64, recipients []TransferTarget) (util.Uint256, error) { if !c.initDone { return util.Uint256{}, errNetworkNotInitialized } - tx, err := c.CreateNEP17MultiTransferTx(acc, gas, recipients, data) + tx, err := c.CreateNEP17MultiTransferTx(acc, gas, recipients) if err != nil { return util.Uint256{}, err }