From 8ececdc9a7d6d60fe7f9303d5fba5b4cb8dc3a57 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 30 Aug 2019 10:44:59 +0300 Subject: [PATCH] transaction: fix invocation decoding for different versions Quick fix similar to abc583385328cf468d4e2933884e03021aca35bf + uncomment the test case for it. Closes #173. --- pkg/core/transaction/invocation.go | 11 +++++++++-- pkg/core/transaction/transaction.go | 2 +- pkg/rpc/server_test.go | 3 +-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/core/transaction/invocation.go b/pkg/core/transaction/invocation.go index f07233cfe..2a0a73fcd 100644 --- a/pkg/core/transaction/invocation.go +++ b/pkg/core/transaction/invocation.go @@ -14,6 +14,7 @@ type InvocationTX struct { // Gas cost of the smart contract. Gas util.Fixed8 + Version uint8 } // NewInvocationTX returns a new invocation transaction. @@ -35,7 +36,11 @@ func NewInvocationTX(script []byte) *Transaction { func (tx *InvocationTX) DecodeBinary(r io.Reader) error { br := util.BinReader{R: r} tx.Script = br.ReadBytes() - br.ReadLE(&tx.Gas) + if (tx.Version >= 1) { + br.ReadLE(&tx.Gas) + } else { + tx.Gas = util.Fixed8FromInt64(0) + } return br.Err } @@ -43,6 +48,8 @@ func (tx *InvocationTX) DecodeBinary(r io.Reader) error { func (tx *InvocationTX) EncodeBinary(w io.Writer) error { bw := util.BinWriter{W: w} bw.WriteBytes(tx.Script) - bw.WriteLE(tx.Gas) + if (tx.Version >= 1) { + bw.WriteLE(tx.Gas) + } return bw.Err } diff --git a/pkg/core/transaction/transaction.go b/pkg/core/transaction/transaction.go index d2e242b3e..3c2332373 100644 --- a/pkg/core/transaction/transaction.go +++ b/pkg/core/transaction/transaction.go @@ -136,7 +136,7 @@ func (t *Transaction) DecodeBinary(r io.Reader) error { func (t *Transaction) decodeData(r io.Reader) error { switch t.Type { case InvocationType: - t.Data = &InvocationTX{} + t.Data = &InvocationTX{Version: t.Version} return t.Data.(*InvocationTX).DecodeBinary(r) case MinerType: t.Data = &MinerTX{} diff --git a/pkg/rpc/server_test.go b/pkg/rpc/server_test.go index c389142b7..03b18acd7 100644 --- a/pkg/rpc/server_test.go +++ b/pkg/rpc/server_test.go @@ -224,12 +224,11 @@ var testRpcCases = []tc{ expectedResult: `{"jsonrpc":"2.0","result":true,"id":1}`, }, - /* Good case: TODO: uncomment this test case once https://github.com/CityOfZion/neo-go/issues/173 is fixed! { rpcCall: `{ "jsonrpc": "2.0", "id": 1, "method": "sendrawtransaction", "params": ["d1001b00046e616d6567d3d8602814a429a91afdbaa3914884a1c90c733101201cc9c05cefffe6cdd7b182816a9152ec218d2ec000000141403387ef7940a5764259621e655b3c621a6aafd869a611ad64adcc364d8dd1edf84e00a7f8b11b630a377eaef02791d1c289d711c08b7ad04ff0d6c9caca22cfe6232103cbb45da6072c14761c9da545749d9cfd863f860c351066d16df480602a2024c6ac"] }`, method: "sendrawtransaction_2", expectedResult: `{"jsonrpc":"2.0","result":true,"id":1}`, - },*/ + }, // Bad case, incorrect raw transaction {