Skip to content

Commit

Permalink
Fix gm hermes keys command when hdpath is set (#976)
Browse files Browse the repository at this point in the history
* Fix gm hermes keys command when hdpath is set

* Update CHANGELOG.md

Co-authored-by: Romain Ruetschi <romain@informal.systems>

* Update scripts/gm/CHANGELOG.md

Co-authored-by: Romain Ruetschi <romain@informal.systems>

* Updated stoml required version

Co-authored-by: Romain Ruetschi <romain@informal.systems>
  • Loading branch information
greg-szabo and romac committed May 28, 2021
1 parent 5067621 commit ef85be3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

- [ibc-relayer]
- Fix for a client worker bug; Hermes `start` returns error if no chain is reachable ([#972])
- [gaia-manager]
- Import hermes keys properly even if wallet HD derivation path is set ([#975])

### BREAKING CHANGES

Expand All @@ -30,6 +32,7 @@
[#871]: https://github.com/informalsystems/ibc-rs/issues/871
[#911]: https://github.com/informalsystems/ibc-rs/issues/911
[#972]: https://github.com/informalsystems/ibc-rs/issues/972
[#975]: https://github.com/informalsystems/ibc-rs/issues/975
[#983]: https://github.com/informalsystems/ibc-rs/issues/983
[#996]: https://github.com/informalsystems/ibc-rs/issues/996

Expand Down
18 changes: 18 additions & 0 deletions scripts/gm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Gaiad Manager Change Log

## v0.0.2

### BUGFIXES
- Import hermes keys properly even if hdpath is set ([#975])

### FEATURES
- Introduced [CHANGELOG](https://github.com/informalsystems/ibc-rs/blob/master/scripts/gm/CHANGELOG.md) file.

[#975]: https://github.com/informalsystems/ibc-rs/issues/975

## v0.0.1

### FEATURES
- Initial release ([#902])

[#902]: https://github.com/informalsystems/ibc-rs/issues/902
61 changes: 51 additions & 10 deletions scripts/gm/bin/lib-gm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if [ "${DEBUG:-}" == "2" ]; then
fi

version() {
echo "v0.0.1"
echo "v0.0.2"
}

config_defaults() {
Expand Down Expand Up @@ -50,17 +50,29 @@ install() {
}

enforce_requirements() {
if [ -z "$(which stoml)" ]; then
exit_with_error "missing stoml, install it from https://github.com/freshautomations/stoml/releases"
fi
if [ -z "$(which sconfig)" ]; then
exit_with_error "missing sconfig, install it from https://github.com/freshautomations/sconfig/releases"
fi
if [ -z "$(which sed)" ]; then
exit_with_error "missing sed, please install it (this requirement will be removed in the future)"
SED="$(which sed)"
if [ -z "$SED" ]; then
exit_with_error "missing sed, please install it"
fi
if [ -z "$(which tr)" ]; then
exit_with_error "missing tr, please install it (this requirement will be removed in the future)"
exit_with_error "missing tr, please install it"
fi
if [ -z "$(which dirname)" ]; then
exit_with_error "missing dirname, please install it"
fi
STOML="$(which stoml)"
if [ -z "$STOML" ]; then
exit_with_error "missing stoml, install it from https://github.com/freshautomations/stoml/releases"
fi
STOML_VERSION="$("$STOML" --version | "$SED" 's/^stoml version //')"
MAJOR="$(echo "${STOML_VERSION}" | "$SED" "s/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)$/\1/")"
MINOR="$(echo "${STOML_VERSION}" | "$SED" "s/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)$/\2/")"
PATCH="$(echo "${STOML_VERSION}" | "$SED" "s/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)$/\3/")"
if [ $((MAJOR)) -eq 0 ] && [ $((MINOR)) -lt 6 ] || { [ $((MAJOR)) -eq 0 ] && [ $((MINOR)) -eq 6 ] && [ $((PATCH)) -lt 2 ]; }; then
exit_with_error "stoml too old, install 0.6.2 or newer from https://github.com/freshautomations/stoml/releases"
fi
}

Expand Down Expand Up @@ -696,6 +708,10 @@ list_keys() {
}

hermes_config() {
HERMES_DIR="$(dirname "$GLOBAL_HERMES_CONFIG")"
if [ ! -d "$HERMES_DIR" ]; then
mkdir -p "$HERMES_DIR"
fi
cat <<EOF > "$GLOBAL_HERMES_CONFIG"
[global]
strategy = '${GLOBAL_HERMES_STRATEGY}'
Expand Down Expand Up @@ -730,14 +746,39 @@ EOF
done
}

# This is a helper function that extracts the coinType from an absolute hdpath (m/44'/118'/0'/0/0) for hermes.
get_cointype() {
WALLET_HDPATH="$(get_wallet_hdpath "$1")"
if [ -n "$WALLET_HDPATH" ]; then
COINTYPE=$(echo "$WALLET_HDPATH" | sed 's,^m/[0-9][0-9]*'\''/\([0-9][0-9]*\)'\''/[0-9][0-9]*'\''/[0-9][0-9]*/[0-9][0-9]*$,\1,')
if [ "$COINTYPE" != "$WALLET_HDPATH" ]; then
echo "$COINTYPE"
fi
fi
}

hermes_keys() {
ID="$(get_chain_id "$1")"
NETWORK_HOME_DIR="$(get_home_dir "$ID")"
test -x "$GLOBAL_HERMES_BINARY" || exit_with_error "hermes binary \"${GLOBAL_HERMES_BINARY}\" not found, check your gm.toml config."
if [ -z "$GLOBAL_HERMES_CONFIG" ]; then
"$GLOBAL_HERMES_BINARY" keys add "$ID" -f "${NETWORK_HOME_DIR}/wallet_seed.json"
WALLET_HDPATH="$(get_wallet_hdpath "$1")"
COINTYPE="$(get_cointype "$1")"
if [ -n "$WALLET_HDPATH" ] && [ -z "${COINTYPE}" ]; then
warn "cointype could not be parsed. Reverting to default coin type."
fi
if [ -z "${COINTYPE}" ]; then
if [ -z "$GLOBAL_HERMES_CONFIG" ]; then
"$GLOBAL_HERMES_BINARY" keys add "$ID" -f "${NETWORK_HOME_DIR}/wallet_seed.json"
else
"$GLOBAL_HERMES_BINARY" -c "$GLOBAL_HERMES_CONFIG" keys add "$ID" -f "${NETWORK_HOME_DIR}/wallet_seed.json"
fi
else
"$GLOBAL_HERMES_BINARY" -c "$GLOBAL_HERMES_CONFIG" keys add "$ID" -f "${NETWORK_HOME_DIR}/wallet_seed.json"
MNEMONIC="$(stoml "${NETWORK_HOME_DIR}/wallet_seed.json" "mnemonic")"
if [ -z "$GLOBAL_HERMES_CONFIG" ]; then
"$GLOBAL_HERMES_BINARY" keys restore "$ID" -t "$COINTYPE" -m "$MNEMONIC"
else
"$GLOBAL_HERMES_BINARY" -c "$GLOBAL_HERMES_CONFIG" keys restore "$ID" -t "$COINTYPE" -m "$MNEMONIC"
fi
fi
}

Expand Down

0 comments on commit ef85be3

Please sign in to comment.