mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 19:29:39 +00:00
rpc: add Data field to NEP17 TransferTarget
It's a part of transfer, thus it should be passed along with the other transfer parameters.
This commit is contained in:
parent
2bc5f72523
commit
1d3a297a6b
2 changed files with 11 additions and 14 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue