Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
update testnet hdPath, fixes #688
Browse files Browse the repository at this point in the history
  • Loading branch information
fedekunze committed Nov 12, 2021
1 parent 778534b commit 64bb4b1
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion client/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 64bb4b1

Please sign in to comment.