aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'rpc')
-rw-r--r--rpc/http/server.go6
-rw-r--r--rpc/packages.go43
-rw-r--r--rpc/ws/server.go2
3 files changed, 24 insertions, 27 deletions
diff --git a/rpc/http/server.go b/rpc/http/server.go
index 93b52a634..965727a4e 100644
--- a/rpc/http/server.go
+++ b/rpc/http/server.go
@@ -29,7 +29,7 @@ import (
var rpchttplogger = logger.NewLogger("RPC-HTTP")
var JSON rpc.JsonWrapper
-func NewRpcHttpServer(pipe *xeth.JSXEth, port int) (*RpcHttpServer, error) {
+func NewRpcHttpServer(pipe *xeth.XEth, port int) (*RpcHttpServer, error) {
sport := fmt.Sprintf(":%d", port)
l, err := net.Listen("tcp", sport)
if err != nil {
@@ -47,7 +47,7 @@ func NewRpcHttpServer(pipe *xeth.JSXEth, port int) (*RpcHttpServer, error) {
type RpcHttpServer struct {
quit chan bool
listener net.Listener
- pipe *xeth.JSXEth
+ pipe *xeth.XEth
port int
}
@@ -85,6 +85,8 @@ func (s *RpcHttpServer) Start() {
func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
fn := func(w http.ResponseWriter, req *http.Request) {
+ w.Header().Set("Access-Control-Allow-Origin", "*")
+
rpchttplogger.Debugln("Handling request")
reqParsed, reqerr := JSON.ParseRequestBody(req)
diff --git a/rpc/packages.go b/rpc/packages.go
index 8b5965069..700b9b2b3 100644
--- a/rpc/packages.go
+++ b/rpc/packages.go
@@ -19,8 +19,8 @@
For each request type, define the following:
1. RpcRequest "To" method [message.go], which does basic validation and conversion to "Args" type via json.Decoder()
-2. json.Decoder() calls "UnmarshalJSON" defined on each "Args" struct
-3. EthereumApi method, taking the "Args" type and replying with an interface to be marshalled to JSON
+2. json.Decoder() calls "UnmarshalON" defined on each "Args" struct
+3. EthereumApi method, taking the "Args" type and replying with an interface to be marshalled to ON
*/
package rpc
@@ -38,12 +38,12 @@ type RpcServer interface {
Stop()
}
-func NewEthereumApi(xeth *xeth.JSXEth) *EthereumApi {
- return &EthereumApi{pipe: xeth}
+func NewEthereumApi(xeth *xeth.XEth) *EthereumApi {
+ return &EthereumApi{xeth: xeth}
}
type EthereumApi struct {
- pipe *xeth.JSXEth
+ xeth *xeth.XEth
}
func (p *EthereumApi) GetBlock(args *GetBlockArgs, reply *interface{}) error {
@@ -53,9 +53,9 @@ func (p *EthereumApi) GetBlock(args *GetBlockArgs, reply *interface{}) error {
}
if args.BlockNumber > 0 {
- *reply = p.pipe.BlockByNumber(args.BlockNumber)
+ *reply = p.xeth.BlockByNumber(args.BlockNumber)
} else {
- *reply = p.pipe.BlockByHash(args.Hash)
+ *reply = p.xeth.BlockByHash(args.Hash)
}
return nil
}
@@ -65,7 +65,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) error {
if err != nil {
return err
}
- result, _ := p.pipe.Transact(p.pipe.Key().PrivateKey, args.Recipient, args.Value, args.Gas, args.GasPrice, args.Body)
+ result, _ := p.xeth.Transact( /* TODO specify account */ "", args.Recipient, args.Value, args.Gas, args.GasPrice, args.Body)
*reply = result
return nil
}
@@ -76,7 +76,7 @@ func (p *EthereumApi) Create(args *NewTxArgs, reply *interface{}) error {
return err
}
- result, _ := p.pipe.Transact(p.pipe.Key().PrivateKey, "", args.Value, args.Gas, args.GasPrice, args.Body)
+ result, _ := p.xeth.Transact( /* TODO specify account */ "", "", args.Value, args.Gas, args.GasPrice, args.Body)
*reply = result
return nil
}
@@ -86,23 +86,18 @@ func (p *EthereumApi) PushTx(args *PushTxArgs, reply *interface{}) error {
if err != nil {
return err
}
- result, _ := p.pipe.PushTx(args.Tx)
+ result, _ := p.xeth.PushTx(args.Tx)
*reply = result
return nil
}
-func (p *EthereumApi) GetKey(args interface{}, reply *interface{}) error {
- *reply = p.pipe.Key()
- return nil
-}
-
func (p *EthereumApi) GetStorageAt(args *GetStorageArgs, reply *interface{}) error {
err := args.requirements()
if err != nil {
return err
}
- state := p.pipe.World().SafeGet(ethutil.Hex2Bytes(args.Address))
+ state := p.xeth.State().SafeGet(args.Address)
var hx string
if strings.Index(args.Key, "0x") == 0 {
@@ -119,22 +114,22 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageArgs, reply *interface{}) err
}
func (p *EthereumApi) GetPeerCount(reply *interface{}) error {
- *reply = p.pipe.PeerCount()
+ *reply = p.xeth.PeerCount()
return nil
}
func (p *EthereumApi) GetIsListening(reply *interface{}) error {
- *reply = p.pipe.IsListening()
+ *reply = p.xeth.IsListening()
return nil
}
func (p *EthereumApi) GetCoinbase(reply *interface{}) error {
- *reply = p.pipe.CoinBase()
+ *reply = p.xeth.Coinbase()
return nil
}
func (p *EthereumApi) GetIsMining(reply *interface{}) error {
- *reply = p.pipe.IsMining()
+ *reply = p.xeth.IsMining()
return nil
}
@@ -143,7 +138,7 @@ func (p *EthereumApi) GetTxCountAt(args *GetTxCountArgs, reply *interface{}) err
if err != nil {
return err
}
- *reply = p.pipe.TxCountAt(args.Address)
+ *reply = p.xeth.TxCountAt(args.Address)
return nil
}
@@ -152,7 +147,7 @@ func (p *EthereumApi) GetBalanceAt(args *GetBalanceArgs, reply *interface{}) err
if err != nil {
return err
}
- state := p.pipe.World().SafeGet(ethutil.Hex2Bytes(args.Address))
+ state := p.xeth.State().SafeGet(args.Address)
*reply = BalanceRes{Balance: state.Balance().String(), Address: args.Address}
return nil
}
@@ -162,12 +157,12 @@ func (p *EthereumApi) GetCodeAt(args *GetCodeAtArgs, reply *interface{}) error {
if err != nil {
return err
}
- *reply = p.pipe.CodeAt(args.Address)
+ *reply = p.xeth.CodeAt(args.Address)
return nil
}
func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error {
- // Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC
+ // Spec at https://github.com/ethereum/wiki/wiki/Generic-ON-RPC
rpclogger.DebugDetailf("%T %s", req.Params, req.Params)
switch req.Method {
case "eth_coinbase":
diff --git a/rpc/ws/server.go b/rpc/ws/server.go
index e2b918430..2efc6ff02 100644
--- a/rpc/ws/server.go
+++ b/rpc/ws/server.go
@@ -76,7 +76,7 @@ func (self *WebSocketServer) Start() {
wslogger.Infof("Starting RPC-WS server on port %d", self.port)
go self.handlerLoop()
- api := rpc.NewEthereumApi(xeth.NewJSXEth(self.eth))
+ api := rpc.NewEthereumApi(xeth.New(self.eth))
h := self.apiHandler(api)
http.Handle("/ws", h)