mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 11:32:09 +00:00
cleanup / move methods
Former-commit-id: a3948262d6acc24f0f49c245593ab1cf10bb2962 [formerly a0d5b9186ba4faa89c7dc4bdcd8ad949f641ad1b] Former-commit-id: 0635e28b194fa4de6b7bcdb819a524ebe44f2d9c
This commit is contained in:
parent
167cdf7914
commit
4a89464c91
@ -13,8 +13,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// TODO(prestonvanloon): Can this be referenced from main.clientIdentifier?
|
||||
clientIdentifier = "geth" // Client identifier to advertise over the network
|
||||
clientIdentifier = "geth" // Used to determine the ipc name.
|
||||
)
|
||||
|
||||
// Client for sharding. Communicates to geth node via JSON RPC.
|
||||
@ -32,7 +31,7 @@ func MakeShardingClient(ctx *cli.Context) *Client {
|
||||
if ctx.GlobalIsSet(utils.DataDirFlag.Name) {
|
||||
path = ctx.GlobalString(utils.DataDirFlag.Name)
|
||||
}
|
||||
endpoint := fmt.Sprintf("%s/geth.ipc", path)
|
||||
endpoint := fmt.Sprintf("%s/%s.ipc", path, clientIdentifier)
|
||||
|
||||
config := &node.Config{
|
||||
DataDir: path,
|
||||
@ -58,7 +57,7 @@ func MakeShardingClient(ctx *cli.Context) *Client {
|
||||
|
||||
// Start the sharding client.
|
||||
// * Connects to node.
|
||||
// * Verifies the validator management contract.
|
||||
// * Verifies or deploys the validator management contract.
|
||||
func (c *Client) Start() error {
|
||||
log.Info("Starting sharding client")
|
||||
rpcClient, err := dialRPC(c.endpoint)
|
||||
@ -71,14 +70,14 @@ func (c *Client) Start() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: Wait to be selected in goroutine?
|
||||
// TODO: Wait to be selected as collator in goroutine?
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Wait until sharding client is shutdown.
|
||||
func (c *Client) Wait() {
|
||||
// TODO: Blocking lock
|
||||
// TODO: Blocking lock.
|
||||
}
|
||||
|
||||
// dialRPC endpoint to node.
|
||||
@ -88,3 +87,19 @@ func dialRPC(endpoint string) (*rpc.Client, error) {
|
||||
}
|
||||
return rpc.Dial(endpoint)
|
||||
}
|
||||
|
||||
// UnlockAccount will unlock the specified account using utils.PasswordFileFlag or empty string if unset.
|
||||
func (c *Client) unlockAccount(account accounts.Account) error {
|
||||
pass := ""
|
||||
|
||||
if c.ctx.GlobalIsSet(utils.PasswordFileFlag.Name) {
|
||||
blob, err := ioutil.ReadFile(c.ctx.GlobalString(utils.PasswordFileFlag.Name))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read account password contents in file %s. %v", utils.PasswordFileFlag.Value, err)
|
||||
}
|
||||
// TODO: Use bufio.Scanner or other reader that doesn't include a trailing newline character.
|
||||
pass = strings.Trim(string(blob), "\n") // Some text files end in new line, remove with strings.Trim.
|
||||
}
|
||||
|
||||
return c.keystore.Unlock(account, pass)
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ var (
|
||||
// Verify validator management contract.
|
||||
// Checks that the contract exists and verifies the bytecode. Otherwise, deploys a copy of the contract.
|
||||
func (c *Client) verifyVMC() error {
|
||||
// TODO: Fetch validator manager contract.
|
||||
b, err := c.client.CodeAt(context.Background(), validatorManagerAddress, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get contract code at %s. %v", validatorManagerAddress, err)
|
||||
@ -50,6 +49,8 @@ func (c *Client) verifyVMC() error {
|
||||
}
|
||||
|
||||
// TODO: Check contract bytecode is what we expected, otherwise return error.
|
||||
// Note: The compiled byte code returned by the contract will not exactly match the original
|
||||
// bytecode since the contract constructor is not saved on the chain.
|
||||
if !bytes.Equal(b, abiBytecode) {
|
||||
return fmt.Errorf("bytecode at contract address %s does not match expected bytecode", validatorManagerAddress.String())
|
||||
}
|
||||
@ -65,7 +66,6 @@ func (c *Client) deployVMC() (*common.Address, error) {
|
||||
return nil, fmt.Errorf("no accounts found")
|
||||
}
|
||||
|
||||
// TODO: call unlock only if account is actually locked.
|
||||
if err := c.unlockAccount(accounts[0]); err != nil {
|
||||
return nil, fmt.Errorf("unable to unlock account 0: %v", err)
|
||||
}
|
||||
@ -108,18 +108,3 @@ func (c *Client) deployVMC() (*common.Address, error) {
|
||||
|
||||
return &receipt.ContractAddress, nil
|
||||
}
|
||||
|
||||
func (c *Client) unlockAccount(account accounts.Account) error {
|
||||
pass := ""
|
||||
|
||||
if c.ctx.GlobalIsSet(utils.PasswordFileFlag.Name) {
|
||||
blob, err := ioutil.ReadFile(c.ctx.GlobalString(utils.PasswordFileFlag.Name))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read account password contents in file %s. %v", utils.PasswordFileFlag.Value, err)
|
||||
}
|
||||
// Some text files end in new line, remove with strings.Trim.
|
||||
pass = strings.Trim(string(blob), "\n")
|
||||
}
|
||||
|
||||
return c.keystore.Unlock(account, pass)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user