@@ -11,6 +11,7 @@ import (
11
11
"github.com/ethereum/go-ethereum/logger/glog"
12
12
"github.com/ethereum/go-ethereum/rlp"
13
13
"github.com/ethereum/go-ethereum/rpc/codec"
14
+ "github.com/ethereum/go-ethereum/rpc/comms"
14
15
"github.com/ethereum/go-ethereum/rpc/shared"
15
16
"github.com/ethereum/go-ethereum/xeth"
16
17
)
32
33
"admin_chainSyncStatus" : (* adminApi ).ChainSyncStatus ,
33
34
"admin_setSolc" : (* adminApi ).SetSolc ,
34
35
"admin_datadir" : (* adminApi ).DataDir ,
36
+ "admin_startRPC" : (* adminApi ).StartRPC ,
37
+ "admin_stopRPC" : (* adminApi ).StopRPC ,
35
38
}
36
39
)
37
40
@@ -42,25 +45,25 @@ type adminhandler func(*adminApi, *shared.Request) (interface{}, error)
42
45
type adminApi struct {
43
46
xeth * xeth.XEth
44
47
ethereum * eth.Ethereum
45
- methods map [ string ] adminhandler
46
- codec codec.ApiCoder
48
+ codec codec. Codec
49
+ coder codec.ApiCoder
47
50
}
48
51
49
52
// create a new admin api instance
50
- func NewAdminApi (xeth * xeth.XEth , ethereum * eth.Ethereum , coder codec.Codec ) * adminApi {
53
+ func NewAdminApi (xeth * xeth.XEth , ethereum * eth.Ethereum , codec codec.Codec ) * adminApi {
51
54
return & adminApi {
52
55
xeth : xeth ,
53
56
ethereum : ethereum ,
54
- methods : AdminMapping ,
55
- codec : coder .New (nil ),
57
+ codec : codec ,
58
+ coder : codec .New (nil ),
56
59
}
57
60
}
58
61
59
62
// collection with supported methods
60
63
func (self * adminApi ) Methods () []string {
61
- methods := make ([]string , len (self . methods ))
64
+ methods := make ([]string , len (AdminMapping ))
62
65
i := 0
63
- for k := range self . methods {
66
+ for k := range AdminMapping {
64
67
methods [i ] = k
65
68
i ++
66
69
}
@@ -69,15 +72,15 @@ func (self *adminApi) Methods() []string {
69
72
70
73
// Execute given request
71
74
func (self * adminApi ) Execute (req * shared.Request ) (interface {}, error ) {
72
- if callback , ok := self . methods [req .Method ]; ok {
75
+ if callback , ok := AdminMapping [req .Method ]; ok {
73
76
return callback (self , req )
74
77
}
75
78
76
79
return nil , & shared.NotImplementedError {req .Method }
77
80
}
78
81
79
82
func (self * adminApi ) Name () string {
80
- return AdminApiName
83
+ return shared . AdminApiName
81
84
}
82
85
83
86
func (self * adminApi ) ApiVersion () string {
@@ -86,7 +89,7 @@ func (self *adminApi) ApiVersion() string {
86
89
87
90
func (self * adminApi ) AddPeer (req * shared.Request ) (interface {}, error ) {
88
91
args := new (AddPeerArgs )
89
- if err := self .codec .Decode (req .Params , & args ); err != nil {
92
+ if err := self .coder .Decode (req .Params , & args ); err != nil {
90
93
return nil , shared .NewDecodeParamError (err .Error ())
91
94
}
92
95
@@ -120,7 +123,7 @@ func hasAllBlocks(chain *core.ChainManager, bs []*types.Block) bool {
120
123
121
124
func (self * adminApi ) ImportChain (req * shared.Request ) (interface {}, error ) {
122
125
args := new (ImportExportChainArgs )
123
- if err := self .codec .Decode (req .Params , & args ); err != nil {
126
+ if err := self .coder .Decode (req .Params , & args ); err != nil {
124
127
return nil , shared .NewDecodeParamError (err .Error ())
125
128
}
126
129
@@ -163,7 +166,7 @@ func (self *adminApi) ImportChain(req *shared.Request) (interface{}, error) {
163
166
164
167
func (self * adminApi ) ExportChain (req * shared.Request ) (interface {}, error ) {
165
168
args := new (ImportExportChainArgs )
166
- if err := self .codec .Decode (req .Params , & args ); err != nil {
169
+ if err := self .coder .Decode (req .Params , & args ); err != nil {
167
170
return nil , shared .NewDecodeParamError (err .Error ())
168
171
}
169
172
@@ -181,7 +184,7 @@ func (self *adminApi) ExportChain(req *shared.Request) (interface{}, error) {
181
184
182
185
func (self * adminApi ) Verbosity (req * shared.Request ) (interface {}, error ) {
183
186
args := new (VerbosityArgs )
184
- if err := self .codec .Decode (req .Params , & args ); err != nil {
187
+ if err := self .coder .Decode (req .Params , & args ); err != nil {
185
188
return nil , shared .NewDecodeParamError (err .Error ())
186
189
}
187
190
@@ -202,7 +205,7 @@ func (self *adminApi) ChainSyncStatus(req *shared.Request) (interface{}, error)
202
205
203
206
func (self * adminApi ) SetSolc (req * shared.Request ) (interface {}, error ) {
204
207
args := new (SetSolcArgs )
205
- if err := self .codec .Decode (req .Params , & args ); err != nil {
208
+ if err := self .coder .Decode (req .Params , & args ); err != nil {
206
209
return nil , shared .NewDecodeParamError (err .Error ())
207
210
}
208
211
@@ -212,3 +215,32 @@ func (self *adminApi) SetSolc(req *shared.Request) (interface{}, error) {
212
215
}
213
216
return solc .Info (), nil
214
217
}
218
+
219
+ func (self * adminApi ) StartRPC (req * shared.Request ) (interface {}, error ) {
220
+ var err error
221
+ args := new (StartRPCArgs )
222
+ if err := self .coder .Decode (req .Params , & args ); err != nil {
223
+ return nil , shared .NewDecodeParamError (err .Error ())
224
+ }
225
+
226
+ cfg := comms.HttpConfig {
227
+ ListenAddress : args .ListenAddress ,
228
+ ListenPort : args .ListenPort ,
229
+ CorsDomain : args .CorsDomain ,
230
+ }
231
+
232
+ if apis , err := ParseApiString (args .Apis , self .codec , self .xeth , self .ethereum ); err == nil {
233
+ err = comms .StartHttp (cfg , self .codec , Merge (apis ... ))
234
+ }
235
+
236
+ if err == nil {
237
+ return true , nil
238
+ }
239
+
240
+ return false , err
241
+ }
242
+
243
+ func (self * adminApi ) StopRPC (req * shared.Request ) (interface {}, error ) {
244
+ comms .StopHttp ()
245
+ return true , nil
246
+ }
0 commit comments