transaction: implement AddVerificationHash() method

This commit is contained in:
Evgenii Stratonikov 2020-03-12 19:47:09 +03:00
parent ca476cbf8a
commit cdf025bf89
4 changed files with 11 additions and 14 deletions

View file

@ -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)

View file

@ -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())

View file

@ -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 {

View file

@ -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")