11# Polkadot Bulletin Chain - Just Commands
2- # Install just: brew install just
3- # Run `just --list` to see all available commands
2+ #
3+ # See README.md for usage instructions.
4+
5+ # PID file locations
6+ PID_DIR := " /tmp/bulletin-pids"
47
58# Default recipe - run the complete PAPI workflow test
6- default : authorize-and-store
9+ default : run- authorize-and-store
710
811# Build the bulletin chain node in release mode
912build :
@@ -13,80 +16,191 @@ build:
1316npm-install :
1417 npm install
1518
16- # Test the complete workflow (builds, starts services, runs example, shuts down services)
17- # Parameters: api=[papi|pjs] - choose between Polkadot API (papi) or Polkadot JS (pjs)
18- authorize-and-store api = " papi": build npm-install
19+ # Initialize IPFS if not already initialized
20+ ipfs-init :
1921 #!/usr/bin/env bash
2022 set -e
2123
22- API_TYPE=" {{ api }} "
23-
24- if [[ " $API_TYPE" != " papi" && " $API_TYPE" != " pjs" ]]; then
25- echo " ❌ Error: api parameter must be 'papi' or 'pjs'"
24+ if [ -f " ../kubo/ipfs" ]; then
25+ IPFS_CMD=" ../kubo/ipfs"
26+ elif command -v ipfs &> / dev/ null; then
27+ IPFS_CMD=" ipfs"
28+ else
29+ echo " ❌ Error: IPFS not found."
2630 exit 1
2731 fi
2832
29- echo " 🚀 Starting $API_TYPE workflow test..."
30- echo " "
31-
32- # Check if IPFS is available
33- if ! command -v ipfs &> / dev/ null; then
34- echo " ❌ IPFS not found. Using local kubo binary..."
35- IPFS_CMD=" ./kubo/ipfs"
36- if [ ! -f " $IPFS_CMD" ]; then
37- echo " ❌ Error: Neither system IPFS nor ./kubo/ipfs found."
38- echo " Please install IPFS or download kubo to ./kubo/"
39- exit 1
40- fi
41- else
42- IPFS_CMD=" ipfs"
43- fi
33+ echo " 🔧 Using IPFS command: $IPFS_CMD"
4434
4535 # Initialize IPFS if needed
4636 if [ ! -d ~/ .ipfs ]; then
4737 echo " 📦 Initializing IPFS..."
4838 $IPFS_CMD init
39+ else
40+ echo " ✅ IPFS already initialized"
41+ fi
42+
43+ # Start IPFS daemon in background
44+ ipfs-start :
45+ #!/usr/bin/env bash
46+ set -e
47+
48+ mkdir -p {{ PID_DIR }}
49+
50+ if [ -f " ../kubo/ipfs" ]; then
51+ IPFS_CMD=" ../kubo/ipfs"
52+ elif command -v ipfs &> / dev/ null; then
53+ IPFS_CMD=" ipfs"
54+ else
55+ echo " ❌ Error: IPFS not found."
56+ exit 1
4957 fi
5058
51- # Start IPFS daemon in background
59+ echo " 🔧 Using IPFS command: $IPFS_CMD"
5260 echo " 📡 Starting IPFS daemon..."
5361 $IPFS_CMD daemon > / tmp/ ipfs-daemon.log 2 >&1 &
5462 IPFS_PID=$!
63+ echo $IPFS_PID > {{ PID_DIR }} / ipfs.pid
5564 echo " IPFS PID: $IPFS_PID"
65+ echo " Log: /tmp/ipfs-daemon.log"
5666 sleep 2
67+
68+ # Connect to IPFS nodes
69+ ipfs-connect :
70+ #!/usr/bin/env bash
71+ set -e
72+
73+ if [ -f " ../kubo/ipfs" ]; then
74+ IPFS_CMD=" ../kubo/ipfs"
75+ elif command -v ipfs &> / dev/ null; then
76+ IPFS_CMD=" ipfs"
77+ else
78+ echo " ❌ Error: IPFS not found."
79+ exit 1
80+ fi
81+
82+ echo " 🔧 Using IPFS command: $IPFS_CMD"
83+ echo " 🔗 Connecting IPFS nodes..."
84+ $IPFS_CMD swarm connect / ip4/ 127.0.0.1 / tcp/ 12347 / ws/ p2p/ 12 D3KooWRkZhiRhsqmrQ28 rt73 K7V3aCBpqKrLGSXmZ99 PTcTZby || true
85+ $IPFS_CMD swarm connect / ip4/ 127.0.0.1 / tcp/ 10001 / ws/ p2p/ 12 D3KooWQCkBm1BYtkHpocxCwMgR8yjitEeHGx8spzcDLGt2gkBm || true
86+
87+ # Start start solo chain with zombienet in background
88+ bulletin-solo-zombienet-start :
89+ #!/usr/bin/env bash
90+ set -e
91+
92+ mkdir -p {{ PID_DIR }}
5793
58- # Start zombienet in background
5994 echo " ⚡ Starting Bulletin chain with zombienet..."
60- POLKADOT_BULLETIN_BINARY_PATH=../ target/ release/ polkadot-bulletin-chain ./ $(ls zombienet-*-*) -p native spawn ./ zombienet/ bulletin-polkadot-local.toml > / tmp/ zombienet.log 2 >&1 &
95+ POLKADOT_BULLETIN_BINARY_PATH=../ target/ release/ polkadot-bulletin-chain .. / $(ls .. / zombienet-*-*) -p native spawn . ./ zombienet/ bulletin-polkadot-local.toml > / tmp/ zombienet.log 2 >&1 &
6196 ZOMBIENET_PID=$!
97+ echo $ZOMBIENET_PID > {{ PID_DIR }} / zombienet.pid
6298 echo " Zombienet PID: $ZOMBIENET_PID"
99+ echo " Log: /tmp/zombienet.log"
63100 echo " Waiting for chain to start (15 seconds)..."
64101 sleep 15
102+
103+ # Start IPFS reconnect script in background
104+ ipfs-reconnect-start :
105+ #!/usr/bin/env bash
106+ set -e
107+
108+ mkdir -p {{ PID_DIR }}
65109
66- # Start IPFS reconnect script in background
67110 echo " 🔄 Starting IPFS reconnect script..."
68111 ./ scripts/ ipfs-reconnect-solo.sh > / tmp/ ipfs-reconnect.log 2 >&1 &
69112 RECONNECT_PID=$!
113+ echo $RECONNECT_PID > {{ PID_DIR }} / ipfs-reconnect.pid
70114 echo " Reconnect PID: $RECONNECT_PID"
115+ echo " Log: /tmp/ipfs-reconnect.log"
71116 sleep 2
117+
118+ # Generate PAPI descriptors
119+ papi-generate :
120+ #!/usr/bin/env bash
121+ set -e
122+
123+ echo " 🔧 Generating PAPI descriptors..."
124+ npm run papi:generate
125+
126+ # Setup all services needed for testing (IPFS, zombienet, IPFS reconnect, PAPI)
127+ # Parameters: api=[papi|pjs] - choose between Polkadot API (papi) or Polkadot JS (pjs)
128+ setup-services api = " papi":
129+ #!/usr/bin/env bash
130+ set -e
131+
132+ API_TYPE=" {{ api }} "
133+
134+ echo " 🔧 Setting up services for $API_TYPE..."
72135
73- # Generate PAPI descriptors (only for papi)
136+ # Initialize IPFS
137+ just ipfs-init
138+
139+ # Start services
140+ just ipfs-start
141+ just bulletin-solo-zombienet-start
142+ just ipfs-connect
143+ just ipfs-reconnect-start
144+
145+ # Generate PAPI descriptors if needed
74146 if [ " $API_TYPE" == " papi" ]; then
75- echo " 🔧 Generating PAPI descriptors..."
76- npm run papi:generate
147+ just papi-generate
148+ fi
149+
150+ echo " ✅ Services setup complete"
151+
152+ # Stop all running services (IPFS, zombienet, reconnect script)
153+ teardown-services :
154+ #!/usr/bin/env bash
155+
156+ echo " 🧹 Stopping all services..."
157+
158+ # Stop services by reading PIDs from files
159+ if [ -d {{ PID_DIR }} ]; then
160+ for pidfile in {{ PID_DIR }} / *.pid; do
161+ if [ -f " $pidfile" ]; then
162+ PID=$(cat " $pidfile" )
163+ SERVICE=$(basename " $pidfile" .pid)
164+ if kill $PID 2 >/ dev/ null; then
165+ echo " ✓ Stopped $SERVICE (PID: $PID)"
166+ else
167+ echo " ⚠ $SERVICE (PID: $PID) not running or already stopped"
168+ fi
169+ rm " $pidfile"
170+ fi
171+ done
172+ rmdir {{ PID_DIR }} 2 >/ dev/ null || true
173+ else
174+ echo " No running services found"
175+ fi
176+
177+ echo " ✅ Services stopped"
178+
179+ # Test the complete workflow (builds, starts services, runs example, shuts down services)
180+ # Parameters: api=[papi|pjs] - choose between Polkadot API (papi) or Polkadot JS (pjs)
181+ run-authorize-and-store api = " papi": build npm-install
182+ #!/usr/bin/env bash
183+ set -e
184+
185+ API_TYPE=" {{ api }} "
186+
187+ if [[ " $API_TYPE" != " papi" && " $API_TYPE" != " pjs" ]]; then
188+ echo " ❌ Error: api parameter must be 'papi' or 'pjs'"
189+ exit 1
77190 fi
78191
79- # Determine which example to run
192+ echo " 🚀 Starting $API_TYPE workflow test..."
193+ echo " "
194+
195+ # Setup all services
196+ just setup-services $API_TYPE
197+
198+ # Run the example
80199 if [ " $API_TYPE" == " papi" ]; then
81200 EXAMPLE_FILE=" authorize_and_store_papi.js"
82201 else
83202 EXAMPLE_FILE=" authorize_and_store.js"
84203 fi
85-
86- # Run the example
87- echo " "
88- echo " 🎯 Running $EXAMPLE_FILE example..."
89- echo " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
90204 node $EXAMPLE_FILE
91205 EXAMPLE_EXIT=$?
92206
@@ -105,8 +219,6 @@ authorize-and-store api="papi": build npm-install
105219 echo " /tmp/ipfs-reconnect.log"
106220
107221 # Clean up background processes
108- echo " 🧹 Cleaning up background processes..."
109- kill $IPFS_PID $ZOMBIENET_PID $RECONNECT_PID 2 >/ dev/ null || true
110-
222+ just teardown-services
111223
112224 exit $EXAMPLE_EXIT
0 commit comments