-
Notifications
You must be signed in to change notification settings - Fork 0
/
address.go
38 lines (34 loc) · 1.03 KB
/
address.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/cmwaters/maelstrom/client/cmd/config"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/spf13/cobra"
)
var addressCmd = &cobra.Command{
Use: "address",
Short: "Get the address of the client",
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := config.Load(configFileName)
if err != nil {
return fmt.Errorf("failed to get config: %w", err)
}
cdc := encoding.MakeConfig(app.ModuleEncodingRegisters...)
keys, err := keyring.New(cfg.KeyName, keyring.BackendTest, cfg.KeyringDir, nil, cdc.Codec)
if err != nil {
return fmt.Errorf("failed to create new keyring: %w", err)
}
record, err := keys.Key(cfg.KeyName)
if err != nil {
return fmt.Errorf("failed to retrieve key: %w", err)
}
address, err := record.GetAddress()
if err != nil {
return fmt.Errorf("failed to get address from key record: %w", err)
}
fmt.Println(address.String())
return nil
},
}