Compare commits

...

3 Commits

Author SHA1 Message Date
Jim McDonald
8078359eab Show account info for dynamically generated HD accounts 2020-07-28 20:16:41 +01:00
Jim McDonald
7de8dc7424 Show account info for dynamically generated HD accounts 2020-07-28 20:14:43 +01:00
Jim McDonald
987dbd26c6 Provide deposit info prior to chain-based info 2020-07-24 13:56:53 +01:00
3 changed files with 37 additions and 11 deletions

View File

@@ -17,6 +17,7 @@ import (
"context"
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -39,10 +40,21 @@ In quiet mode this will return 0 if the account exists, otherwise 1.`,
wallet, err := openWallet()
errCheck(err, "Failed to access wallet")
outputIf(debug, fmt.Sprintf("Opened wallet %q of type %s", wallet.Name(), wallet.Type()))
_, accountName, err := e2wallet.WalletAndAccountNames(viper.GetString("account"))
errCheck(err, "Failed to obtain account name")
if wallet.Type() == "hierarchical deterministic" && strings.HasPrefix(accountName, "m/") {
assert(getWalletPassphrase() != "", "walletpassphrase is required to show information about dynamically generated hierarchical deterministic accounts")
locker, isLocker := wallet.(e2wtypes.WalletLocker)
if isLocker {
ctx, cancel := context.WithTimeout(context.Background(), viper.GetDuration("timeout"))
defer cancel()
errCheck(locker.Unlock(ctx, []byte(getWalletPassphrase())), "Failed to unlock wallet")
}
}
accountByNameProvider, isAccountByNameProvider := wallet.(e2wtypes.WalletAccountByNameProvider)
assert(isAccountByNameProvider, "wallet cannot obtain accounts by name")
ctx, cancel := context.WithTimeout(context.Background(), viper.GetDuration("timeout"))

View File

@@ -56,6 +56,19 @@ In quiet mode this will return 0 if the validator information can be obtained, o
account, err := validatorInfoAccount()
errCheck(err, "Failed to obtain validator account")
if verbose {
network := network()
outputIf(debug, fmt.Sprintf("Network is %s", network))
pubKey, err := bestPublicKey(account)
if err == nil {
deposits, totalDeposited, err := graphData(network, pubKey.Marshal())
if err == nil {
fmt.Printf("Number of deposits: %d\n", deposits)
fmt.Printf("Total deposited: %s\n", string2eth.GWeiToString(totalDeposited, true))
}
}
}
validatorInfo, err := grpc.FetchValidatorInfo(eth2GRPCConn, account)
errCheck(err, "Failed to obtain validator information")
validator, err := grpc.FetchValidator(eth2GRPCConn, account)
@@ -79,16 +92,6 @@ In quiet mode this will return 0 if the validator information can be obtained, o
fmt.Printf("Status: %s\n", strings.Title(strings.ToLower(validatorInfo.Status.String())))
fmt.Printf("Balance: %s\n", string2eth.GWeiToString(validatorInfo.Balance, true))
if verbose {
network := network()
outputIf(debug, fmt.Sprintf("Network is %s", network))
deposits, totalDeposited, err := graphData(network, validator.PublicKey)
if err == nil {
fmt.Printf("Number of deposits: %d\n", deposits)
fmt.Printf("Total deposited: %s\n", string2eth.GWeiToString(totalDeposited, true))
}
}
if validatorInfo.Status == ethpb.ValidatorStatus_ACTIVE ||
validatorInfo.Status == ethpb.ValidatorStatus_EXITING ||
validatorInfo.Status == ethpb.ValidatorStatus_SLASHING {
@@ -134,6 +137,17 @@ func validatorInfoAccount() (e2wtypes.Account, error) {
if err != nil {
return nil, errors.Wrap(err, "failed to obtain account name")
}
if wallet.Type() == "hierarchical deterministic" && strings.HasPrefix(accountName, "m/") {
assert(getWalletPassphrase() != "", "walletpassphrase is required to obtain information about validators with dynamically generated hierarchical deterministic accounts")
locker, isLocker := wallet.(e2wtypes.WalletLocker)
if isLocker {
ctx, cancel := context.WithTimeout(context.Background(), viper.GetDuration("timeout"))
defer cancel()
errCheck(locker.Unlock(ctx, []byte(getWalletPassphrase())), "Failed to unlock wallet")
}
}
accountByNameProvider, isProvider := wallet.(e2wtypes.WalletAccountByNameProvider)
if !isProvider {
return nil, errors.New("failed to ask wallet for account by name")

View File

@@ -22,7 +22,7 @@ import (
"github.com/spf13/viper"
)
var ReleaseVersion = "local build from v1.5.1"
var ReleaseVersion = "local build from v1.5.2"
// versionCmd represents the version command
var versionCmd = &cobra.Command{