prysm-pulse/sharding/client.go
Preston Van Loon 7e09ed395b contract deploy somewhat working
Former-commit-id: 2bccce337d29f12b7a96d5d79be6528c1ddfe6e6 [formerly 853da49db264a445f955c21294909909c59b56f7]
Former-commit-id: d67aece06f67fc24d0a7036646ded876218ce84f
2018-01-15 16:39:00 -05:00

73 lines
1.6 KiB
Go

package sharding
import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/ethclient"
"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 *ethclient.Client
keystore *keystore.KeyStore // Keystore containing the single signer
}
func MakeShardingClient(ctx *cli.Context) *Client {
endpoint := ""
if ctx.GlobalIsSet(utils.DataDirFlag.Name) {
endpoint = ctx.GlobalString(utils.DataDirFlag.Name)
}
config := &node.Config{
DataDir: "/tmp/ethereum",
}
scryptN, scryptP, keydir, err := config.AccountConfig()
if err != nil {
panic(err) // TODO: handle this
}
ks := keystore.NewKeyStore(keydir, scryptN, scryptP)
return &Client{
endpoint: endpoint,
keystore: ks,
}
}
func (c *Client) Start() error {
log.Info("Starting sharding client")
rpcClient, err := dialRPC(c.endpoint)
if err != nil {
return err
}
c.client = ethclient.NewClient(rpcClient)
defer rpcClient.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)
}