Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gm hermes keys command when hdpath is set #976

Merged
merged 6 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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 @@ -27,6 +29,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

## v0.3.2
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 @@ -48,17 +48,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 @@ -692,6 +704,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 = 'naive'
Expand Down Expand Up @@ -726,14 +742,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