StartRPC starts the HTTP RPC API server.
(host *string, port *int, cors *string, apis *string, vhosts *string)
| 102 | |
| 103 | // StartRPC starts the HTTP RPC API server. |
| 104 | func (api *PrivateAdminAPI) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error) { |
| 105 | api.node.lock.Lock() |
| 106 | defer api.node.lock.Unlock() |
| 107 | |
| 108 | if api.node.httpHandler != nil { |
| 109 | return false, fmt.Errorf("HTTP RPC already running on %s", api.node.httpEndpoint) |
| 110 | } |
| 111 | |
| 112 | if host == nil { |
| 113 | h := DefaultHTTPHost |
| 114 | if api.node.config.HTTPHost != "" { |
| 115 | h = api.node.config.HTTPHost |
| 116 | } |
| 117 | host = &h |
| 118 | } |
| 119 | if port == nil { |
| 120 | port = &api.node.config.HTTPPort |
| 121 | } |
| 122 | |
| 123 | allowedOrigins := api.node.config.HTTPCors |
| 124 | if cors != nil { |
| 125 | allowedOrigins = nil |
| 126 | for _, origin := range strings.Split(*cors, ",") { |
| 127 | allowedOrigins = append(allowedOrigins, strings.TrimSpace(origin)) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | allowedVHosts := api.node.config.HTTPVirtualHosts |
| 132 | if vhosts != nil { |
| 133 | allowedVHosts = nil |
| 134 | for _, vhost := range strings.Split(*host, ",") { |
| 135 | allowedVHosts = append(allowedVHosts, strings.TrimSpace(vhost)) |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | modules := api.node.httpWhitelist |
| 140 | if apis != nil { |
| 141 | modules = nil |
| 142 | for _, m := range strings.Split(*apis, ",") { |
| 143 | modules = append(modules, strings.TrimSpace(m)) |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | if err := api.node.startHTTP(fmt.Sprintf("%s:%d", *host, *port), api.node.rpcAPIs, modules, allowedOrigins, allowedVHosts); err != nil { |
| 148 | return false, err |
| 149 | } |
| 150 | return true, nil |
| 151 | } |
| 152 | |
| 153 | // StopRPC terminates an already running HTTP RPC API endpoint. |
| 154 | func (api *PrivateAdminAPI) StopRPC() (bool, error) { |