mirror of
https://github.com/wealdtech/ethdo.git
synced 2026-01-09 14:07:56 -05:00
Tidy-ups.
This commit is contained in:
@@ -45,6 +45,7 @@ type command struct {
|
||||
forkVersion string
|
||||
genesisValidatorsRoot string
|
||||
prepareOffline bool
|
||||
signedOperationsInput string
|
||||
|
||||
// Beacon node connection.
|
||||
timeout time.Duration
|
||||
@@ -80,6 +81,7 @@ func newCommand(_ context.Context) (*command, error) {
|
||||
mnemonic: viper.GetString("mnemonic"),
|
||||
path: viper.GetString("path"),
|
||||
privateKey: viper.GetString("private-key"),
|
||||
signedOperationsInput: viper.GetString("signed-operations"),
|
||||
|
||||
validator: viper.GetString("validator"),
|
||||
withdrawalAddressStr: viper.GetString("withdrawal-address"),
|
||||
|
||||
@@ -33,6 +33,9 @@ func (c *command) output(_ context.Context) (string, error) {
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to marshal signed operations")
|
||||
}
|
||||
if c.json {
|
||||
return string(data), nil
|
||||
}
|
||||
if err := os.WriteFile(changeOperationsFilename, data, 0600); err != nil {
|
||||
return "", errors.Wrap(err, fmt.Sprintf("failed to write %s", changeOperationsFilename))
|
||||
}
|
||||
|
||||
@@ -321,7 +321,13 @@ func (c *command) loadChainInfo(_ context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *command) loadOperations(_ context.Context) error {
|
||||
func (c *command) loadOperations(ctx context.Context) error {
|
||||
// Start off by attempting to use the provided signed operations.
|
||||
if c.signedOperationsInput != "" {
|
||||
return c.loadOperationsFromInput(ctx)
|
||||
}
|
||||
|
||||
// If not, read it from the file with the standard name.
|
||||
_, err := os.Stat(changeOperationsFilename)
|
||||
if err != nil {
|
||||
if c.debug {
|
||||
@@ -329,7 +335,6 @@ func (c *command) loadOperations(_ context.Context) error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if c.debug {
|
||||
fmt.Fprintf(os.Stderr, "%s found; loading operations\n", changeOperationsFilename)
|
||||
}
|
||||
@@ -344,6 +349,28 @@ func (c *command) loadOperations(_ context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *command) loadOperationsFromInput(_ context.Context) error {
|
||||
if strings.HasPrefix(c.signedOperationsInput, "{") {
|
||||
// This looks like a single entry; turn it in to an array.
|
||||
c.signedOperationsInput = fmt.Sprintf("[%s]", c.signedOperationsInput)
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(c.signedOperationsInput, "[") {
|
||||
// This looks like a file; read it in.
|
||||
data, err := os.ReadFile(c.signedOperationsInput)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to read input file")
|
||||
}
|
||||
c.signedOperationsInput = string(data)
|
||||
}
|
||||
|
||||
if err := json.Unmarshal([]byte(c.signedOperationsInput), &c.signedOperations); err != nil {
|
||||
return errors.Wrap(err, "failed to parse change operations input")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *command) generateOperationsFromMnemonic(ctx context.Context) error {
|
||||
seed, err := util.SeedFromMnemonic(c.mnemonic)
|
||||
if err != nil {
|
||||
|
||||
@@ -60,7 +60,7 @@ func init() {
|
||||
validatorCredentialsSetCmd.Flags().String("validator", "", "Validator for which to set validator credentials")
|
||||
validatorCredentialsSetCmd.Flags().String("withdrawal-account", "", "Account with which the validator's withdrawal credentials were set")
|
||||
validatorCredentialsSetCmd.Flags().String("withdrawal-address", "", "Execution address to which to direct withdrawals")
|
||||
validatorCredentialsSetCmd.Flags().String("signed-operation", "", "Use pre-defined JSON signed operation as created by --json to transmit the credentials change operation")
|
||||
validatorCredentialsSetCmd.Flags().String("signed-operations", "", "Use pre-defined JSON signed operation as created by --json to transmit the credentials change operation (reads from change-operations.json if not present)")
|
||||
validatorCredentialsSetCmd.Flags().Bool("json", false, "Generate JSON data containing a signed operation rather than broadcast it to the network (implied when offline)")
|
||||
validatorCredentialsSetCmd.Flags().Bool("offline", false, "Do not attempt to connect to a beacon node to obtain information for the operation")
|
||||
validatorCredentialsSetCmd.Flags().String("fork-version", "", "Fork version to use for signing (overrides fetching from beacon node)")
|
||||
@@ -74,7 +74,7 @@ func validatorCredentialsSetBindings() {
|
||||
if err := viper.BindPFlag("validator", validatorCredentialsSetCmd.Flags().Lookup("validator")); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := viper.BindPFlag("signed-operation", validatorCredentialsSetCmd.Flags().Lookup("signed-operation")); err != nil {
|
||||
if err := viper.BindPFlag("signed-operations", validatorCredentialsSetCmd.Flags().Lookup("signed-operations")); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := viper.BindPFlag("withdrawal-account", validatorCredentialsSetCmd.Flags().Lookup("withdrawal-account")); err != nil {
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
|
||||
// ReleaseVersion is the release version of the codebase.
|
||||
// Usually overridden by tag names when building binaries.
|
||||
var ReleaseVersion = "local build (latest release 1.26.5)"
|
||||
var ReleaseVersion = "local build (latest release 1.27.0)"
|
||||
|
||||
// versionCmd represents the version command
|
||||
var versionCmd = &cobra.Command{
|
||||
|
||||
2
go.mod
2
go.mod
@@ -26,7 +26,7 @@ require (
|
||||
github.com/wealdtech/go-eth2-types/v2 v2.8.0
|
||||
github.com/wealdtech/go-eth2-util v1.8.0
|
||||
github.com/wealdtech/go-eth2-wallet v1.15.0
|
||||
github.com/wealdtech/go-eth2-wallet-dirk v1.4.1
|
||||
github.com/wealdtech/go-eth2-wallet-dirk v1.4.2
|
||||
github.com/wealdtech/go-eth2-wallet-distributed v1.1.4
|
||||
github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.3.0
|
||||
github.com/wealdtech/go-eth2-wallet-hd/v2 v2.6.0
|
||||
|
||||
4
go.sum
4
go.sum
@@ -517,8 +517,8 @@ github.com/wealdtech/go-eth2-util v1.8.0 h1:hhs3h2y3Ldty18lppFdpe46nZpdDAMbY7Qqi
|
||||
github.com/wealdtech/go-eth2-util v1.8.0/go.mod h1:rSuE0v5zX+uyZrqW/iUmXOxeDpB7lTvhcZvAVh0KlMU=
|
||||
github.com/wealdtech/go-eth2-wallet v1.15.0 h1:yff2rWCvHyr5bOU41wwilsNemFRYOFinZoIPjhzG10M=
|
||||
github.com/wealdtech/go-eth2-wallet v1.15.0/go.mod h1:BqXnen6XCa99yaUx/XIcyImaZLJMMj4wIMcUBywlMJs=
|
||||
github.com/wealdtech/go-eth2-wallet-dirk v1.4.1 h1:TXq4pRCFhOGPtp3e35BKWF5z13p+im9dh6i8ISkochs=
|
||||
github.com/wealdtech/go-eth2-wallet-dirk v1.4.1/go.mod h1:WGzvX3nxQnFNv4Hjx7jfBQhlVAEsRqe1tZwC8hZWM98=
|
||||
github.com/wealdtech/go-eth2-wallet-dirk v1.4.2 h1:TV5rrXGtHPteV+Mk7v6KFdmSUDm38SDKBDHFIvKIL8w=
|
||||
github.com/wealdtech/go-eth2-wallet-dirk v1.4.2/go.mod h1:WGzvX3nxQnFNv4Hjx7jfBQhlVAEsRqe1tZwC8hZWM98=
|
||||
github.com/wealdtech/go-eth2-wallet-distributed v1.1.4 h1:EBk/FofiQWtbRYmwdCp0qM9TPDvlh1LN2yjlLr4W3ao=
|
||||
github.com/wealdtech/go-eth2-wallet-distributed v1.1.4/go.mod h1:Y31pDxcdyADwfQl65t8V6KhcmCes31EXkXZPDcT2SIk=
|
||||
github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.1.6/go.mod h1:hIeHsLJWVxFUUqQqaBm9nmUW3Y/eHneQclYyNayUeQg=
|
||||
|
||||
Reference in New Issue
Block a user