From e0a17d353ee1c71d4c6dea77c49a8e0ad8863a21 Mon Sep 17 00:00:00 2001 From: Ethan Buchman <ethan@coinculture.info> Date: Wed, 20 Jan 2016 23:38:19 -0500 Subject: [PATCH] fixes for BroadcastTx --- erisdb/codec.go | 5 +++-- erisdb/methods.go | 15 ++++++++++----- erisdb/restServer.go | 25 ++++++++++++++++--------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/erisdb/codec.go b/erisdb/codec.go index 04055df1..f72bcd3a 100644 --- a/erisdb/codec.go +++ b/erisdb/codec.go @@ -1,10 +1,11 @@ package erisdb import ( - "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/wire" - rpc "github.com/eris-ltd/eris-db/rpc" "io" "io/ioutil" + + "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/wire" + rpc "github.com/eris-ltd/eris-db/rpc" ) // Codec that uses tendermints 'binary' package for JSON. diff --git a/erisdb/methods.go b/erisdb/methods.go index 0b0a370e..2adfc778 100644 --- a/erisdb/methods.go +++ b/erisdb/methods.go @@ -3,10 +3,13 @@ package erisdb import ( "crypto/rand" "encoding/hex" - "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/types" + "strings" + ep "github.com/eris-ltd/eris-db/erisdb/pipe" rpc "github.com/eris-ltd/eris-db/rpc" - "strings" + + "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/types" + "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/wire" ) // TODO use the method name definition file. @@ -381,12 +384,14 @@ func (this *ErisDbMethods) CallCode(request *rpc.RPCRequest, requester interface } func (this *ErisDbMethods) BroadcastTx(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { - param := &types.CallTx{} - err := this.codec.DecodeBytes(param, request.Params) + var err error + // Special because Tx is an interface + param := new(types.Tx) + wire.ReadJSONPtr(param, request.Params, &err) if err != nil { return nil, rpc.INVALID_PARAMS, err } - receipt, errC := this.pipe.Transactor().BroadcastTx(param) + receipt, errC := this.pipe.Transactor().BroadcastTx(*param) if errC != nil { return nil, rpc.INTERNAL_ERROR, errC } diff --git a/erisdb/restServer.go b/erisdb/restServer.go index 5585d572..cf428321 100644 --- a/erisdb/restServer.go +++ b/erisdb/restServer.go @@ -3,14 +3,18 @@ package erisdb import ( "encoding/hex" "fmt" - "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/gin-gonic/gin" - "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/types" + "io/ioutil" + "strconv" + "strings" + ep "github.com/eris-ltd/eris-db/erisdb/pipe" rpc "github.com/eris-ltd/eris-db/rpc" "github.com/eris-ltd/eris-db/server" "github.com/eris-ltd/eris-db/util" - "strconv" - "strings" + + "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/gin-gonic/gin" + "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/types" + "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/wire" ) // Provides a REST-like web-api. Implements server.Server @@ -372,12 +376,15 @@ func (this *RestServer) handlePeer(c *gin.Context) { // ********************************* Transactions ********************************* func (this *RestServer) handleBroadcastTx(c *gin.Context) { - param := &types.CallTx{} - errD := this.codec.Decode(param, c.Request.Body) - if errD != nil { - c.AbortWithError(500, errD) + // Special because Tx is an interface + param := new(types.Tx) + b, err := ioutil.ReadAll(c.Request.Body) + defer c.Request.Body.Close() + wire.ReadJSONPtr(param, b, &err) + if err != nil { + c.AbortWithError(500, err) } - receipt, err := this.pipe.Transactor().BroadcastTx(param) + receipt, err := this.pipe.Transactor().BroadcastTx(*param) if err != nil { c.AbortWithError(500, err) } -- GitLab