transaction: fix invocation decoding for different versions

Quick fix similar to abc5833853 + uncomment the
test case for it.

Closes #173.
This commit is contained in:
Roman Khimov 2019-08-30 10:44:59 +03:00
parent 2ef2c0b84c
commit 8ececdc9a7
3 changed files with 11 additions and 5 deletions

View file

@ -14,6 +14,7 @@ type InvocationTX struct {
// Gas cost of the smart contract. // Gas cost of the smart contract.
Gas util.Fixed8 Gas util.Fixed8
Version uint8
} }
// NewInvocationTX returns a new invocation transaction. // NewInvocationTX returns a new invocation transaction.
@ -35,7 +36,11 @@ func NewInvocationTX(script []byte) *Transaction {
func (tx *InvocationTX) DecodeBinary(r io.Reader) error { func (tx *InvocationTX) DecodeBinary(r io.Reader) error {
br := util.BinReader{R: r} br := util.BinReader{R: r}
tx.Script = br.ReadBytes() tx.Script = br.ReadBytes()
if (tx.Version >= 1) {
br.ReadLE(&tx.Gas) br.ReadLE(&tx.Gas)
} else {
tx.Gas = util.Fixed8FromInt64(0)
}
return br.Err return br.Err
} }
@ -43,6 +48,8 @@ func (tx *InvocationTX) DecodeBinary(r io.Reader) error {
func (tx *InvocationTX) EncodeBinary(w io.Writer) error { func (tx *InvocationTX) EncodeBinary(w io.Writer) error {
bw := util.BinWriter{W: w} bw := util.BinWriter{W: w}
bw.WriteBytes(tx.Script) bw.WriteBytes(tx.Script)
if (tx.Version >= 1) {
bw.WriteLE(tx.Gas) bw.WriteLE(tx.Gas)
}
return bw.Err return bw.Err
} }

View file

@ -136,7 +136,7 @@ func (t *Transaction) DecodeBinary(r io.Reader) error {
func (t *Transaction) decodeData(r io.Reader) error { func (t *Transaction) decodeData(r io.Reader) error {
switch t.Type { switch t.Type {
case InvocationType: case InvocationType:
t.Data = &InvocationTX{} t.Data = &InvocationTX{Version: t.Version}
return t.Data.(*InvocationTX).DecodeBinary(r) return t.Data.(*InvocationTX).DecodeBinary(r)
case MinerType: case MinerType:
t.Data = &MinerTX{} t.Data = &MinerTX{}

View file

@ -224,12 +224,11 @@ var testRpcCases = []tc{
expectedResult: `{"jsonrpc":"2.0","result":true,"id":1}`, 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"] }`, rpcCall: `{ "jsonrpc": "2.0", "id": 1, "method": "sendrawtransaction", "params": ["d1001b00046e616d6567d3d8602814a429a91afdbaa3914884a1c90c733101201cc9c05cefffe6cdd7b182816a9152ec218d2ec000000141403387ef7940a5764259621e655b3c621a6aafd869a611ad64adcc364d8dd1edf84e00a7f8b11b630a377eaef02791d1c289d711c08b7ad04ff0d6c9caca22cfe6232103cbb45da6072c14761c9da545749d9cfd863f860c351066d16df480602a2024c6ac"] }`,
method: "sendrawtransaction_2", method: "sendrawtransaction_2",
expectedResult: `{"jsonrpc":"2.0","result":true,"id":1}`, expectedResult: `{"jsonrpc":"2.0","result":true,"id":1}`,
},*/ },
// Bad case, incorrect raw transaction // Bad case, incorrect raw transaction
{ {