Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #516 from benjaminbollen/issue453-fix
Browse files Browse the repository at this point in the history
Fix for deserialisation of BroadcastTx which was missing a type byte.
  • Loading branch information
zramsay authored Feb 27, 2017
2 parents 5052b10 + 2ef4b05 commit 2915d10
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 63 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Eris DB
# Eris-DB

|[![GoDoc](https://godoc.org/github.com/eris-db?status.png)](https://godoc.org/github.com/eris-ltd/eris-db) | Linux |
|---|-------|
| Master | [![Circle CI](https://circleci.com/gh/eris-ltd/eris-db/tree/master.svg?style=svg)](https://circleci.com/gh/eris-ltd/eris-db/tree/master) |
| Develop | [![Circle CI (develop)](https://circleci.com/gh/eris-ltd/eris-db/tree/develop.svg?style=svg)](https://circleci.com/gh/eris-ltd/eris-db/tree/develop) |

Eris DB is Eris' blockchain client. It includes a permissions layer, an implementation of the Ethereum Virtual Machine, and uses Tendermint Consensus. Most functionality is provided by `eris chains`, exposed through [eris-cli](https://monax.io/docs/documentation/cli), the entry point for the Eris Platform.
Eris-db is Monax' permissioned blockchain client. It executes Ethereum smart contracts on a permissioned virtual machine. Eris-db provides transaction finality and high transaction throughput on proof-of-stake Tendermint consensus engine. For smart contract development most functionality is provided by `eris chains`, exposed through [eris](https://monax.io/docs/documentation/cli), the entry point for the Eris Platform.

## Table of Contents

Expand All @@ -22,7 +22,7 @@ See the [eris-db documentation](https://monax.io/docs/documentation/db/) for mor

## Installation

`eris-db` is intended to be used by the `eris chains` command via [eris-cli](https://monax.io/docs/documentation/cli/latest/eris_chains). Available commands such as `make | start | stop | logs | inspect | update` are used for chain lifecycle management.
`eris-db` is intended to be used by the `eris chains` command via [eris](https://monax.io/docs/documentation/cli/latest/eris_chains). Available commands such as `make | start | stop | logs | inspect | update` are used for chain lifecycle management.

### For Developers
Dependency management for eris-db is managed with [glide](github.com/Masterminds/glide), and you can build eris-db from source by following
Expand All @@ -32,9 +32,13 @@ Dependency management for eris-db is managed with [glide](github.com/Masterminds
3. and execute following commands in a terminal:
```
go get github.com/Masterminds/glide
go get -d github.com/eris-ltd/eris-db
REPO=$($GOPATH/src/github.com/eris-ltd/eris-db)
cd $REPO && glide install
cd $REPO/cmd/eris-db && go install
```

Expand Down
1 change: 1 addition & 0 deletions rpc/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ type Codec interface {
EncodeBytes(interface{}) ([]byte, error)
Encode(interface{}, io.Writer) error
DecodeBytes(interface{}, []byte) error
DecodeBytesPtr(interface{}, []byte) error
Decode(interface{}, io.Reader) error
}
9 changes: 9 additions & 0 deletions rpc/v0/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func (this *TCodec) EncodeBytes(v interface{}) ([]byte, error) {
return wire.JSONBytes(v), nil
}

// TODO: [ben] implement EncodeBytesPtr ?

// Decode from an io.Reader.
func (this *TCodec) Decode(v interface{}, r io.Reader) error {
bts, errR := ioutil.ReadAll(r)
Expand All @@ -62,3 +64,10 @@ func (this *TCodec) DecodeBytes(v interface{}, bts []byte) error {
wire.ReadJSON(v, bts, &err)
return err
}

// Decode from a byte array pointer.
func (this *TCodec) DecodeBytesPtr(v interface{}, bts []byte) error {
var err error
wire.ReadJSONPtr(v, bts, &err)
return err
}
71 changes: 71 additions & 0 deletions rpc/v0/json_service_data_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2017 Monax Industries Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package rpc_v0

import (
"encoding/json"
"testing"

"github.com/eris-ltd/eris-db/rpc"
"github.com/eris-ltd/eris-db/txs"

"github.com/stretchr/testify/assert"
)

var testBroadcastCallTxJsonRequest = []byte(`
{
"id": "57EC1D39-7B3D-4F96-B286-8FC128177AFC4",
"jsonrpc": "2.0",
"method": "erisdb.broadcastTx",
"params": [
2,
{
"address": "5A9083BB0EFFE4C8EB2ADD29174994F73E77D418",
"data": "2F2397A00000000000000000000000000000000000000000000000000000000000003132",
"fee": 1,
"gas_limit": 1000000,
"input": {
"address": "BE18FDCBF12BF99F4D75325E17FF2E78F1A35FE8",
"amount": 1,
"pub_key": [
1,
"8D1611925948DC2EDDF739FB65CE517757D286155A039B28441C3349BE9A8C38"
],
"sequence": 2,
"signature": [
1,
"B090D622F143ECEDA9B9E7B15485CE7504453C05434951CF867B013D80ED1BD2A0CA32846FC175D234CDFB9D5C3D792759E8FE79FD4DB3006B24950EE3C37D00"
]
}
}
]
}`)

// strictly test the codec for go-wire encoding of the Json format,
// This should restore compatibility with the format on v0.11.4
// (which was broken on v0.12)
func TestCallTxJsonFormatCodec(t *testing.T) {
codec := NewTCodec()
param := new(txs.Tx)

// Create new request object and unmarshal.
request := &rpc.RPCRequest{}
assert.NoError(t, json.Unmarshal(testBroadcastCallTxJsonRequest, request),
"Provided JSON test data does not unmarshal to rpc.RPCRequest object.")
assert.NoError(t, codec.DecodeBytesPtr(param, request.Params),
"RPC codec failed to decode params as transaction type.")
_, ok := (*param).(*txs.CallTx)
assert.True(t, ok, "Type byte 0x02 should unmarshal into CallTx.")
}
7 changes: 4 additions & 3 deletions rpc/v0/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,13 @@ func (erisDbMethods *ErisDbMethods) CallCode(request *rpc.RPCRequest, requester
}

func (erisDbMethods *ErisDbMethods) BroadcastTx(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) {
param := &txs.CallTx{}
err := erisDbMethods.codec.DecodeBytes(param, request.Params)
// Accept all transaction types as parameter for broadcast.
param := new(txs.Tx)
err := erisDbMethods.codec.DecodeBytesPtr(param, request.Params)
if err != nil {
return nil, rpc.INVALID_PARAMS, err
}
receipt, errC := erisDbMethods.pipe.Transactor().BroadcastTx(param)
receipt, errC := erisDbMethods.pipe.Transactor().BroadcastTx(*param)
if errC != nil {
return nil, rpc.INTERNAL_ERROR, errC
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package testdata
package rpc_v0

import (
account "github.com/eris-ltd/eris-db/account"
consensus_types "github.com/eris-ltd/eris-db/consensus/types"
core_types "github.com/eris-ltd/eris-db/core/types"
event "github.com/eris-ltd/eris-db/event"
genesis "github.com/eris-ltd/eris-db/genesis"
rpc_v0 "github.com/eris-ltd/eris-db/rpc/v0"
"github.com/eris-ltd/eris-db/rpc/v0/shared"
transaction "github.com/eris-ltd/eris-db/txs"
mintTypes "github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -558,22 +557,22 @@ type (
}

GetAccountData struct {
Input *rpc_v0.AddressParam `json:"input"`
Output *account.Account `json:"output"`
Input *AddressParam `json:"input"`
Output *account.Account `json:"output"`
}

GetAccountsData struct {
Input *rpc_v0.AccountsParam `json:"input"`
Input *AccountsParam `json:"input"`
Output *core_types.AccountList `json:"output"`
}

GetStorageData struct {
Input *rpc_v0.AddressParam `json:"input"`
Output *core_types.Storage `json:"output"`
Input *AddressParam `json:"input"`
Output *core_types.Storage `json:"output"`
}

GetStorageAtData struct {
Input *rpc_v0.StorageAtParam `json:"input"`
Input *StorageAtParam `json:"input"`
Output *core_types.StorageItem `json:"output"`
}

Expand Down Expand Up @@ -602,13 +601,13 @@ type (
}

GetBlockData struct {
Input *rpc_v0.HeightParam `json:"input"`
Output *mintTypes.Block `json:"output"`
Input *HeightParam `json:"input"`
Output *mintTypes.Block `json:"output"`
}

GetBlocksData struct {
Input *rpc_v0.BlocksParam `json:"input"`
Output *core_types.Blocks `json:"output"`
Input *BlocksParam `json:"input"`
Output *core_types.Blocks `json:"output"`
}

GetConsensusStateData struct {
Expand Down Expand Up @@ -644,62 +643,62 @@ type (
}

GetPeerData struct {
Input *rpc_v0.PeerParam `json:"input"`
Input *PeerParam `json:"input"`
Output *consensus_types.Peer `json:"output"`
}

TransactData struct {
Input *rpc_v0.TransactParam `json:"input"`
Output *transaction.Receipt `json:"output"`
Input *TransactParam `json:"input"`
Output *transaction.Receipt `json:"output"`
}

TransactCreateData struct {
Input *rpc_v0.TransactParam `json:"input"`
Output *transaction.Receipt `json:"output"`
Input *TransactParam `json:"input"`
Output *transaction.Receipt `json:"output"`
}

GetUnconfirmedTxsData struct {
Output *transaction.UnconfirmedTxs `json:"output"`
}

CallCodeData struct {
Input *rpc_v0.CallCodeParam `json:"input"`
Output *core_types.Call `json:"output"`
Input *CallCodeParam `json:"input"`
Output *core_types.Call `json:"output"`
}

CallData struct {
Input *rpc_v0.CallParam `json:"input"`
Output *core_types.Call `json:"output"`
Input *CallParam `json:"input"`
Output *core_types.Call `json:"output"`
}

EventSubscribeData struct {
Input *rpc_v0.EventIdParam `json:"input"`
Output *event.EventSub `json:"output"`
Input *EventIdParam `json:"input"`
Output *event.EventSub `json:"output"`
}

EventUnsubscribeData struct {
Input *rpc_v0.SubIdParam `json:"input"`
Output *event.EventUnsub `json:"output"`
Input *SubIdParam `json:"input"`
Output *event.EventUnsub `json:"output"`
}

TransactNameRegData struct {
Input *rpc_v0.TransactNameRegParam `json:"input"`
Output *transaction.Receipt `json:"output"`
Input *TransactNameRegParam `json:"input"`
Output *transaction.Receipt `json:"output"`
}

GetNameRegEntryData struct {
Input *rpc_v0.NameRegEntryParam `json:"input"`
Output *core_types.NameRegEntry `json:"output"`
Input *NameRegEntryParam `json:"input"`
Output *core_types.NameRegEntry `json:"output"`
}

GetNameRegEntriesData struct {
Input *rpc_v0.FilterListParam `json:"input"`
Input *FilterListParam `json:"input"`
Output *core_types.ResultListNames `json:"output"`
}

/*
EventPollData struct {
Input *rpc_v0.SubIdParam `json:"input"`
Input *SubIdParam `json:"input"`
Output *event.PollResponse `json:"output"`
}
*/
Expand Down Expand Up @@ -742,7 +741,7 @@ type (
)

func LoadTestData() *TestData {
codec := rpc_v0.NewTCodec()
codec := NewTCodec()
testData := &TestData{}
if err := codec.DecodeBytes(testData, []byte(testDataJson)); err != nil {
panic(err)
Expand Down
Loading

0 comments on commit 2915d10

Please sign in to comment.