Skip to content
Open
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
89 changes: 89 additions & 0 deletions check-dex-status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash
# GalaSwap DEX Status Check Script
# Usage: ./check-dex-status.sh

echo "πŸ” GALASWAP DEX STATUS CHECK"
echo "============================"
echo "Timestamp: $(date)"
echo ""

# TODO: Replace these with your actual GalaChain connection details
CHANNEL_NAME="product-channel"
CHAINCODE_NAME="basic-product"
PEER_ADDRESS="peer0.your-org.com:7051"

# Method 1: Using gala-cli (if available)
if command -v gala-cli &> /dev/null; then
echo "πŸ“‘ Checking DEX status via gala-cli..."

# Try to call checkPaused - if it throws an error, DEX is paused
if gala-cli chaincode query \
--channel-name "$CHANNEL_NAME" \
--chaincode-name "$CHAINCODE_NAME" \
--function-name "checkPaused" \
--args "" \
--peer-addresses "$PEER_ADDRESS" 2>/dev/null; then

echo "βœ… DEX STATUS: OPERATIONAL"
echo "🟒 All trading functions are active"
else
echo "πŸ”΄ DEX STATUS: PAUSED"
echo "🚫 All trading functions are blocked"
fi

# Method 2: Using peer CLI (fallback)
elif command -v peer &> /dev/null; then
echo "πŸ“‘ Checking DEX status via peer CLI..."

if peer chaincode query \
-C "$CHANNEL_NAME" \
-n "$CHAINCODE_NAME" \
-c "{\"function\":\"checkPaused\",\"Args\":[]}" 2>/dev/null; then

echo "βœ… DEX STATUS: OPERATIONAL"
echo "🟒 All trading functions are active"
else
echo "πŸ”΄ DEX STATUS: PAUSED"
echo "🚫 All trading functions are blocked"
fi

# Method 3: API call (if CLI tools not available)
else
echo "πŸ“‘ Checking DEX status via API..."

# TODO: Replace with your actual API endpoint and auth
API_ENDPOINT="https://your-galachain-api.com/api/chaincode/query"
AUTH_TOKEN="your-admin-token"

if curl -X POST "$API_ENDPOINT" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AUTH_TOKEN" \
-d "{
\"chaincodeName\": \"$CHAINCODE_NAME\",
\"functionName\": \"checkPaused\",
\"args\": []
}" \
--fail \
--silent \
--show-error 2>/dev/null; then

echo "βœ… DEX STATUS: OPERATIONAL"
echo "🟒 All trading functions are active"
else
echo "πŸ”΄ DEX STATUS: PAUSED"
echo "🚫 All trading functions are blocked"
fi
fi

echo ""
echo "πŸ“‹ AVAILABLE COMMANDS:"
echo " πŸ›‘ Emergency pause: ./emergency-stop.sh"
echo " ▢️ Emergency resume: ./emergency-resume.sh"
echo " πŸ“Š Check status: ./check-dex-status.sh"
echo ""

# Show recent emergency log entries
if [ -f "emergency.log" ]; then
echo "πŸ“œ RECENT EMERGENCY ACTIONS:"
tail -5 emergency.log
fi
130 changes: 130 additions & 0 deletions emergency-resume.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/bin/bash
# GalaSwap DEX Emergency Resume Script
# Usage: ./emergency-resume.sh

set -e # Exit on any error

echo "πŸ”„ GALASWAP DEX EMERGENCY RESUME INITIATED"
echo "=========================================="
echo "Timestamp: $(date)"
echo "Executed by: $(whoami)"
echo "Host: $(hostname)"
echo ""

# Safety warnings
echo "⚠️ CRITICAL SAFETY CHECKS:"
echo "πŸ” Have you verified the security issue is resolved?"
echo "πŸ§ͺ Have you tested the fix thoroughly?"
echo "πŸ‘₯ Has the security team approved resume?"
echo "πŸ“‹ Have you documented the incident resolution?"
echo ""

# Multiple confirmation prompts for safety
echo "🚨 WARNING: This will resume ALL DEX operations!"
echo "Only proceed if you are absolutely certain it is safe."
echo ""
echo "Type 'RESUME' to confirm you want to resume operations:"
read CONFIRMATION

if [ "$CONFIRMATION" != "RESUME" ]; then
echo "❌ Resume cancelled - confirmation not received"
exit 1
fi

echo ""
echo "Final confirmation: Resume DEX operations now? (y/N)"
read FINAL_CONFIRMATION

if [ "$FINAL_CONFIRMATION" != "y" ] && [ "$FINAL_CONFIRMATION" != "Y" ]; then
echo "❌ Resume cancelled by user"
exit 1
fi

echo ""
echo "πŸ”„ Executing emergency resume..."

# TODO: Replace these with your actual GalaChain connection details
CHANNEL_NAME="product-channel"
CHAINCODE_NAME="basic-product"
PEER_ADDRESS="peer0.your-org.com:7051"

# Method 1: Using gala-cli (if available)
if command -v gala-cli &> /dev/null; then
echo "πŸ“‘ Using gala-cli to resume DEX..."

gala-cli chaincode invoke \
--channel-name "$CHANNEL_NAME" \
--chaincode-name "$CHAINCODE_NAME" \
--function-name "resumeDex" \
--args "" \
--peer-addresses "$PEER_ADDRESS"

RESUME_RESULT=$?

# Method 2: Using peer CLI (fallback)
elif command -v peer &> /dev/null; then
echo "πŸ“‘ Using peer CLI to resume DEX..."

peer chaincode invoke \
-o orderer.your-domain.com:7050 \
-C "$CHANNEL_NAME" \
-n "$CHAINCODE_NAME" \
--peerAddresses "$PEER_ADDRESS" \
-c "{\"function\":\"resumeDex\",\"Args\":[]}"

RESUME_RESULT=$?

# Method 3: API call (if CLI tools not available)
else
echo "πŸ“‘ Using API call to resume DEX..."

# TODO: Replace with your actual API endpoint and auth
API_ENDPOINT="https://your-galachain-api.com/api/chaincode/invoke"
AUTH_TOKEN="your-admin-token"

curl -X POST "$API_ENDPOINT" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AUTH_TOKEN" \
-d "{
\"chaincodeName\": \"$CHAINCODE_NAME\",
\"functionName\": \"resumeDex\",
\"args\": []
}" \
--fail \
--silent \
--show-error

RESUME_RESULT=$?
fi

# Check if resume was successful
if [ $RESUME_RESULT -eq 0 ]; then
echo ""
echo "βœ… DEX SUCCESSFULLY RESUMED!"
echo "🟒 All trading operations are now active"
echo ""
echo "πŸ“‹ NEXT STEPS:"
echo " 1. πŸ“Š Monitor system closely for 30 minutes"
echo " 2. πŸ“± Notify team of successful resume"
echo " 3. πŸ“’ Update user communications"
echo " 4. πŸ“ Complete incident report"
echo " 5. πŸ” Review incident response process"
echo ""
echo "πŸ“ˆ Monitor: ./check-dex-status.sh"
echo ""

# Log the resume action
echo "$(date): EMERGENCY RESUME - By: $(whoami)" >> emergency.log

else
echo ""
echo "❌ EMERGENCY RESUME FAILED!"
echo "🚨 DEX STATUS UNKNOWN - INVESTIGATE IMMEDIATELY"
echo ""
echo "πŸ”„ IMMEDIATE ACTIONS:"
echo " 1. πŸ“ž Contact technical team"
echo " 2. πŸ” Check system logs"
echo " 3. πŸ§ͺ Verify current pause status"
echo ""
exit 1
fi
128 changes: 128 additions & 0 deletions emergency-stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/bin/bash
# GalaSwap DEX Emergency Stop Script
# Usage: ./emergency-stop.sh [reason]

set -e # Exit on any error

echo "🚨 GALASWAP DEX EMERGENCY PAUSE INITIATED"
echo "=========================================="
echo "Timestamp: $(date)"
echo "Executed by: $(whoami)"
echo "Host: $(hostname)"

# Get emergency reason
if [ -n "$1" ]; then
REASON="$1"
else
echo ""
echo "Enter emergency reason (or press Enter for default):"
read REASON
fi

# Set default reason if none provided
if [ -z "$REASON" ]; then
REASON="EMERGENCY_STOP_$(date +%Y%m%d_%H%M%S)"
fi

echo ""
echo "πŸ”΄ PAUSING DEX WITH REASON: $REASON"
echo "⚠️ This will block ALL DEX operations immediately!"
echo ""

# Confirmation prompt
echo "Continue with emergency pause? (y/N)"
read CONFIRMATION

if [ "$CONFIRMATION" != "y" ] && [ "$CONFIRMATION" != "Y" ]; then
echo "❌ Emergency pause cancelled by user"
exit 1
fi

echo ""
echo "πŸ”„ Executing emergency pause..."

# TODO: Replace these with your actual GalaChain connection details
CHANNEL_NAME="product-channel"
CHAINCODE_NAME="basic-product"
PEER_ADDRESS="peer0.your-org.com:7051"

# Method 1: Using gala-cli (if available)
if command -v gala-cli &> /dev/null; then
echo "πŸ“‘ Using gala-cli to pause DEX..."

gala-cli chaincode invoke \
--channel-name "$CHANNEL_NAME" \
--chaincode-name "$CHAINCODE_NAME" \
--function-name "pauseDex" \
--args "\"$REASON\"" \
--peer-addresses "$PEER_ADDRESS"

PAUSE_RESULT=$?

# Method 2: Using peer CLI (fallback)
elif command -v peer &> /dev/null; then
echo "πŸ“‘ Using peer CLI to pause DEX..."

peer chaincode invoke \
-o orderer.your-domain.com:7050 \
-C "$CHANNEL_NAME" \
-n "$CHAINCODE_NAME" \
--peerAddresses "$PEER_ADDRESS" \
-c "{\"function\":\"pauseDex\",\"Args\":[\"$REASON\"]}"

PAUSE_RESULT=$?

# Method 3: API call (if CLI tools not available)
else
echo "πŸ“‘ Using API call to pause DEX..."

# TODO: Replace with your actual API endpoint and auth
API_ENDPOINT="https://your-galachain-api.com/api/chaincode/invoke"
AUTH_TOKEN="your-admin-token"

curl -X POST "$API_ENDPOINT" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AUTH_TOKEN" \
-d "{
\"chaincodeName\": \"$CHAINCODE_NAME\",
\"functionName\": \"pauseDex\",
\"args\": [\"$REASON\"]
}" \
--fail \
--silent \
--show-error

PAUSE_RESULT=$?
fi

# Check if pause was successful
if [ $PAUSE_RESULT -eq 0 ]; then
echo ""
echo "βœ… DEX SUCCESSFULLY PAUSED!"
echo "πŸ”΄ All trading operations are now blocked"
echo ""
echo "πŸ“‹ NEXT STEPS:"
echo " 1. πŸ“± Notify emergency team immediately"
echo " 2. πŸ“Š Check system status and logs"
echo " 3. πŸ” Begin incident investigation"
echo " 4. πŸ“ Document incident details"
echo " 5. πŸ“’ Prepare user communication"
echo ""
echo "πŸ’‘ To resume operations: ./emergency-resume.sh"
echo ""

# Log the emergency action
echo "$(date): EMERGENCY PAUSE - Reason: $REASON - By: $(whoami)" >> emergency.log

else
echo ""
echo "❌ EMERGENCY PAUSE FAILED!"
echo "🚨 DEX MAY STILL BE OPERATIONAL - CRITICAL ISSUE"
echo ""
echo "πŸ”„ IMMEDIATE ACTIONS:"
echo " 1. πŸ“ž Contact technical team immediately"
echo " 2. πŸ”„ Try alternative pause method"
echo " 3. πŸ›‘ Consider network-level intervention"
echo ""
exit 1
fi
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@gala-chain/client": "~2.3.4",
"@gala-chain/test": "~2.3.4",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/decimal.js": "^0.0.32",
"@types/jest": "^29.5.12",
"@types/node": "18.11.9",
"@typescript-eslint/eslint-plugin": "^5.47.1",
Expand Down
Loading
Loading