[#610] neofs-cli: add --wallet flag

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-06-15 18:45:45 +03:00 committed by Alex Vanin
parent 2b5998b820
commit 1b14b25e6c

View file

@ -84,6 +84,8 @@ func init() {
rootCmd.PersistentFlags().StringP("key", "k", "", "private key in hex, WIF, NEP-2 or filepath") rootCmd.PersistentFlags().StringP("key", "k", "", "private key in hex, WIF, NEP-2 or filepath")
_ = viper.BindPFlag("key", rootCmd.PersistentFlags().Lookup("key")) _ = viper.BindPFlag("key", rootCmd.PersistentFlags().Lookup("key"))
rootCmd.PersistentFlags().StringP("wallet", "w", "", "path to the wallet")
_ = viper.BindPFlag("wallet", rootCmd.PersistentFlags().Lookup("wallet"))
rootCmd.PersistentFlags().StringP("address", "", "", "address of wallet account") rootCmd.PersistentFlags().StringP("address", "", "", "address of wallet account")
_ = viper.BindPFlag("address", rootCmd.PersistentFlags().Lookup("address")) _ = viper.BindPFlag("address", rootCmd.PersistentFlags().Lookup("address"))
@ -143,12 +145,15 @@ func getKey() (*ecdsa.PrivateKey, error) {
return &priv.PrivateKey, nil return &priv.PrivateKey, nil
} }
privateKey := viper.GetString("key") if walletPath := viper.GetString("wallet"); walletPath != "" {
w, err := wallet.NewWalletFromFile(privateKey) w, err := wallet.NewWalletFromFile(walletPath)
if err == nil { if err != nil {
return nil, fmt.Errorf("%w: %v", errInvalidKey, err)
}
return getKeyFromWallet(w, viper.GetString("address")) return getKeyFromWallet(w, viper.GetString("address"))
} }
privateKey := viper.GetString("key")
if len(privateKey) == nep2Base58Length { if len(privateKey) == nep2Base58Length {
return getKeyFromNEP2(privateKey) return getKeyFromNEP2(privateKey)
} }