2020-10-15 22:31:52 +00:00
|
|
|
package accounts
|
2020-07-08 19:21:54 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2021-02-26 15:00:05 +00:00
|
|
|
"math"
|
2020-07-08 19:21:54 +00:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2022-08-16 12:20:13 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/validator/accounts/wallet"
|
2022-11-07 10:29:27 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/validator/client/iface"
|
2022-08-16 12:20:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/validator/keymanager"
|
2020-07-08 19:21:54 +00:00
|
|
|
)
|
|
|
|
|
2022-04-28 14:46:46 +00:00
|
|
|
// List pretty-prints accounts in the wallet.
|
|
|
|
func (acm *AccountsCLIManager) List(ctx context.Context) error {
|
|
|
|
if acm.listValidatorIndices {
|
|
|
|
client, _, err := acm.prepareBeaconClients(ctx)
|
2021-02-26 15:00:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-04-28 14:46:46 +00:00
|
|
|
return listValidatorIndices(ctx, acm.keymanager, *client)
|
2021-02-26 15:00:05 +00:00
|
|
|
}
|
2022-04-28 14:46:46 +00:00
|
|
|
return acm.keymanager.ListKeymanagerAccounts(ctx,
|
2022-03-22 03:04:09 +00:00
|
|
|
keymanager.ListKeymanagerAccountConfig{
|
2022-04-28 14:46:46 +00:00
|
|
|
ShowDepositData: acm.showDepositData,
|
|
|
|
ShowPrivateKeys: acm.showPrivateKeys,
|
|
|
|
WalletAccountsDir: acm.wallet.AccountsDir(),
|
2022-03-22 03:04:09 +00:00
|
|
|
KeymanagerConfigFileName: wallet.KeymanagerConfigFileName,
|
|
|
|
})
|
2020-07-24 00:43:01 +00:00
|
|
|
}
|
2021-02-26 15:00:05 +00:00
|
|
|
|
2022-11-07 10:29:27 +00:00
|
|
|
func listValidatorIndices(ctx context.Context, km keymanager.IKeymanager, client iface.ValidatorClient) error {
|
2021-02-26 15:00:05 +00:00
|
|
|
pubKeys, err := km.FetchValidatingPublicKeys(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not get validating public keys")
|
|
|
|
}
|
|
|
|
var pks [][]byte
|
|
|
|
for i := range pubKeys {
|
|
|
|
pks = append(pks, pubKeys[i][:])
|
|
|
|
}
|
|
|
|
req := ðpb.MultipleValidatorStatusRequest{PublicKeys: pks}
|
|
|
|
resp, err := client.MultipleValidatorStatus(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not request validator indices")
|
|
|
|
}
|
|
|
|
fmt.Println(au.BrightGreen("Validator indices:").Bold())
|
|
|
|
for i, idx := range resp.Indices {
|
|
|
|
if idx != math.MaxUint64 {
|
|
|
|
fmt.Printf("%#x: %d\n", pubKeys[i][0:4], idx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|