|
42 | 42 |
|
43 | 43 | // useLedger indicates that the Ledger device should be used. |
44 | 44 | useLedger bool |
| 45 | + |
| 46 | + // noAddress indicates that the address should not be shown when printing a key. |
| 47 | + // This matches the old behavior of the read cmd. |
| 48 | + noAddress bool |
45 | 49 | ) |
46 | 50 |
|
47 | 51 | // walletCmd represents the wallet command. |
@@ -145,7 +149,7 @@ sure the device is connected, unlocked, and the Spacemesh app is open.`, |
145 | 149 |
|
146 | 150 | // readCmd reads an existing wallet file. |
147 | 151 | var readCmd = &cobra.Command{ |
148 | | - Use: "read [wallet file] [--full/-f] [--private/-p] [--parent] [--base58] [--hex]", |
| 152 | + Use: "read [wallet file] [--full/-f] [--private/-p] [--parent] [--base58] [--hex] [--no-address]", |
149 | 153 | DisableFlagsInUseLine: true, |
150 | 154 | Short: "Reads an existing wallet file", |
151 | 155 | Long: `This command can be used to verify whether an existing wallet file can be |
@@ -176,8 +180,11 @@ only child keys).`, |
176 | 180 | {Number: 1, WidthMax: maxWidth, WidthMaxEnforcer: widthEnforcer}, |
177 | 181 | } |
178 | 182 |
|
179 | | - // TODO: add spacemesh address format (bech32) |
180 | | - // https://github.com/spacemeshos/smcli/issues/38 |
| 183 | + if !noAddress { |
| 184 | + header = append(header[:3], header[2:]...) |
| 185 | + header[2] = "address" |
| 186 | + } |
| 187 | + |
181 | 188 | if printPrivate { |
182 | 189 | caption = append(caption, fmt.Sprintf("Mnemonic: %s", w.Mnemonic())) |
183 | 190 | header = append(header[:2], header[1:]...) |
@@ -218,55 +225,42 @@ only child keys).`, |
218 | 225 | } |
219 | 226 | } |
220 | 227 |
|
221 | | - privKeyEncoder := func(privKey []byte) string { |
222 | | - if len(privKey) == 0 { |
223 | | - return "(none)" |
| 228 | + addRow := func(account *wallet.EDKeyPair) { |
| 229 | + row := make([]interface{}, 0, 6) // Row len is 4 w/o address, up to 6 w/ priv key. |
| 230 | + row = append(row, encoder(account.Public)) |
| 231 | + |
| 232 | + if printPrivate { |
| 233 | + privKey := "(none)" |
| 234 | + if len(account.Private) > 0 { |
| 235 | + privKey = encoder(account.Private) |
| 236 | + } |
| 237 | + |
| 238 | + row = append(row, privKey) |
224 | 239 | } |
225 | | - return encoder(privKey) |
| 240 | + |
| 241 | + row = append(row, account.Path.String()) |
| 242 | + |
| 243 | + if !noAddress { |
| 244 | + row = append(row, types.GenerateAddress(account.Public).String()) |
| 245 | + } |
| 246 | + |
| 247 | + row = append(row, account.DisplayName, account.Created) |
| 248 | + |
| 249 | + t.AppendRow(row) |
226 | 250 | } |
227 | 251 |
|
228 | 252 | // print the master account |
229 | 253 | if printParent { |
230 | | - master := w.Secrets.MasterKeypair |
231 | | - if master != nil { |
232 | | - if printPrivate { |
233 | | - t.AppendRow(table.Row{ |
234 | | - encoder(master.Public), |
235 | | - privKeyEncoder(master.Private), |
236 | | - master.Path.String(), |
237 | | - master.DisplayName, |
238 | | - master.Created, |
239 | | - }) |
240 | | - } else { |
241 | | - t.AppendRow(table.Row{ |
242 | | - encoder(master.Public), |
243 | | - master.Path.String(), |
244 | | - master.DisplayName, |
245 | | - master.Created, |
246 | | - }) |
247 | | - } |
| 254 | + if master := w.Secrets.MasterKeypair; master != nil { |
| 255 | + addRow(master) |
248 | 256 | } |
249 | 257 | } |
250 | 258 |
|
251 | 259 | // print child accounts |
252 | 260 | for _, a := range w.Secrets.Accounts { |
253 | | - if printPrivate { |
254 | | - t.AppendRow(table.Row{ |
255 | | - encoder(a.Public), |
256 | | - privKeyEncoder(a.Private), |
257 | | - a.Path.String(), |
258 | | - a.DisplayName, |
259 | | - a.Created, |
260 | | - }) |
261 | | - } else { |
262 | | - t.AppendRow(table.Row{ |
263 | | - encoder(a.Public), |
264 | | - a.Path.String(), |
265 | | - a.DisplayName, |
266 | | - a.Created, |
267 | | - }) |
268 | | - } |
| 261 | + addRow(a) |
269 | 262 | } |
| 263 | + |
270 | 264 | t.Render() |
271 | 265 | }, |
272 | 266 | } |
@@ -316,6 +310,7 @@ func init() { |
316 | 310 | readCmd.Flags().BoolVar(&printBase58, "base58", false, "Print keys in base58 (rather than bech32)") |
317 | 311 | readCmd.Flags().BoolVar(&printHex, "hex", false, "Print keys in hex (rather than bech32)") |
318 | 312 | readCmd.Flags().BoolVar(&printParent, "parent", false, "Print parent key (not only child keys)") |
| 313 | + readCmd.Flags().BoolVar(&noAddress, "no-address", false, "Do not print the address associated with the key") |
319 | 314 | readCmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "enable debug mode") |
320 | 315 | createCmd.Flags().BoolVarP(&useLedger, "ledger", "l", false, "Create a wallet using a Ledger device") |
321 | 316 | addrCmd.Flags().BoolVar(&printParent, "parent", false, "Print parent address (not only child addresses)") |
|
0 commit comments