aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-01-06 18:44:22 +0800
committerobscuren <geffobscura@gmail.com>2015-01-06 18:44:22 +0800
commita26aecdfdb0223b2fb54ca2d40adb2b531512d42 (patch)
tree4bc8e01cbd36d831734be23d9433ea7446ea761e
parent47e6b2cef8ee0164e82d119c6a9359b55259d645 (diff)
downloaddexon-a26aecdfdb0223b2fb54ca2d40adb2b531512d42.tar
dexon-a26aecdfdb0223b2fb54ca2d40adb2b531512d42.tar.gz
dexon-a26aecdfdb0223b2fb54ca2d40adb2b531512d42.tar.bz2
dexon-a26aecdfdb0223b2fb54ca2d40adb2b531512d42.tar.lz
dexon-a26aecdfdb0223b2fb54ca2d40adb2b531512d42.tar.xz
dexon-a26aecdfdb0223b2fb54ca2d40adb2b531512d42.tar.zst
dexon-a26aecdfdb0223b2fb54ca2d40adb2b531512d42.zip
Updated WS API. Fixes #219. Closes #220
-rw-r--r--cmd/utils/websockets.go70
-rw-r--r--websocket/client.go6
-rw-r--r--websocket/message.go2
-rw-r--r--websocket/server.go2
4 files changed, 38 insertions, 42 deletions
diff --git a/cmd/utils/websockets.go b/cmd/utils/websockets.go
index e4bc1b185..ef9de192b 100644
--- a/cmd/utils/websockets.go
+++ b/cmd/utils/websockets.go
@@ -33,73 +33,73 @@ func (self *WebSocketServer) Serv() {
data := ethutil.NewValue(msg.Args)
bcode, err := ethutil.Compile(data.Get(0).Str(), false)
if err != nil {
- c.Write(args(nil, err.Error()), msg.Seed)
+ c.Write(args(nil, err.Error()), msg.Id)
}
code := ethutil.Bytes2Hex(bcode)
- c.Write(args(code, nil), msg.Seed)
- case "getBlockByNumber":
+ c.Write(args(code, nil), msg.Id)
+ case "eth_blockByNumber":
args := msg.Arguments()
block := pipe.BlockByNumber(int32(args.Get(0).Uint()))
- c.Write(block, msg.Seed)
+ c.Write(block, msg.Id)
- case "getKey":
- c.Write(pipe.Key().PrivateKey, msg.Seed)
- case "transact":
+ case "eth_blockByHash":
+ args := msg.Arguments()
+
+ c.Write(pipe.BlockByHash(args.Get(0).Str()), msg.Id)
+
+ case "eth_transact":
if mp, ok := msg.Args[0].(map[string]interface{}); ok {
object := mapToTxParams(mp)
c.Write(
- args(pipe.Transact(object["from"], object["to"], object["value"], object["gas"], object["gasPrice"], object["data"])),
- msg.Seed,
+ args(pipe.Transact(pipe.Key().PrivateKey, object["to"], object["value"], object["gas"], object["gasPrice"], object["data"])),
+ msg.Id,
)
}
- case "getCoinBase":
- c.Write(pipe.CoinBase(), msg.Seed)
+ case "eth_gasPrice":
+ c.Write("10000000000000", msg.Id)
+ case "eth_coinbase":
+ c.Write(pipe.CoinBase(), msg.Id)
- case "getIsListening":
- c.Write(pipe.IsListening(), msg.Seed)
+ case "eth_listening":
+ c.Write(pipe.IsListening(), msg.Id)
- case "getIsMining":
- c.Write(pipe.IsMining(), msg.Seed)
-
- case "getPeerCoint":
- c.Write(pipe.PeerCount(), msg.Seed)
-
- case "getCountAt":
- args := msg.Arguments()
+ case "eth_mining":
+ c.Write(pipe.IsMining(), msg.Id)
- c.Write(pipe.TxCountAt(args.Get(0).Str()), msg.Seed)
+ case "eth_peerCount":
+ c.Write(pipe.PeerCount(), msg.Id)
- case "getCodeAt":
+ case "eth_countAt":
args := msg.Arguments()
- c.Write(len(pipe.CodeAt(args.Get(0).Str())), msg.Seed)
+ c.Write(pipe.TxCountAt(args.Get(0).Str()), msg.Id)
- case "getBlockByHash":
+ case "eth_codeAt":
args := msg.Arguments()
- c.Write(pipe.BlockByHash(args.Get(0).Str()), msg.Seed)
+ c.Write(len(pipe.CodeAt(args.Get(0).Str())), msg.Id)
- case "getStorageAt":
+ case "eth_storageAt":
args := msg.Arguments()
- c.Write(pipe.StorageAt(args.Get(0).Str(), args.Get(1).Str()), msg.Seed)
+ c.Write(pipe.StorageAt(args.Get(0).Str(), args.Get(1).Str()), msg.Id)
- case "getBalanceAt":
+ case "eth_balanceAt":
args := msg.Arguments()
- c.Write(pipe.BalanceAt(args.Get(0).Str()), msg.Seed)
+ c.Write(pipe.BalanceAt(args.Get(0).Str()), msg.Id)
- case "getSecretToAddress":
+ case "eth_secretToAddress":
args := msg.Arguments()
- c.Write(pipe.SecretToAddress(args.Get(0).Str()), msg.Seed)
+ c.Write(pipe.SecretToAddress(args.Get(0).Str()), msg.Id)
- case "newFilter":
- case "newFilterString":
- case "messages":
+ case "eth_newFilter":
+ case "eth_newFilterString":
+ case "eth_messages":
// TODO
}
diff --git a/websocket/client.go b/websocket/client.go
index d961816e8..db2c8e5c9 100644
--- a/websocket/client.go
+++ b/websocket/client.go
@@ -50,8 +50,8 @@ func (c *Client) Conn() *ws.Conn {
return c.ws
}
-func (c *Client) Write(data interface{}, seed int) {
- msg := &Message{Seed: seed, Data: data}
+func (c *Client) Write(data interface{}, id int) {
+ msg := &Message{Id: id, Data: data}
select {
case c.ch <- msg:
default:
@@ -73,7 +73,6 @@ func (c *Client) Listen() {
// Listen write request via chanel
func (c *Client) listenWrite() {
- wslogger.Debugln("Listening write to client")
for {
select {
@@ -93,7 +92,6 @@ func (c *Client) listenWrite() {
// Listen read request via chanel
func (c *Client) listenRead() {
- wslogger.Debugln("Listening read from client")
for {
select {
diff --git a/websocket/message.go b/websocket/message.go
index 67289c4c4..73b47456f 100644
--- a/websocket/message.go
+++ b/websocket/message.go
@@ -5,7 +5,7 @@ import "github.com/ethereum/go-ethereum/ethutil"
type Message struct {
Call string `json:"call"`
Args []interface{} `json:"args"`
- Seed int `json:"seed"`
+ Id int `json:"_id"`
Data interface{} `json:"data"`
}
diff --git a/websocket/server.go b/websocket/server.go
index 5fd923a0c..b0658b1b4 100644
--- a/websocket/server.go
+++ b/websocket/server.go
@@ -81,8 +81,6 @@ func (s *Server) MessageFunc(f MsgFunc) {
// Listen and serve.
// It serves client connection and broadcast request.
func (s *Server) Listen() {
- wslogger.Debugln("Listening server...")
-
// ws handler
onConnected := func(ws *ws.Conn) {
defer func() {