From 7eaeb18f18689ab1438c7484f67de474e2305fef Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 3 Mar 2020 21:20:58 +0300 Subject: [PATCH] transaction: marshal ContractTX even if Data is nil It contains no information so it doesn't matter anyway. --- cli/wallet/wallet.go | 1 - pkg/core/transaction/transaction.go | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cli/wallet/wallet.go b/cli/wallet/wallet.go index 41c043d90..2928192ac 100644 --- a/cli/wallet/wallet.go +++ b/cli/wallet/wallet.go @@ -416,7 +416,6 @@ func transferAsset(ctx *cli.Context) error { } tx := transaction.NewContractTX() - tx.Data = new(transaction.ContractTX) if err := request.AddInputsAndUnspentsToTx(tx, from, asset, amount, c); err != nil { return cli.NewExitError(err, 1) } diff --git a/pkg/core/transaction/transaction.go b/pkg/core/transaction/transaction.go index adfa9e2dc..da6704e8e 100644 --- a/pkg/core/transaction/transaction.go +++ b/pkg/core/transaction/transaction.go @@ -158,7 +158,8 @@ func (t *Transaction) EncodeBinary(bw *io.BinWriter) { // encodeHashableFields encodes the fields that are not used for // signing the transaction, which are all fields except the scripts. func (t *Transaction) encodeHashableFields(bw *io.BinWriter) { - if t.Data == nil { + noData := t.Type == ContractType + if t.Data == nil && !noData { bw.Err = errors.New("transaction has no data") return } @@ -166,7 +167,9 @@ func (t *Transaction) encodeHashableFields(bw *io.BinWriter) { bw.WriteB(byte(t.Version)) // Underlying TXer. - t.Data.EncodeBinary(bw) + if !noData { + t.Data.EncodeBinary(bw) + } // Attributes bw.WriteArray(t.Attributes)