Skip to content

Commit

Permalink
fix(keys): align key retrieval function with key creation (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs committed Sep 18, 2024
1 parent 838b0a0 commit d6ceb6c
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
9 changes: 5 additions & 4 deletions cmd/config/export/bech32.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package export

import (
"path/filepath"
"strings"

"github.com/dymensionxyz/roller/cmd/consts"
Expand All @@ -12,9 +11,11 @@ import (
func getBech32Prefix(rlpCfg config.RollappConfig) (string, error) {
rollappSeqAddrInfo, err := utils.GetAddressInfoBinary(
utils.KeyConfig{
Dir: filepath.Join(rlpCfg.Home, consts.ConfigDirName.Rollapp),
ID: consts.KeysIds.RollappSequencer,
}, rlpCfg.RollappBinary,
Dir: consts.ConfigDirName.Rollapp,
ID: consts.KeysIds.RollappSequencer,
ChainBinary: consts.Executables.RollappEVM,
Type: "",
}, rlpCfg.Home,
)
if err != nil {
return "", err
Expand Down
1 change: 0 additions & 1 deletion cmd/eibc/fulfill/order/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func Cmd() *cobra.Command {
pterm.Error.Println("failed to fulfill order: ", err)
return
}
fmt.Println(gCmd.String())

txOutput, err := bash.ExecCommandWithInput(gCmd, "signatures")
if err != nil {
Expand Down
14 changes: 8 additions & 6 deletions cmd/keys/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ func Cmd() *cobra.Command {

hubSeqInfo, err := utils.GetAddressInfoBinary(
utils.KeyConfig{
Dir: filepath.Join(rollappConfig.Home, consts.ConfigDirName.HubKeys),
ID: consts.KeysIds.HubSequencer,
}, consts.Executables.Dymension,
Dir: consts.ConfigDirName.HubKeys,
ChainBinary: consts.Executables.Dymension,
ID: consts.KeysIds.HubSequencer,
}, rollappConfig.Home,
)
errorhandling.PrettifyErrorIfExists(err)
addresses = append(
Expand All @@ -58,9 +59,10 @@ func Cmd() *cobra.Command {

raSeqInfo, err := utils.GetAddressInfoBinary(
utils.KeyConfig{
Dir: filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp),
ID: consts.KeysIds.RollappSequencer,
}, rollappConfig.RollappBinary,
Dir: filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp),
ChainBinary: consts.Executables.RollappEVM,
ID: consts.KeysIds.RollappSequencer,
}, rollappConfig.Home,
)
errorhandling.PrettifyErrorIfExists(err)
addresses = append(
Expand Down
2 changes: 1 addition & 1 deletion cmd/rollapp/sequencer/metadata/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func Cmd() *cobra.Command {
Type: consts.SDK_ROLLAPP,
}

seqAddrInfo, err := utils.GetAddressInfoBinary(hubSeqKC, hubSeqKC.ChainBinary)
seqAddrInfo, err := utils.GetAddressInfoBinary(hubSeqKC, rollappConfig.Home)
if err != nil {
pterm.Error.Println("failed to get address info: ", err)
return
Expand Down
2 changes: 1 addition & 1 deletion cmd/rollapp/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func Cmd() *cobra.Command {
ChainBinary: consts.Executables.Dymension,
Type: consts.SDK_ROLLAPP,
}
seqAddrInfo, err := utils.GetAddressInfoBinary(hubSeqKC, hubSeqKC.ChainBinary)
seqAddrInfo, err := utils.GetAddressInfoBinary(hubSeqKC, rollappConfig.Home)
if err != nil {
pterm.Error.Println("failed to get address info: ", err)
return
Expand Down
6 changes: 3 additions & 3 deletions cmd/utils/key_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ func ParseAddressFromOutput(output bytes.Buffer) (*KeyInfo, error) {
return key, nil
}

func GetAddressInfoBinary(keyConfig KeyConfig, binaryPath string) (*KeyInfo, error) {
func GetAddressInfoBinary(keyConfig KeyConfig, home string) (*KeyInfo, error) {
showKeyCommand := exec.Command(
binaryPath,
keyConfig.ChainBinary,
"keys",
"show",
keyConfig.ID,
"--keyring-backend",
"test",
"--keyring-dir",
keyConfig.Dir,
filepath.Join(home, keyConfig.Dir),
"--output",
"json",
)
Expand Down
4 changes: 2 additions & 2 deletions utils/eibc/eibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ func GetFulfillOrderCmd(orderId, fee string, hd consts.HubData) (*exec.Cmd, erro
func EnsureWhaleAccount() error {
home, _ := os.UserHomeDir()
kc := utils.KeyConfig{
Dir: filepath.Join(home, consts.ConfigDirName.Eibc),
Dir: consts.ConfigDirName.Eibc,
ID: consts.KeysIds.Eibc,
ChainBinary: consts.Executables.Dymension,
Type: "",
}

_, err := utils.GetAddressInfoBinary(kc, consts.Executables.Dymension)
_, err := utils.GetAddressInfoBinary(kc, home)
if err != nil {
pterm.Info.Println("whale account not found in the keyring, creating it now")
addressInfo, err := keys.CreateAddressBinary(kc, home)
Expand Down

0 comments on commit d6ceb6c

Please sign in to comment.