forked from cerc-io/plugeth
Rename transport to ws
Cleanup object naming for clarity
This commit is contained in:
parent
a38bca3438
commit
dd3f38fe5b
@ -39,7 +39,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/miner"
|
"github.com/ethereum/go-ethereum/miner"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
rpchttp "github.com/ethereum/go-ethereum/rpc/http"
|
rpchttp "github.com/ethereum/go-ethereum/rpc/http"
|
||||||
rpcws "github.com/ethereum/go-ethereum/rpc/websocket"
|
rpcws "github.com/ethereum/go-ethereum/rpc/ws"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
// "github.com/ethereum/go-ethereum/websocket"
|
// "github.com/ethereum/go-ethereum/websocket"
|
||||||
"github.com/ethereum/go-ethereum/xeth"
|
"github.com/ethereum/go-ethereum/xeth"
|
||||||
|
@ -14,14 +14,14 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package websocket
|
package ws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
ws "code.google.com/p/go.net/websocket"
|
"code.google.com/p/go.net/websocket"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/event/filter"
|
"github.com/ethereum/go-ethereum/event/filter"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
@ -88,23 +88,23 @@ func (self *WebSocketServer) Start() {
|
|||||||
func (s *WebSocketServer) apiHandler(xeth *rpc.EthereumApi) http.Handler {
|
func (s *WebSocketServer) apiHandler(xeth *rpc.EthereumApi) http.Handler {
|
||||||
fn := func(w http.ResponseWriter, req *http.Request) {
|
fn := func(w http.ResponseWriter, req *http.Request) {
|
||||||
h := sockHandler(xeth)
|
h := sockHandler(xeth)
|
||||||
s := ws.Server{Handler: h}
|
s := websocket.Server{Handler: h}
|
||||||
s.ServeHTTP(w, req)
|
s.ServeHTTP(w, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
return http.HandlerFunc(fn)
|
return http.HandlerFunc(fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sockHandler(xeth *rpc.EthereumApi) ws.Handler {
|
func sockHandler(xeth *rpc.EthereumApi) websocket.Handler {
|
||||||
fn := func(conn *ws.Conn) {
|
fn := func(conn *websocket.Conn) {
|
||||||
for {
|
for {
|
||||||
// FIX wslogger does not output to console
|
// FIX wslogger does not output to console
|
||||||
wslogger.Debugln("Handling request")
|
wslogger.Debugln("Handling request")
|
||||||
var reqParsed rpc.RpcRequest
|
var reqParsed rpc.RpcRequest
|
||||||
|
|
||||||
if err := ws.JSON.Receive(conn, &reqParsed); err != nil {
|
if err := websocket.JSON.Receive(conn, &reqParsed); err != nil {
|
||||||
wslogger.Debugln(rpc.ErrorParseRequest)
|
wslogger.Debugln(rpc.ErrorParseRequest)
|
||||||
ws.JSON.Send(conn, rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: rpc.ErrorParseRequest})
|
websocket.JSON.Send(conn, rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: rpc.ErrorParseRequest})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,12 +112,12 @@ func sockHandler(xeth *rpc.EthereumApi) ws.Handler {
|
|||||||
reserr := xeth.GetRequestReply(&reqParsed, &response)
|
reserr := xeth.GetRequestReply(&reqParsed, &response)
|
||||||
if reserr != nil {
|
if reserr != nil {
|
||||||
wslogger.Errorln(reserr)
|
wslogger.Errorln(reserr)
|
||||||
ws.JSON.Send(conn, rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: reserr.Error()})
|
websocket.JSON.Send(conn, rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: reserr.Error()})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
wslogger.Debugf("Generated response: %T %s", response, response)
|
wslogger.Debugf("Generated response: %T %s", response, response)
|
||||||
ws.JSON.Send(conn, rpc.RpcSuccessResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: false, Result: response})
|
websocket.JSON.Send(conn, rpc.RpcSuccessResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: false, Result: response})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fn
|
return fn
|
Loading…
Reference in New Issue
Block a user