diff --git a/client/testnet.go b/client/testnet.go index 9bf42baea6..bc75c37cf0 100644 --- a/client/testnet.go +++ b/client/testnet.go @@ -272,7 +272,8 @@ func initTestnetFiles( return err } - addr, secret, err := sdkserver.GenerateSaveCoinKey(kb, nodeDirName, true, algo) + // TODO: remove when using Cosmos SDK v0.45 + addr, secret, err := GenerateSaveCoinKey(kb, nodeDirName, true, algo) if err != nil { _ = os.RemoveAll(args.outputDir) return err @@ -560,3 +561,37 @@ func startTestnet(cmd *cobra.Command, args startArgs) error { return nil } + +// TODO: remove + +// GenerateSaveCoinKey returns the address of a public key, along with the secret +// phrase to recover the private key. +func GenerateSaveCoinKey(keybase keyring.Keyring, keyName string, overwrite bool, algo keyring.SignatureAlgo) (sdk.AccAddress, string, error) { + exists := false + _, err := keybase.Key(keyName) + if err == nil { + exists = true + } + + // ensure no overwrite + if !overwrite && exists { + return sdk.AccAddress([]byte{}), "", fmt.Errorf( + "key already exists, overwrite is disabled") + } + + // generate a private key, with recovery phrase + if exists { + err = keybase.Delete(keyName) + if err != nil { + return sdk.AccAddress([]byte{}), "", fmt.Errorf( + "failed to overwrite key") + } + } + + info, secret, err := keybase.NewMnemonic(keyName, keyring.English, sdk.GetConfig().GetFullBIP44Path(), keyring.DefaultBIP39Passphrase, algo) + if err != nil { + return sdk.AccAddress([]byte{}), "", err + } + + return sdk.AccAddress(info.GetPubKey().Address()), secret, nil +}