Esempio n. 1
0
// Attach connects to the running node's IPC exposed APIs, and returns an Go API
// interface.
func (g *Geth) Attach() (*API, error) {
	client, err := rpc.NewIPCClient(g.ipcEndpoint)
	if err != nil {
		return nil, err
	}
	return &API{client: client}, nil
}
Esempio n. 2
0
// NewRemoteRPCClient returns a RPC client which connects to a running geth instance.
// Depending on the given context this can either be a IPC or a HTTP client.
func NewRemoteRPCClient(ctx *cli.Context) (rpc.Client, error) {
	if ctx.Args().Present() {
		endpoint := ctx.Args().First()
		return NewRemoteRPCClientFromString(endpoint)
	}

	// use IPC by default
	endpoint := IPCSocketPath(ctx)
	return rpc.NewIPCClient(endpoint)
}
Esempio n. 3
0
// NewRemoteRPCClientFromString returns a RPC client which connects to the given
// endpoint. It must start with either `ipc:` or `rpc:` (HTTP).
func NewRemoteRPCClientFromString(endpoint string) (rpc.Client, error) {
	if strings.HasPrefix(endpoint, "ipc:") {
		return rpc.NewIPCClient(endpoint[4:])
	}
	if strings.HasPrefix(endpoint, "rpc:") {
		return rpc.NewHTTPClient(endpoint[4:])
	}
	if strings.HasPrefix(endpoint, "http://") {
		return rpc.NewHTTPClient(endpoint)
	}
	if strings.HasPrefix(endpoint, "ws:") {
		return rpc.NewWSClient(endpoint)
	}

	return nil, fmt.Errorf("invalid endpoint")
}