Skip to content

Commit

Permalink
Merge pull request #108 from Agoric/ms/check-chain-status-before-cont…
Browse files Browse the repository at this point in the history
…ract-start

Check for Blocks before Contract Start and Adding Format Script
  • Loading branch information
amessbee authored Jan 9, 2025
2 parents c2bea82 + 60b9b18 commit f551a3e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"docker:bash": "docker compose exec agd bash",
"docker:make": "docker compose exec agd make -C /workspace/contract",
"make:help": "make list",
"start": "yarn docker:make clean start-contract",
"start": "./scripts/wait-for-chain.sh && yarn docker:make clean start-contract",
"build": "agoric run scripts/build-contract-deployer.js",
"test": "ava --verbose",
"lint": "tsc && eslint '**/*.js'",
Expand Down
33 changes: 33 additions & 0 deletions contract/scripts/wait-for-chain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Function to check if we see a pattern of block commits
check_block_pattern() {
local count=0
local required_patterns=3 # Number of block patterns we want to see

while IFS= read -r line; do
echo -n "." # Show progress

if [[ $line =~ "block-manager: block "[0-9]+" commit" ]]; then
((count++))
if [ $count -ge $required_patterns ]; then
echo
echo "$line"
return 0 # Success
fi
fi
done

return 1 # Pattern not found
}

echo "Waiting for blockchain to start..."
yarn docker:logs | check_block_pattern

if [ $? -eq 0 ]; then
echo "Blockchain is running and producing blocks..."
exit 0
else
echo "Failed to detect blockchain activity\n Run yarn start:docker to start the blockchain first!"
exit 1
fi

0 comments on commit f551a3e

Please sign in to comment.