testnet custom algorithm (#441)
* testnet custom algorithm * minor fixes
This commit is contained in:
parent
a243f43fe2
commit
a2a5799d13
@ -34,6 +34,10 @@ func KeyCommands() *cobra.Command {
|
||||
|
||||
// support adding Ethereum supported keys
|
||||
addCmd := clientkeys.AddKeyCommand()
|
||||
|
||||
// update the default signing algorithm value to "eth_secp256k1"
|
||||
algoFlag := addCmd.Flag("algo")
|
||||
algoFlag.DefValue = string(crypto.EthSecp256k1)
|
||||
addCmd.RunE = runAddCmd
|
||||
|
||||
cmd.AddCommand(
|
||||
|
@ -48,6 +48,7 @@ var (
|
||||
flagNodeDaemonHome = "node-daemon-home"
|
||||
flagNodeCLIHome = "node-cli-home"
|
||||
flagStartingIPAddress = "starting-ip-address"
|
||||
flagKeyAlgo = "algo"
|
||||
)
|
||||
|
||||
const nodeDirPerm = 0755
|
||||
@ -77,10 +78,11 @@ Note, strict routability for addresses is turned off in the config file.`,
|
||||
nodeCLIHome, _ := cmd.Flags().GetString(flagNodeCLIHome)
|
||||
startingIPAddress, _ := cmd.Flags().GetString(flagStartingIPAddress)
|
||||
numValidators, _ := cmd.Flags().GetInt(flagNumValidators)
|
||||
algo, _ := cmd.Flags().GetString(flagKeyAlgo)
|
||||
|
||||
return InitTestnet(
|
||||
cmd, config, cdc, mbm, genBalIterator, outputDir, chainID, minGasPrices,
|
||||
nodeDirPrefix, nodeDaemonHome, nodeCLIHome, startingIPAddress, keyringBackend, numValidators,
|
||||
nodeDirPrefix, nodeDaemonHome, nodeCLIHome, startingIPAddress, keyringBackend, algo, numValidators,
|
||||
)
|
||||
},
|
||||
}
|
||||
@ -94,16 +96,27 @@ Note, strict routability for addresses is turned off in the config file.`,
|
||||
cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
|
||||
cmd.Flags().String(server.FlagMinGasPrices, fmt.Sprintf("0.000006%s", types.DenomDefault), "Minimum gas prices to accept for transactions; All fees in a tx must meet this minimum (e.g. 0.01photon,0.001stake)")
|
||||
cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|test)")
|
||||
|
||||
cmd.Flags().String(flagKeyAlgo, string(crypto.EthSecp256k1), "Key signing algorithm to generate keys for")
|
||||
return cmd
|
||||
}
|
||||
|
||||
// InitTestnet initializes the testnet configuration
|
||||
func InitTestnet(
|
||||
cmd *cobra.Command, config *tmconfig.Config, cdc *codec.Codec,
|
||||
mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator,
|
||||
outputDir, chainID, minGasPrices, nodeDirPrefix, nodeDaemonHome,
|
||||
nodeCLIHome, startingIPAddress, keyringBackend string, numValidators int,
|
||||
cmd *cobra.Command,
|
||||
config *tmconfig.Config,
|
||||
cdc *codec.Codec,
|
||||
mbm module.BasicManager,
|
||||
genBalIterator banktypes.GenesisBalancesIterator,
|
||||
outputDir,
|
||||
chainID,
|
||||
minGasPrices,
|
||||
nodeDirPrefix,
|
||||
nodeDaemonHome,
|
||||
nodeCLIHome,
|
||||
startingIPAddress,
|
||||
keyringBackend,
|
||||
algo string,
|
||||
numValidators int,
|
||||
) error {
|
||||
|
||||
if chainID == "" {
|
||||
@ -176,7 +189,7 @@ func InitTestnet(
|
||||
)
|
||||
|
||||
keyPass := clientkeys.DefaultKeyPass
|
||||
addr, secret, err := server.GenerateSaveCoinKey(kb, nodeDirName, keyPass, true)
|
||||
addr, secret, err := GenerateSaveCoinKey(kb, nodeDirName, keyPass, true, keyring.SigningAlgo(algo))
|
||||
if err != nil {
|
||||
_ = os.RemoveAll(outputDir)
|
||||
return err
|
||||
@ -323,6 +336,27 @@ func initGenFiles(
|
||||
return nil
|
||||
}
|
||||
|
||||
// GenerateSaveCoinKey returns the address of a public key, along with the secret
|
||||
// phrase to recover the private key.
|
||||
func GenerateSaveCoinKey(keybase keyring.Keybase, keyName, keyPass string, overwrite bool, algo keyring.SigningAlgo) (sdk.AccAddress, string, error) {
|
||||
// ensure no overwrite
|
||||
if !overwrite {
|
||||
_, err := keybase.Get(keyName)
|
||||
if err == nil {
|
||||
return sdk.AccAddress([]byte{}), "", fmt.Errorf(
|
||||
"key already exists, overwrite is disabled")
|
||||
}
|
||||
}
|
||||
|
||||
// generate a private key, with recovery phrase
|
||||
info, secret, err := keybase.CreateMnemonic(keyName, keyring.English, keyPass, algo)
|
||||
if err != nil {
|
||||
return sdk.AccAddress([]byte{}), "", err
|
||||
}
|
||||
|
||||
return sdk.AccAddress(info.GetPubKey().Address()), secret, nil
|
||||
}
|
||||
|
||||
func collectGenFiles(
|
||||
cdc *codec.Codec, config *tmconfig.Config, chainID string,
|
||||
nodeIDs []string, valPubKeys []tmcrypto.PubKey,
|
||||
|
Loading…
Reference in New Issue
Block a user