diff --git a/pkg/core/transaction/transaction.go b/pkg/core/transaction/transaction.go index cdabfa3c0..e9384f50a 100644 --- a/pkg/core/transaction/transaction.go +++ b/pkg/core/transaction/transaction.go @@ -197,6 +197,16 @@ func (t Transaction) GroupOutputByAssetID() map[util.Uint256][]*Output { return m } +// GetSignedPart returns a part of the transaction which must be signed. +func (t *Transaction) GetSignedPart() []byte { + buf := io.NewBufBinWriter() + t.encodeHashableFields(buf.BinWriter) + if buf.Err != nil { + return nil + } + return buf.Bytes() +} + // Bytes converts the transaction to []byte func (t *Transaction) Bytes() []byte { buf := io.NewBufBinWriter() diff --git a/pkg/rpc/request/txBuilder.go b/pkg/rpc/request/txBuilder.go index dad08b42a..25738d7e5 100644 --- a/pkg/rpc/request/txBuilder.go +++ b/pkg/rpc/request/txBuilder.go @@ -94,16 +94,7 @@ func SignTx(tx *transaction.Transaction, wif *keys.WIF) error { // GetInvocationScript returns NEO VM script containing transaction signature. func GetInvocationScript(tx *transaction.Transaction, wif *keys.WIF) ([]byte, error) { - var ( - buf = io.NewBufBinWriter() - signature []byte - ) - tx.EncodeBinary(buf.BinWriter) - if buf.Err != nil { - return nil, errs.Wrap(buf.Err, "Failed to encode transaction to binary") - } - data := buf.Bytes() - signature = wif.PrivateKey.Sign(data[:(len(data) - 1)]) + signature := wif.PrivateKey.Sign(tx.GetSignedPart()) return append([]byte{byte(opcode.PUSHBYTES64)}, signature...), nil }