Skip to content

Commit

Permalink
fireblocks in create config (#119)
Browse files Browse the repository at this point in the history
* fireblocks in create config

* make input promot and use that

* fix comment

* generate mocks

* generate mocks
  • Loading branch information
shrimalmadhur committed Apr 28, 2024
1 parent 4ed56f5 commit d3ef7e3
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 18 deletions.
104 changes: 87 additions & 17 deletions pkg/operator/config/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,6 @@ func promptOperatorInfo(config *types.OperatorConfigNew, p utils.Prompter) (type
}
config.EthRPCUrl = rpcUrl

// Prompt for ecdsa key path
ecdsaKeyPath, err := p.InputString("Enter your ecdsa key path:", "", "",
func(s string) error {
_, err := os.Stat(s)
if os.IsNotExist(err) {
return err
}
return nil
},
)

if err != nil {
return types.OperatorConfigNew{}, err
}
config.PrivateKeyStorePath = ecdsaKeyPath

// Prompt for network & set chainId
chainId, err := p.Select("Select your network:", []string{"mainnet", "holesky", "local"})
if err != nil {
Expand All @@ -201,7 +185,93 @@ func promptOperatorInfo(config *types.OperatorConfigNew, p utils.Prompter) (type
config.ELDelegationManagerAddress = utils.ChainMetadataMap[utils.LocalChainId].ELDelegationManagerAddress
}

config.SignerType = types.LocalKeystoreSigner
// Prompt for signer type
signerType, err := p.Select("Select your signer type:", []string{"local_keystore", "fireblocks"})
if err != nil {
return types.OperatorConfigNew{}, err
}

switch signerType {
case "local_keystore":
config.SignerType = types.LocalKeystoreSigner
// Prompt for ecdsa key path
ecdsaKeyPath, err := p.InputString("Enter your ecdsa key path:", "", "",
func(s string) error {
_, err := os.Stat(s)
if os.IsNotExist(err) {
return err
}
return nil
},
)

if err != nil {
return types.OperatorConfigNew{}, err
}
config.PrivateKeyStorePath = ecdsaKeyPath
case "fireblocks":
config.SignerType = types.FireBlocksSigner
// Prompt for fireblocks API key
apiKey, err := p.InputString("Enter your fireblocks api key:", "", "",
func(s string) error {
if len(s) == 0 {
return errors.New("fireblocks API key should not be empty")
}
return nil
},
)
if err != nil {
return types.OperatorConfigNew{}, err
}
config.FireblocksConfig.APIKey = apiKey

// Prompt for fireblocks base url
baseUrl, err := p.InputString("Enter your fireblocks base url:", "https://api.fireblocks.io/", "",
func(s string) error {
if len(s) == 0 {
return errors.New("base url should not be empty")
}
return nil
},
)
if err != nil {
return types.OperatorConfigNew{}, err
}
config.FireblocksConfig.BaseUrl = baseUrl

// Prompt for fireblocks vault account name
vaultAccountName, err := p.InputString("Enter the name of fireblocks vault:", "", "",
func(s string) error {
if len(s) == 0 {
return errors.New("vault account name should not be empty")
}
return nil
},
)
if err != nil {
return types.OperatorConfigNew{}, err
}
config.FireblocksConfig.VaultAccountName = vaultAccountName

// Prompt for fireblocks API timeout
timeout, err := p.InputInteger("Enter the timeout for fireblocks API (in seconds):", "3", "",
func(i int64) error {
if i <= 0 {
return errors.New("timeout should be greater than 0")
}
return nil
},
)
if err != nil {
return types.OperatorConfigNew{}, err
}
config.FireblocksConfig.Timeout = timeout

// ask to fill in secret key
config.FireblocksConfig.SecretKey = "<FILL-ME>"
default:
return types.OperatorConfigNew{}, fmt.Errorf("unknown signer type %s", signerType)
}

return *config, nil
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/utils/mocks/prompter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion pkg/utils/prompter.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package utils

import "github.com/AlecAivazis/survey/v2"
import (
"fmt"
"strconv"

"github.com/AlecAivazis/survey/v2"
)

// Prompter is an interface for prompting the user for input.
type Prompter interface {
Select(prompt string, options []string) (string, error)
InputString(prompt, defValue, help string, validator func(string) error) (string, error)
InputInteger(prompt, defValue, help string, validator func(int64) error) (int64, error)
Confirm(prompt string) (bool, error)
InputHiddenString(prompt, help string, validator func(string) error) (string, error)
}
Expand Down Expand Up @@ -46,6 +52,27 @@ func (p *prompter) InputString(prompt, defValue, help string, validator func(str
return result, err
}

func (p *prompter) InputInteger(prompt, defValue, help string, validator func(int64) error) (int64, error) {
var result int64
i := &survey.Input{
Message: prompt,
Default: defValue,
Help: help,
}

err := survey.AskOne(i, &result, survey.WithValidator(func(ans interface{}) error {
atoi, err := strconv.Atoi(ans.(string))
if err != nil {
return fmt.Errorf("invalid integer with err: %s", err.Error())
}
if err := validator(int64(atoi)); err != nil {
return err
}
return nil
}))
return result, err
}

// Confirm prompts the user to confirm an action with a yes/no question.
func (p *prompter) Confirm(prompt string) (bool, error) {
result := false
Expand Down

0 comments on commit d3ef7e3

Please sign in to comment.