prysm-pulse/sharding/client.go
Preston Van Loon 50e92a018e add test boilerplate for sharding client
Former-commit-id: 7cbd81db9421e1517ad92829a2dbbdfcf5f38699 [formerly 76607161435699e18a970c82f9838d20e94f04d7]
Former-commit-id: f6db97246aa70eda35e59a2a05fa55316289bd76
2018-01-14 21:59:51 -05:00

59 lines
1.1 KiB
Go

package sharding
import (
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/rpc"
cli "gopkg.in/urfave/cli.v1"
)
const (
// TODO: Can this be referenced from main.clientIdentifier?
clientIdentifier = "geth" // Client identifier to advertise over the network
)
type Client struct {
endpoint string
client *rpc.Client
}
func MakeShardingClient(ctx *cli.Context) *Client {
endpoint := ""
if ctx.GlobalIsSet(utils.DataDirFlag.Name) {
endpoint = ctx.GlobalString(utils.DataDirFlag.Name)
}
return &Client{
endpoint: endpoint,
}
}
func (c *Client) Start() error {
log.Info("Starting sharding client")
rpcClient, err := dialRPC(c.endpoint)
if err != nil {
return err
}
c.client = rpcClient
defer c.client.Close()
if err := c.verifyVMC(); err != nil {
return err
}
// TODO: Wait to be selected?
return nil
}
func (c *Client) Wait() {
// TODO: Blocking lock
}
func dialRPC(endpoint string) (*rpc.Client, error) {
if endpoint == "" {
endpoint = node.DefaultIPCEndpoint(clientIdentifier)
}
return rpc.Dial(endpoint)
}