aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api/admin.go
diff options
context:
space:
mode:
authorBas van Kervel <bas@ethdev.com>2015-06-22 18:47:32 +0800
committerBas van Kervel <bas@ethdev.com>2015-06-22 18:47:32 +0800
commit2e0b56a72b3eafc89938003da29c06496ac9ad4e (patch)
treeeba3eb3a822da0ba7de98d9c7b6dc8601a63db0a /rpc/api/admin.go
parent2737baa6577a337f33f020d587af100c9bda3585 (diff)
downloadgo-tangerine-2e0b56a72b3eafc89938003da29c06496ac9ad4e.tar
go-tangerine-2e0b56a72b3eafc89938003da29c06496ac9ad4e.tar.gz
go-tangerine-2e0b56a72b3eafc89938003da29c06496ac9ad4e.tar.bz2
go-tangerine-2e0b56a72b3eafc89938003da29c06496ac9ad4e.tar.lz
go-tangerine-2e0b56a72b3eafc89938003da29c06496ac9ad4e.tar.xz
go-tangerine-2e0b56a72b3eafc89938003da29c06496ac9ad4e.tar.zst
go-tangerine-2e0b56a72b3eafc89938003da29c06496ac9ad4e.zip
added RPC start/stop support
Diffstat (limited to 'rpc/api/admin.go')
-rw-r--r--rpc/api/admin.go60
1 files changed, 46 insertions, 14 deletions
diff --git a/rpc/api/admin.go b/rpc/api/admin.go
index 368375c93..7e79fd4d0 100644
--- a/rpc/api/admin.go
+++ b/rpc/api/admin.go
@@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc/codec"
+ "github.com/ethereum/go-ethereum/rpc/comms"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/xeth"
)
@@ -32,6 +33,8 @@ var (
"admin_chainSyncStatus": (*adminApi).ChainSyncStatus,
"admin_setSolc": (*adminApi).SetSolc,
"admin_datadir": (*adminApi).DataDir,
+ "admin_startRPC": (*adminApi).StartRPC,
+ "admin_stopRPC": (*adminApi).StopRPC,
}
)
@@ -42,25 +45,25 @@ type adminhandler func(*adminApi, *shared.Request) (interface{}, error)
type adminApi struct {
xeth *xeth.XEth
ethereum *eth.Ethereum
- methods map[string]adminhandler
- codec codec.ApiCoder
+ codec codec.Codec
+ coder codec.ApiCoder
}
// create a new admin api instance
-func NewAdminApi(xeth *xeth.XEth, ethereum *eth.Ethereum, coder codec.Codec) *adminApi {
+func NewAdminApi(xeth *xeth.XEth, ethereum *eth.Ethereum, codec codec.Codec) *adminApi {
return &adminApi{
xeth: xeth,
ethereum: ethereum,
- methods: AdminMapping,
- codec: coder.New(nil),
+ codec: codec,
+ coder: codec.New(nil),
}
}
// collection with supported methods
func (self *adminApi) Methods() []string {
- methods := make([]string, len(self.methods))
+ methods := make([]string, len(AdminMapping))
i := 0
- for k := range self.methods {
+ for k := range AdminMapping {
methods[i] = k
i++
}
@@ -69,7 +72,7 @@ func (self *adminApi) Methods() []string {
// Execute given request
func (self *adminApi) Execute(req *shared.Request) (interface{}, error) {
- if callback, ok := self.methods[req.Method]; ok {
+ if callback, ok := AdminMapping[req.Method]; ok {
return callback(self, req)
}
@@ -77,7 +80,7 @@ func (self *adminApi) Execute(req *shared.Request) (interface{}, error) {
}
func (self *adminApi) Name() string {
- return AdminApiName
+ return shared.AdminApiName
}
func (self *adminApi) ApiVersion() string {
@@ -86,7 +89,7 @@ func (self *adminApi) ApiVersion() string {
func (self *adminApi) AddPeer(req *shared.Request) (interface{}, error) {
args := new(AddPeerArgs)
- if err := self.codec.Decode(req.Params, &args); err != nil {
+ if err := self.coder.Decode(req.Params, &args); err != nil {
return nil, shared.NewDecodeParamError(err.Error())
}
@@ -120,7 +123,7 @@ func hasAllBlocks(chain *core.ChainManager, bs []*types.Block) bool {
func (self *adminApi) ImportChain(req *shared.Request) (interface{}, error) {
args := new(ImportExportChainArgs)
- if err := self.codec.Decode(req.Params, &args); err != nil {
+ if err := self.coder.Decode(req.Params, &args); err != nil {
return nil, shared.NewDecodeParamError(err.Error())
}
@@ -163,7 +166,7 @@ func (self *adminApi) ImportChain(req *shared.Request) (interface{}, error) {
func (self *adminApi) ExportChain(req *shared.Request) (interface{}, error) {
args := new(ImportExportChainArgs)
- if err := self.codec.Decode(req.Params, &args); err != nil {
+ if err := self.coder.Decode(req.Params, &args); err != nil {
return nil, shared.NewDecodeParamError(err.Error())
}
@@ -181,7 +184,7 @@ func (self *adminApi) ExportChain(req *shared.Request) (interface{}, error) {
func (self *adminApi) Verbosity(req *shared.Request) (interface{}, error) {
args := new(VerbosityArgs)
- if err := self.codec.Decode(req.Params, &args); err != nil {
+ if err := self.coder.Decode(req.Params, &args); err != nil {
return nil, shared.NewDecodeParamError(err.Error())
}
@@ -202,7 +205,7 @@ func (self *adminApi) ChainSyncStatus(req *shared.Request) (interface{}, error)
func (self *adminApi) SetSolc(req *shared.Request) (interface{}, error) {
args := new(SetSolcArgs)
- if err := self.codec.Decode(req.Params, &args); err != nil {
+ if err := self.coder.Decode(req.Params, &args); err != nil {
return nil, shared.NewDecodeParamError(err.Error())
}
@@ -212,3 +215,32 @@ func (self *adminApi) SetSolc(req *shared.Request) (interface{}, error) {
}
return solc.Info(), nil
}
+
+func (self *adminApi) StartRPC(req *shared.Request) (interface{}, error) {
+ var err error
+ args := new(StartRPCArgs)
+ if err := self.coder.Decode(req.Params, &args); err != nil {
+ return nil, shared.NewDecodeParamError(err.Error())
+ }
+
+ cfg := comms.HttpConfig{
+ ListenAddress: args.ListenAddress,
+ ListenPort: args.ListenPort,
+ CorsDomain: args.CorsDomain,
+ }
+
+ if apis, err := ParseApiString(args.Apis, self.codec, self.xeth, self.ethereum); err == nil {
+ err = comms.StartHttp(cfg, self.codec, Merge(apis...))
+ }
+
+ if err == nil {
+ return true, nil
+ }
+
+ return false, err
+}
+
+func (self *adminApi) StopRPC(req *shared.Request) (interface{}, error) {
+ comms.StopHttp()
+ return true, nil
+}