-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
SOURCE_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" | ||
|
||
print_help() { | ||
cat <<-EOF | ||
Get the current lifecycle of the SNS as a descriptive string rather than a | ||
number. | ||
EOF | ||
} | ||
|
||
declare -A LIFECYCLE_MAP=( | ||
[1]="pending" | ||
[2]="open" | ||
[3]="committed" | ||
[4]="aborted" | ||
[5]="adopted" | ||
) | ||
|
||
# Source the clap.bash file --------------------------------------------------- | ||
source "$SOURCE_DIR/clap.bash" | ||
# Define options | ||
clap.define short=n long=network desc="The dfx network to use" variable=DFX_NETWORK default="local" | ||
clap.define short=i long=identity desc="The dfx identity to use" variable=DFX_IDENTITY default="$(dfx identity whoami)" | ||
# Source the output file ---------------------------------------------------------- | ||
source "$(clap.build)" | ||
|
||
export DFX_NETWORK | ||
export DFX_IDENTITY | ||
|
||
LIFECYCLE_ID="$(dfx canister call sns_swap get_lifecycle '(record{})' | idl2json | jq -r '.lifecycle[0]')" | ||
|
||
echo "${LIFECYCLE_MAP[$LIFECYCLE_ID]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
SOURCE_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" | ||
PATH="$SOURCE_DIR:$PATH" | ||
|
||
print_help() { | ||
cat <<-EOF | ||
Wait up to 2 minutes for the current SNS to reach the given lifecycle. | ||
EOF | ||
} | ||
|
||
LIFECYCLES=( | ||
"pending" | ||
"open" | ||
"committed" | ||
"aborted" | ||
"adopted" | ||
) | ||
|
||
LIFECYCLE_LIST=$(printf " %s," "${LIFECYCLES[@]}") | ||
LIFECYCLE_LIST=${LIFECYCLE_LIST%,*} | ||
|
||
# Source the clap.bash file --------------------------------------------------- | ||
source "$SOURCE_DIR/clap.bash" | ||
# Define options | ||
clap.define short=l long=lifecycle desc="One of $LIFECYCLE_LIST" variable=LIFECYCLE default="open" | ||
clap.define short=n long=network desc="The dfx network to use" variable=DFX_NETWORK default="local" | ||
clap.define short=i long=identity desc="The dfx identity to use" variable=DFX_IDENTITY default="$(dfx identity whoami)" | ||
# Source the output file ---------------------------------------------------------- | ||
source "$(clap.build)" | ||
|
||
if [[ ! "${LIFECYCLE_LIST}" =~ " ${LIFECYCLE:-}," ]]; then | ||
echo "ERROR: Unknown lifecycle '$LIFECYCLE'" | ||
echo "Please choose one of: $LIFECYCLE_LIST" | ||
exit 1 | ||
fi | ||
|
||
current_lifecycle=$(dfx-sns-get-lifecycle --network "$DFX_NETWORK" --identity "$DFX_IDENTITY") | ||
|
||
echo "Current lifecycle: $current_lifecycle" | ||
echo "Waiting for lifecycle: $LIFECYCLE" | ||
|
||
for ((try = 60; try > 0; try--)); do | ||
if [[ "$current_lifecycle" == "$LIFECYCLE" ]]; then | ||
echo "Lifecycle reached." | ||
exit 0 | ||
fi | ||
sleep 2 | ||
current_lifecycle=$(dfx-sns-get-lifecycle --network "$DFX_NETWORK" --identity "$DFX_IDENTITY") | ||
done | ||
|
||
echo "ERROR: Lifecycle not reached after 2 minutes." | ||
exit 1 |