startRPC is a helper method to start all the various RPC endpoint during node startup. It's not meant to be called at any time afterwards as it makes certain assumptions about the state of the node.
(services map[reflect.Type]Service)
| 235 | // startup. It's not meant to be called at any time afterwards as it makes certain |
| 236 | // assumptions about the state of the node. |
| 237 | func (n *Node) startRPC(services map[reflect.Type]Service) error { |
| 238 | // Gather all the possible APIs to surface |
| 239 | apis := n.apis() |
| 240 | for _, service := range services { |
| 241 | apis = append(apis, service.APIs()...) |
| 242 | } |
| 243 | // Start the various API endpoints, terminating all in case of errors |
| 244 | if err := n.startInProc(apis); err != nil { |
| 245 | return err |
| 246 | } |
| 247 | if err := n.startIPC(apis); err != nil { |
| 248 | n.stopInProc() |
| 249 | return err |
| 250 | } |
| 251 | if err := n.startHTTP(n.httpEndpoint, apis, n.config.HTTPModules, n.config.HTTPCors, n.config.HTTPVirtualHosts); err != nil { |
| 252 | n.stopIPC() |
| 253 | n.stopInProc() |
| 254 | return err |
| 255 | } |
| 256 | if err := n.startWS(n.wsEndpoint, apis, n.config.WSModules, n.config.WSOrigins, n.config.WSExposeAll); err != nil { |
| 257 | n.stopHTTP() |
| 258 | n.stopIPC() |
| 259 | n.stopInProc() |
| 260 | return err |
| 261 | } |
| 262 | // All API endpoints started successfully |
| 263 | n.rpcAPIs = apis |
| 264 | return nil |
| 265 | } |
| 266 | |
| 267 | func (n *Node) stopRPC() { |
| 268 | n.stopWS() |
no test coverage detected