aboutsummaryrefslogtreecommitdiffstats
path: root/node/api.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-04-12 20:03:21 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2016-04-12 20:03:21 +0800
commit8627680e24a29abd5f2aaaeaa2c1c852d8fb693b (patch)
tree1ad39e8b43d04e5a17c17c0b7314eece80620dd5 /node/api.go
parent934f587bd5c38a36e8b8c8647a9e600d1751ff2f (diff)
parentaa9fff3e68b1def0a9a22009c233150bf9ba481f (diff)
downloaddexon-8627680e24a29abd5f2aaaeaa2c1c852d8fb693b.tar
dexon-8627680e24a29abd5f2aaaeaa2c1c852d8fb693b.tar.gz
dexon-8627680e24a29abd5f2aaaeaa2c1c852d8fb693b.tar.bz2
dexon-8627680e24a29abd5f2aaaeaa2c1c852d8fb693b.tar.lz
dexon-8627680e24a29abd5f2aaaeaa2c1c852d8fb693b.tar.xz
dexon-8627680e24a29abd5f2aaaeaa2c1c852d8fb693b.tar.zst
dexon-8627680e24a29abd5f2aaaeaa2c1c852d8fb693b.zip
Merge pull request #2359 from bas-vk/rpc-optional-args
rpc: several fixes and support for optional arguments
Diffstat (limited to 'node/api.go')
-rw-r--r--node/api.go47
1 files changed, 43 insertions, 4 deletions
diff --git a/node/api.go b/node/api.go
index 8a2578410..f199a8d3d 100644
--- a/node/api.go
+++ b/node/api.go
@@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover"
+ "github.com/ethereum/go-ethereum/rpc"
"github.com/rcrowley/go-metrics"
)
@@ -58,14 +59,33 @@ func (api *PrivateAdminAPI) AddPeer(url string) (bool, error) {
}
// StartRPC starts the HTTP RPC API server.
-func (api *PrivateAdminAPI) StartRPC(host string, port int, cors string, apis string) (bool, error) {
+func (api *PrivateAdminAPI) StartRPC(host *string, port *rpc.HexNumber, cors *string, apis *string) (bool, error) {
api.node.lock.Lock()
defer api.node.lock.Unlock()
if api.node.httpHandler != nil {
return false, fmt.Errorf("HTTP RPC already running on %s", api.node.httpEndpoint)
}
- if err := api.node.startHTTP(fmt.Sprintf("%s:%d", host, port), api.node.rpcAPIs, strings.Split(apis, ","), cors); err != nil {
+
+ if host == nil {
+ host = &api.node.httpHost
+ }
+ if port == nil {
+ port = rpc.NewHexNumber(api.node.httpPort)
+ }
+ if cors == nil {
+ cors = &api.node.httpCors
+ }
+
+ modules := api.node.httpWhitelist
+ if apis != nil {
+ modules = nil
+ for _, m := range strings.Split(*apis, ",") {
+ modules = append(modules, strings.TrimSpace(m))
+ }
+ }
+
+ if err := api.node.startHTTP(fmt.Sprintf("%s:%d", *host, port.Int()), api.node.rpcAPIs, modules, *cors); err != nil {
return false, err
}
return true, nil
@@ -84,14 +104,33 @@ func (api *PrivateAdminAPI) StopRPC() (bool, error) {
}
// StartWS starts the websocket RPC API server.
-func (api *PrivateAdminAPI) StartWS(host string, port int, cors string, apis string) (bool, error) {
+func (api *PrivateAdminAPI) StartWS(host *string, port *rpc.HexNumber, allowedOrigins *string, apis *string) (bool, error) {
api.node.lock.Lock()
defer api.node.lock.Unlock()
if api.node.wsHandler != nil {
return false, fmt.Errorf("WebSocket RPC already running on %s", api.node.wsEndpoint)
}
- if err := api.node.startWS(fmt.Sprintf("%s:%d", host, port), api.node.rpcAPIs, strings.Split(apis, ","), cors); err != nil {
+
+ if host == nil {
+ host = &api.node.wsHost
+ }
+ if port == nil {
+ port = rpc.NewHexNumber(api.node.wsPort)
+ }
+ if allowedOrigins == nil {
+ allowedOrigins = &api.node.wsOrigins
+ }
+
+ modules := api.node.wsWhitelist
+ if apis != nil {
+ modules = nil
+ for _, m := range strings.Split(*apis, ",") {
+ modules = append(modules, strings.TrimSpace(m))
+ }
+ }
+
+ if err := api.node.startWS(fmt.Sprintf("%s:%d", *host, port.Int()), api.node.rpcAPIs, modules, *allowedOrigins); err != nil {
return false, err
}
return true, nil