mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Cleanup of Keymanager Deleter interface (#10415)
* Migrating Keymanager account list functionality into each keymanager type * Addressing review comments * Adding newline at end of BUILD.bazel * bazel run //:gazelle -- fix * account deleter cleanup * bazel run //:gazelle -- fix * remove stale logging statement * adding deleter interface to mock functions * fixing deepsource findings * go.sum * bazel run //:gazelle -- fix * go mod t-dy -compat=1.17 Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com> Co-authored-by: prestonvanloon <preston@prysmaticlabs.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
||||
)
|
||||
|
||||
@@ -11,9 +10,8 @@ var (
|
||||
ErrCouldNotInitializeKeymanager = "could not initialize keymanager"
|
||||
)
|
||||
|
||||
// Config specifies parameters for accounts commands.
|
||||
type Config struct {
|
||||
Wallet *wallet.Wallet
|
||||
// DeleteConfig specifies parameters for the accounts delete command.
|
||||
type DeleteConfig struct {
|
||||
Keymanager keymanager.IKeymanager
|
||||
DeletePublicKeys [][]byte
|
||||
}
|
||||
|
||||
@@ -91,8 +91,7 @@ func DeleteAccountCli(cliCtx *cli.Context) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := DeleteAccount(cliCtx.Context, &Config{
|
||||
Wallet: w,
|
||||
if err := DeleteAccount(cliCtx.Context, &DeleteConfig{
|
||||
Keymanager: kManager,
|
||||
DeletePublicKeys: rawPublicKeys,
|
||||
}); err != nil {
|
||||
@@ -106,17 +105,13 @@ func DeleteAccountCli(cliCtx *cli.Context) error {
|
||||
}
|
||||
|
||||
// DeleteAccount deletes the accounts that the user requests to be deleted from the wallet.
|
||||
func DeleteAccount(ctx context.Context, cfg *Config) error {
|
||||
deleter, ok := cfg.Keymanager.(keymanager.Deleter)
|
||||
if !ok {
|
||||
return errors.New("keymanager does not implement Deleter interface")
|
||||
}
|
||||
func DeleteAccount(ctx context.Context, cfg *DeleteConfig) error {
|
||||
if len(cfg.DeletePublicKeys) == 1 {
|
||||
log.Info("Deleting account...")
|
||||
} else {
|
||||
log.Info("Deleting accounts...")
|
||||
}
|
||||
statuses, err := deleter.DeleteKeystores(ctx, cfg.DeletePublicKeys)
|
||||
statuses, err := cfg.Keymanager.DeleteKeystores(ctx, cfg.DeletePublicKeys)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not delete accounts")
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/crypto/bls"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
ethpbservice "github.com/prysmaticlabs/prysm/proto/eth/service"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
validatorpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
@@ -59,6 +60,10 @@ func (km *mockRemoteKeymanager) ListKeymanagerAccounts(ctx context.Context, cfg
|
||||
return remote.ListKeymanagerAccountsImpl(ctx, cfg, km, km.opts)
|
||||
}
|
||||
|
||||
func (*mockRemoteKeymanager) DeleteKeystores(context.Context, [][]byte) ([]*ethpbservice.DeletedKeystoreStatus, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func createRandomKeystore(t testing.TB, password string) *keymanager.Keystore {
|
||||
encryptor := keystorev4.New()
|
||||
id, err := uuid.NewRandom()
|
||||
|
||||
Reference in New Issue
Block a user