-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: set finality contract enabled value (#35)
- Loading branch information
Showing
7 changed files
with
120 additions
and
37 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
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,6 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
# setting the finality contract enabled value | ||
docker compose -f docker/docker-compose-babylon-integration.yml up -d toggle-cw-killswitch | ||
docker logs -f toggle-cw-killswitch |
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,34 @@ | ||
#!/bin/bash | ||
set -uo pipefail | ||
|
||
# Function to handle pending transactions | ||
wait_for_tx() { | ||
local tx_hash=$1 | ||
local max_attempts=$2 | ||
local interval=$3 | ||
local attempt=0 | ||
|
||
while [ $attempt -lt $max_attempts ]; do | ||
# Query with explicit error handling | ||
if output=$(babylond query tx "$tx_hash" \ | ||
--chain-id "$BABYLON_CHAIN_ID" \ | ||
--node "$BABYLON_RPC_URL" -o json 2>&1); then | ||
echo "Transaction found" | ||
return 0 | ||
else | ||
# Command failed, check if it's because tx is pending | ||
if echo "$output" | grep -q "Internal error: tx ($tx_hash) not found"; then | ||
echo "Transaction pending..." | ||
sleep "$interval" | ||
((attempt++)) | ||
continue | ||
fi | ||
# Other error occurred | ||
echo "Query failed: $output" | ||
return 1 | ||
fi | ||
done | ||
|
||
echo "Timeout after $max_attempts attempts waiting for transaction $tx_hash to be available." | ||
return 1 | ||
} |
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,53 @@ | ||
#!/bin/bash | ||
set -uo pipefail | ||
|
||
source "./common.sh" | ||
|
||
# Set keyring directory | ||
KEYRING_DIR=/home/.babylond | ||
# Set contract address output directory | ||
CONTRACT_DIR=/home/.deploy | ||
# Get the IS_ENABLED environment variable | ||
echo "Setting enabled value to $IS_ENABLED" | ||
|
||
# Read the contract address | ||
CONTRACT_ADDR=$(cat $CONTRACT_DIR/contract-address.txt | tr -d '[:space:]') | ||
echo "Contract address: $CONTRACT_ADDR" | ||
|
||
# Set the is_enabled value in the contract | ||
SET_ENABLED_TX_OUTPUT=$(babylond tx wasm execute $CONTRACT_ADDR \ | ||
'{"set_enabled":{"enabled":'$IS_ENABLED'}}' \ | ||
--gas-prices 0.2ubbn \ | ||
--gas auto \ | ||
--gas-adjustment 1.3 \ | ||
--from $BABYLON_PREFUNDED_KEY \ | ||
--keyring-dir $KEYRING_DIR \ | ||
--chain-id $BABYLON_CHAIN_ID \ | ||
--node $BABYLON_RPC_URL \ | ||
--keyring-backend test \ | ||
-o json -y) | ||
echo "$SET_ENABLED_TX_OUTPUT" | ||
SET_ENABLED_TX_HASH=$(echo "$SET_ENABLED_TX_OUTPUT" | jq -r '.txhash') | ||
echo "Set enabled tx hash: $SET_ENABLED_TX_HASH" | ||
|
||
# Wait for the transaction to be included in a block | ||
if ! wait_for_tx "$SET_ENABLED_TX_HASH" 10 3; then | ||
echo "Failed to set enabled value in contract - transaction failed" | ||
exit 1 | ||
fi | ||
|
||
# Query and verify the enabled state | ||
QUERY_ENABLED_VALUE=$(babylond query wasm contract-state smart $CONTRACT_ADDR \ | ||
'{"is_enabled":{}}' \ | ||
--chain-id $BABYLON_CHAIN_ID \ | ||
--node $BABYLON_RPC_URL \ | ||
-o json \ | ||
| jq -r '.data') | ||
echo "Query enabled value: $QUERY_ENABLED_VALUE" | ||
|
||
if [ "$QUERY_ENABLED_VALUE" != "$IS_ENABLED" ]; then | ||
echo "Failed to set enabled value in contract - value mismatch (expected: $IS_ENABLED, got: $QUERY_ENABLED_VALUE)" | ||
exit 1 | ||
fi | ||
echo "Successfully set enabled value to $IS_ENABLED" | ||
echo |