diff --git a/cli/wallet/nep5.go b/cli/wallet/nep5.go index 5640c045f..5961db31e 100644 --- a/cli/wallet/nep5.go +++ b/cli/wallet/nep5.go @@ -311,10 +311,7 @@ func transferNEP5(ctx *cli.Context) error { gas := flags.Fixed8FromContext(ctx, "gas") tx := transaction.NewInvocationTX(w.Bytes(), gas) - tx.Attributes = append(tx.Attributes, transaction.Attribute{ - Usage: transaction.Script, - Data: from.BytesBE(), - }) + tx.AddVerificationHash(from) if err := request.AddInputsAndUnspentsToTx(tx, fromFlag.String(), core.UtilityTokenID(), gas, c); err != nil { return cli.NewExitError(fmt.Errorf("can't add GAS to a tx: %v", err), 1) diff --git a/pkg/core/transaction/transaction.go b/pkg/core/transaction/transaction.go index da6704e8e..2bf7108ee 100644 --- a/pkg/core/transaction/transaction.go +++ b/pkg/core/transaction/transaction.go @@ -91,6 +91,14 @@ func (t *Transaction) AddInput(in *Input) { t.Inputs = append(t.Inputs, *in) } +// AddVerificationHash adds a script attribute for transaction verification. +func (t *Transaction) AddVerificationHash(addr util.Uint160) { + t.Attributes = append(t.Attributes, Attribute{ + Usage: Script, + Data: addr.BytesBE(), + }) +} + // DecodeBinary implements Serializable interface. func (t *Transaction) DecodeBinary(br *io.BinReader) { t.Type = TXType(br.ReadB()) diff --git a/pkg/rpc/client/rpc.go b/pkg/rpc/client/rpc.go index 893a2dddc..5da25f9af 100644 --- a/pkg/rpc/client/rpc.go +++ b/pkg/rpc/client/rpc.go @@ -515,11 +515,7 @@ func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sys if err != nil { return txHash, errors.Wrap(err, "failed to get address") } - tx.Attributes = append(tx.Attributes, - transaction.Attribute{ - Usage: transaction.Script, - Data: addr.BytesBE(), - }) + tx.AddVerificationHash(addr) } if err = acc.SignTx(tx); err != nil { diff --git a/pkg/rpc/request/txBuilder.go b/pkg/rpc/request/txBuilder.go index f841a71b3..cd7cd75fc 100644 --- a/pkg/rpc/request/txBuilder.go +++ b/pkg/rpc/request/txBuilder.go @@ -38,11 +38,7 @@ func CreateRawContractTransaction(params ContractTxParams) (*transaction.Transac if toAddressHash, err = address.StringToUint160(toAddress); err != nil { return nil, errs.Wrapf(err, "Failed to take script hash from address: %v", toAddress) } - tx.Attributes = append(tx.Attributes, - transaction.Attribute{ - Usage: transaction.Script, - Data: fromAddressHash.BytesBE(), - }) + tx.AddVerificationHash(fromAddressHash) if err = AddInputsAndUnspentsToTx(tx, fromAddress, assetID, amount, balancer); err != nil { return nil, errs.Wrap(err, "failed to add inputs and unspents to transaction")