@@ -4,20 +4,19 @@ import (
44 "bufio"
55 "fmt"
66 "path/filepath"
7- "text/tabwriter"
87
98 "github.com/cosmos/cosmos-sdk/client/flags"
109 "github.com/cosmos/cosmos-sdk/client/input"
11- "github.com/cosmos/cosmos-sdk/crypto/hd"
10+ cryptohd "github.com/cosmos/cosmos-sdk/crypto/hd"
1211 "github.com/cosmos/cosmos-sdk/crypto/keyring"
1312 sdk "github.com/cosmos/cosmos-sdk/types"
1413 "github.com/cosmos/go-bip39"
1514 "github.com/pkg/errors"
16- hubtypes "github.com/sentinel-official/hub/types"
1715 "github.com/spf13/cobra"
1816 "github.com/spf13/viper"
1917
2018 "github.com/sentinel-official/dvpn-node/types"
19+ "github.com/sentinel-official/dvpn-node/utils"
2120)
2221
2322func KeysCmd () * cobra.Command {
@@ -121,27 +120,20 @@ func keysAdd() *cobra.Command {
121120 }
122121
123122 var (
124- hdPath = hd . CreateHDPath ( sdk .GetConfig ().GetCoinType (), account , index )
125- algorithms , _ = kr . SupportedAlgorithms ( )
123+ coinType = sdk .GetConfig ().GetCoinType ()
124+ path = cryptohd . CreateHDPath ( coinType , account , index )
126125 )
127126
128- algorithm , err := keyring . NewSigningAlgoFromString ( string ( hd . Secp256k1Type ), algorithms )
127+ key , err := kr . NewAccount ( name , mnemonic , "" , path . String ( ), cryptohd . Secp256k1 )
129128 if err != nil {
130129 return err
131130 }
132131
133- key , err := kr .NewAccount (name , mnemonic , "" , hdPath .String (), algorithm )
134- if err != nil {
135- return err
136- }
137-
138- _ , _ = fmt .Fprintf (cmd .ErrOrStderr (), "operator: %s\n " , key .GetAddress ())
139- _ , _ = fmt .Fprintf (cmd .ErrOrStderr (), "address: %s\n " , hubtypes .NodeAddress (key .GetAddress ()))
140- _ , _ = fmt .Fprintf (cmd .ErrOrStderr (), "\n " )
141132 _ , _ = fmt .Fprintf (cmd .ErrOrStderr (), "**Important** write this mnemonic phrase in a safe place\n " )
142133 _ , _ = fmt .Fprintf (cmd .ErrOrStderr (), "%s\n " , mnemonic )
134+ _ , _ = fmt .Fprintf (cmd .ErrOrStderr (), "\n " )
143135
144- return nil
136+ return utils . WriteKeys ( cmd . OutOrStdout (), key )
145137 },
146138 }
147139
@@ -202,10 +194,7 @@ func keysShow() *cobra.Command {
202194 return err
203195 }
204196
205- fmt .Printf ("operator: %s\n " , key .GetAddress ())
206- fmt .Printf ("address: %s\n " , hubtypes .NodeAddress (key .GetAddress ()))
207-
208- return nil
197+ return utils .WriteKeys (cmd .OutOrStdout (), key )
209198 },
210199 }
211200
@@ -257,16 +246,7 @@ func keysList() *cobra.Command {
257246 return err
258247 }
259248
260- w := tabwriter .NewWriter (cmd .OutOrStdout (), 1 , 1 , 1 , ' ' , 0 )
261- for _ , key := range keys {
262- _ , _ = fmt .Fprintf (w , "%s\t %s\t %s\n " ,
263- key .GetName (),
264- key .GetAddress (),
265- hubtypes .NodeAddress (key .GetAddress ().Bytes ()),
266- )
267- }
268-
269- return w .Flush ()
249+ return utils .WriteKeys (cmd .OutOrStdout (), keys ... )
270250 },
271251 }
272252
0 commit comments