2015-06-08 03:41:04 -05:00
|
|
|
package comms
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/rpc/api"
|
|
|
|
"github.com/ethereum/go-ethereum/rpc/codec"
|
|
|
|
)
|
|
|
|
|
|
|
|
type IpcConfig struct {
|
|
|
|
Endpoint string
|
|
|
|
}
|
|
|
|
|
|
|
|
type ipcClient struct {
|
2015-06-17 09:22:35 -05:00
|
|
|
codec codec.ApiCoder
|
2015-06-08 03:41:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *ipcClient) Close() {
|
2015-06-17 09:22:35 -05:00
|
|
|
self.codec.Close()
|
2015-06-08 03:41:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *ipcClient) Send(req interface{}) error {
|
2015-06-17 09:22:35 -05:00
|
|
|
return self.codec.WriteResponse(req)
|
2015-06-08 03:41:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *ipcClient) Recv() (interface{}, error) {
|
2015-06-17 09:22:35 -05:00
|
|
|
return self.codec.ReadResponse()
|
2015-06-08 03:41:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new IPC client, UNIX domain socket on posix, named pipe on Windows
|
|
|
|
func NewIpcClient(cfg IpcConfig, codec codec.Codec) (*ipcClient, error) {
|
|
|
|
return newIpcClient(cfg, codec)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start IPC server
|
|
|
|
func StartIpc(cfg IpcConfig, codec codec.Codec, apis ...api.EthereumApi) error {
|
|
|
|
offeredApi := api.Merge(apis...)
|
|
|
|
return startIpc(cfg, codec, offeredApi)
|
|
|
|
}
|