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