This commit is contained in:
Jim McDonald
2023-01-28 00:42:24 +00:00
parent b9ba1ec1c2
commit 85a0590d55
19 changed files with 49 additions and 34 deletions

View File

@@ -142,7 +142,6 @@ linters:
- gocognit
- goconst
- goerr113
- gofumpt
- goheader
- golint
- gomnd

View File

@@ -29,9 +29,11 @@ import (
"github.com/pkg/errors"
)
var jsonOutput bool
var sszOutput bool
var results *dataOut
var (
jsonOutput bool
sszOutput bool
results *dataOut
)
func process(ctx context.Context, data *dataIn) (*dataOut, error) {
if data == nil {

View File

@@ -29,12 +29,14 @@ import (
string2eth "github.com/wealdtech/go-string2eth"
)
var depositVerifyData string
var depositVerifyWithdrawalPubKey string
var depositVerifyWithdrawalAddress string
var depositVerifyValidatorPubKey string
var depositVerifyDepositAmount string
var depositVerifyForkVersion string
var (
depositVerifyData string
depositVerifyWithdrawalPubKey string
depositVerifyWithdrawalAddress string
depositVerifyValidatorPubKey string
depositVerifyDepositAmount string
depositVerifyForkVersion string
)
var depositVerifyCmd = &cobra.Command{
Use: "verify",

View File

@@ -93,6 +93,7 @@ func (c *command) activeValidators(ctx context.Context) (map[phase0.ValidatorInd
return activeValidators, nil
}
func (c *command) processAttesterDuties(ctx context.Context) error {
activeValidators, err := c.activeValidators(ctx)
if err != nil {

View File

@@ -33,10 +33,12 @@ import (
e2wtypes "github.com/wealdtech/go-eth2-wallet-types/v2"
)
var cfgFile string
var quiet bool
var verbose bool
var debug bool
var (
cfgFile string
quiet bool
verbose bool
debug bool
)
// RootCmd represents the base command when called without any subcommands.
var RootCmd = &cobra.Command{

View File

@@ -31,8 +31,10 @@ func init() {
RootCmd.AddCommand(signatureCmd)
}
var dataFlag *pflag.Flag
var domainFlag *pflag.Flag
var (
dataFlag *pflag.Flag
domainFlag *pflag.Flag
)
func signatureFlags(cmd *cobra.Command) {
if dataFlag == nil {

View File

@@ -27,8 +27,10 @@ import (
e2wtypes "github.com/wealdtech/go-eth2-wallet-types/v2"
)
var signatureVerifySignature string
var signatureVerifySigner string
var (
signatureVerifySignature string
signatureVerifySigner string
)
// signatureVerifyCmd represents the signature verify command.
var signatureVerifyCmd = &cobra.Command{

View File

@@ -97,7 +97,7 @@ func (c *command) writeChainInfoToFile(_ context.Context) error {
if err != nil {
return err
}
if err := os.WriteFile(offlinePreparationFilename, data, 0600); err != nil {
if err := os.WriteFile(offlinePreparationFilename, data, 0o600); err != nil {
return err
}

View File

@@ -40,7 +40,7 @@ func (c *command) output(_ context.Context) (string, error) {
if c.json {
return string(data), nil
}
if err := os.WriteFile(changeOperationsFilename, data, 0600); err != nil {
if err := os.WriteFile(changeOperationsFilename, data, 0o600); err != nil {
return "", errors.Wrap(err, fmt.Sprintf("failed to write %s", changeOperationsFilename))
}
return "", nil

View File

@@ -47,8 +47,10 @@ var minTimeout = 2 * time.Minute
// validatorPath is the regular expression that matches a validator path.
var validatorPath = regexp.MustCompile("^m/12381/3600/[0-9]+/0/0$")
var offlinePreparationFilename = "offline-preparation.json"
var changeOperationsFilename = "change-operations.json"
var (
offlinePreparationFilename = "offline-preparation.json"
changeOperationsFilename = "change-operations.json"
)
func (c *command) process(ctx context.Context) error {
if err := c.setup(ctx); err != nil {

View File

@@ -97,7 +97,7 @@ func (c *command) writeChainInfoToFile(_ context.Context) error {
if err != nil {
return err
}
if err := os.WriteFile(offlinePreparationFilename, data, 0600); err != nil {
if err := os.WriteFile(offlinePreparationFilename, data, 0o600); err != nil {
return err
}

View File

@@ -40,7 +40,7 @@ func (c *command) output(_ context.Context) (string, error) {
if c.json {
return string(data), nil
}
if err := os.WriteFile(exitOperationFilename, data, 0600); err != nil {
if err := os.WriteFile(exitOperationFilename, data, 0o600); err != nil {
return "", errors.Wrap(err, fmt.Sprintf("failed to write %s", exitOperationFilename))
}
return "", nil

View File

@@ -46,8 +46,10 @@ var minTimeout = 2 * time.Minute
// validatorPath is the regular expression that matches a validator path.
var validatorPath = regexp.MustCompile("^m/12381/3600/[0-9]+/0/0$")
var offlinePreparationFilename = "offline-preparation.json"
var exitOperationFilename = "exit-operation.json"
var (
offlinePreparationFilename = "offline-preparation.json"
exitOperationFilename = "exit-operation.json"
)
func (c *command) process(ctx context.Context) error {
if err := c.setup(ctx); err != nil {

View File

@@ -40,9 +40,11 @@ func (c *command) process(ctx context.Context) error {
return c.calculateYield(ctx)
}
var weiPerGwei = decimal.New(1e9, 0)
var one = decimal.New(1, 0)
var epochsPerYear = decimal.New(225*365, 0)
var (
weiPerGwei = decimal.New(1e9, 0)
one = decimal.New(1, 0)
epochsPerYear = decimal.New(225*365, 0)
)
// calculateYield calculates yield from the number of active validators.
func (c *command) calculateYield(ctx context.Context) error {

View File

@@ -74,7 +74,7 @@ func process(ctx context.Context, data *dataIn) (*dataOut, error) {
return nil, errors.Wrap(err, "failed to marshal shamir export")
}
if err := os.WriteFile(data.file, sharedFile, 0600); err != nil {
if err := os.WriteFile(data.file, sharedFile, 0o600); err != nil {
return nil, errors.Wrap(err, "failed to write export file")
}

View File

@@ -37,7 +37,7 @@ func TestInput(t *testing.T) {
dir, err := os.MkdirTemp("", "")
require.NoError(t, err)
datFile := filepath.Join(dir, "backup.dat")
require.NoError(t, os.WriteFile(datFile, []byte("dummy"), 0600))
require.NoError(t, os.WriteFile(datFile, []byte("dummy"), 0o600))
defer os.RemoveAll(dir)
store := scratch.New()

View File

@@ -39,7 +39,7 @@ func TestProcess(t *testing.T) {
dir, err := os.MkdirTemp("", "")
require.NoError(t, err)
datFile := filepath.Join(dir, "backup.dat")
require.NoError(t, os.WriteFile(datFile, export, 0600))
require.NoError(t, os.WriteFile(datFile, export, 0o600))
defer os.RemoveAll(dir)
tests := []struct {

View File

@@ -30,7 +30,7 @@ var Log zerolog.Logger
func InitLogging() error {
// Change the output file.
if viper.GetString("log-file") != "" {
f, err := os.OpenFile(viper.GetString("log-file"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
f, err := os.OpenFile(viper.GetString("log-file"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o600)
if err != nil {
return errors.Wrap(err, "failed to open log file")
}

View File

@@ -22,7 +22,6 @@ import (
)
func TestUnmarshal(t *testing.T) {
tests := []struct {
name string
in []byte