From 6cde2ef60c3b749603738a9ac4c1eea356157fbe Mon Sep 17 00:00:00 2001 From: Ali Hamrani Date: Wed, 6 Nov 2024 11:00:15 +0330 Subject: [PATCH] chore(crypto): define testnet HRPs (#1583) --- cmd/cmd.go | 6 +----- cmd/wallet/address.go | 2 ++ crypto/crypto.go | 9 +++++++++ wallet/wallet.go | 6 +----- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index cdd089d66..18ef324c3 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -455,11 +455,7 @@ func MakeConfig(workingDir string) (*config.Config, *genesis.Genesis, error) { } if !gen.ChainType().IsMainnet() { - crypto.AddressHRP = "tpc" - crypto.PublicKeyHRP = "tpublic" - crypto.PrivateKeyHRP = "tsecret" - crypto.XPublicKeyHRP = "txpublic" - crypto.XPrivateKeyHRP = "txsecret" + crypto.ToTestnetHRP() } walletsDir := PactusWalletDir(workingDir) diff --git a/cmd/wallet/address.go b/cmd/wallet/address.go index 390ff1668..2b438f776 100644 --- a/cmd/wallet/address.go +++ b/cmd/wallet/address.go @@ -140,6 +140,7 @@ func buildPrivateKeyCmd(parentCmd *cobra.Command) { Short: "displays the private key for a specified address", Args: cobra.ExactArgs(1), } + parentCmd.AddCommand(privateKeyCmd) passOpt := addPasswordOption(privateKeyCmd) @@ -166,6 +167,7 @@ func buildPublicKeyCmd(parentCmd *cobra.Command) { Short: "displays the public key for a specified address", Args: cobra.ExactArgs(1), } + parentCmd.AddCommand(publicKeyCmd) publicKeyCmd.Run = func(_ *cobra.Command, args []string) { diff --git a/crypto/crypto.go b/crypto/crypto.go index 77c501d06..83aa77083 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -12,3 +12,12 @@ var ( // XPrivateKeyHRP is the Human Readable Part (HRP) for extended private key. XPrivateKeyHRP = "xsecret" ) + +// ToTestnetHRP makes HRPs testnet specified. +func ToTestnetHRP() { + AddressHRP = "tpc" + PublicKeyHRP = "tpublic" + PrivateKeyHRP = "tsecret" + XPublicKeyHRP = "txpublic" + XPrivateKeyHRP = "txsecret" +} diff --git a/wallet/wallet.go b/wallet/wallet.go index 790bf5b17..83a863bea 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -134,11 +134,7 @@ func Create(walletPath, mnemonic, password string, chain genesis.ChainType, func newWallet(walletPath string, store *Store, offline bool, option *walletOpt) (*Wallet, error) { if !store.Network.IsMainnet() { - crypto.AddressHRP = "tpc" - crypto.PublicKeyHRP = "tpublic" - crypto.PrivateKeyHRP = "tsecret" - crypto.XPublicKeyHRP = "txpublic" - crypto.XPrivateKeyHRP = "txsecret" + crypto.ToTestnetHRP() } client := newGrpcClient(option.timeout, option.servers)