forked from TrueCloudLab/neoneo-go
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,
|
Token: token.Hash,
|
||||||
Address: addr,
|
Address: addr,
|
||||||
Amount: amount.Int64(),
|
Amount: amount.Int64(),
|
||||||
|
Data: nil,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,13 +463,14 @@ func transferNEP17(ctx *cli.Context) error {
|
||||||
Token: token.Hash,
|
Token: token.Hash,
|
||||||
Address: to,
|
Address: to,
|
||||||
Amount: amount.Int64(),
|
Amount: amount.Int64(),
|
||||||
|
Data: nil,
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
|
||||||
func signAndSendTransfer(ctx *cli.Context, c *client.Client, acc *wallet.Account, recipients []client.TransferTarget) error {
|
func signAndSendTransfer(ctx *cli.Context, c *client.Client, acc *wallet.Account, recipients []client.TransferTarget) error {
|
||||||
gas := flags.Fixed8FromContext(ctx, "gas")
|
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 {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,12 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
"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 {
|
type TransferTarget struct {
|
||||||
Token util.Uint160
|
Token util.Uint160
|
||||||
Address util.Uint160
|
Address util.Uint160
|
||||||
Amount int64
|
Amount int64
|
||||||
|
Data interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignerAccount represents combination of the transaction.Signer and the
|
// 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,
|
{Token: token,
|
||||||
Address: to,
|
Address: to,
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
|
Data: data,
|
||||||
},
|
},
|
||||||
}, []interface{}{data})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateNEP17MultiTransferTx creates an invocation transaction for performing NEP17 transfers
|
// CreateNEP17MultiTransferTx creates an invocation transaction for performing NEP17 transfers
|
||||||
// from a single sender to multiple recipients with the given data.
|
// 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)
|
from, err := address.StringToUint160(acc.Address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("bad account address: %w", err)
|
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()
|
w := io.NewBufBinWriter()
|
||||||
for i := range recipients {
|
for i := range recipients {
|
||||||
emit.AppCall(w.BinWriter, recipients[i].Token, "transfer", callflag.All,
|
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)
|
emit.Opcodes(w.BinWriter, opcode.ASSERT)
|
||||||
}
|
}
|
||||||
if w.Err != nil {
|
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.
|
// 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 {
|
if !c.initDone {
|
||||||
return util.Uint256{}, errNetworkNotInitialized
|
return util.Uint256{}, errNetworkNotInitialized
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := c.CreateNEP17MultiTransferTx(acc, gas, recipients, data)
|
tx, err := c.CreateNEP17MultiTransferTx(acc, gas, recipients)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.Uint256{}, err
|
return util.Uint256{}, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue