Skip to content

Commit 0c6ce72

Browse files
authored
Merge branch 'main' into big-data-example
2 parents c5e1cd0 + 3cbf832 commit 0c6ce72

File tree

13 files changed

+334
-99
lines changed

13 files changed

+334
-99
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/README.md

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,43 @@
11
# How to Run
22

3+
## Using `just`
4+
5+
[`just`](https://github.com/casey/just) is a command runner (similar to `make`) that helps execute project tasks.
6+
7+
Install just with:
8+
- `cargo install just`, if you have cargo package manager,
9+
- `brew install just`, if you're on Mac OS and have `brew` package manager installed,
10+
- `sudo apt install just`, if you're using a Linux distribution.
11+
12+
### Run prerequisites
13+
14+
It's only needed once after checkout or when dependencies change:
15+
- `just build`
16+
- `just npm-install`
17+
18+
### Run full workflow example
19+
- `just run-authorize-and-store papi` - for PAPI,
20+
- `just run-authorize-and-store pjs` - for PJS.
21+
22+
#### Run individual commands for manual testing
23+
- `just setup-services papi` - Setup all services (IPFS, zombienet, reconnect, PAPI descriptors),
24+
- `just ipfs-init` - Initialize IPFS (if needed),
25+
- `just ipfs-start` - Start IPFS daemon,
26+
- `just bulletin-solo-zombienet-start` - Start zombienet,
27+
- `just ipfs-connect` - Connect to IPFS nodes,
28+
- `just ipfs-reconnect-start` - Start IPFS reconnect script,
29+
- `just papi-generate` - Generate PAPI descriptors,
30+
- `just run-example papi` - Run example with PAPI or PJS,
31+
- `just teardown-services` - Stop all services
32+
33+
## Manually
34+
335

436
```shell
537
cd polkadot-bulletin-chain # make you are inside the project directory for the following steps
638
```
739

8-
## Download Zombienet
40+
### Download Zombienet
941

1042
```shell
1143
OS="$(uname -s)"
@@ -29,7 +61,7 @@ wget "https://github.com/paritytech/zombienet/releases/download/v1.3.133/${zb_bi
2961
chmod +x "${zb_bin}"
3062
```
3163

32-
## Run Kubo
64+
### Run Kubo
3365

3466
#### Execute Locally
3567

@@ -51,7 +83,7 @@ docker run -d --name ipfs-node -v ipfs-data:/data/ipfs -p 4001:4001 -p 8080:8080
5183
docker logs -f ipfs-node
5284
```
5385

54-
## Run Bulletin Solochain with `--ipfs-server`
86+
### Run Bulletin Solochain with `--ipfs-server`
5587

5688
```shell
5789
# Bulletin Solochain
@@ -86,9 +118,9 @@ docker exec -it ipfs-node ipfs swarm connect /ip4/172.17.0.1/tcp/12347/ws/p2p/12
86118
./scripts/ipfs-reconnect-solo.sh
87119
```
88120

89-
## Run Bulletin (Westend) Parachain with `--ipfs-server`
121+
### Run Bulletin (Westend) Parachain with `--ipfs-server`
90122

91-
### Prerequisites
123+
#### Prerequisites
92124

93125
```shell
94126
mkdir -p ~/local_bridge_testing/bin
@@ -114,7 +146,7 @@ cp target/release/polkadot-parachain ~/local_bridge_testing/bin
114146
# polkadot-parachain 1.20.2-165ba47dc91 or higher
115147
```
116148

117-
### Launch Parachain
149+
#### Launch Parachain
118150

119151
```shell
120152
# Bulletin Parachain (Westend)
@@ -124,7 +156,7 @@ POLKADOT_BINARY_PATH=~/local_bridge_testing/bin/polkadot \
124156
./$(ls zombienet-*-*) -p native spawn ./zombienet/bulletin-westend-local.toml
125157
```
126158

127-
### Connect IPFS Nodes
159+
#### Connect IPFS Nodes
128160

129161
```shell
130162
# Uses Kubo
@@ -147,19 +179,19 @@ docker exec -it ipfs-node ipfs swarm connect /ip4/172.17.0.1/tcp/12347/ws/p2p/12
147179
./scripts/ipfs-reconnect-westend.sh
148180
```
149181

150-
## Trigger Authorize, Store and IPFS Get
182+
### Trigger Authorize, Store and IPFS Get
151183

152-
### Example for Simple Authorizing and Store
184+
#### Example for Simple Authorizing and Store
153185

154-
#### Using Legacy @polkadot/api (PJS)
186+
##### Using Legacy @polkadot/api (PJS)
155187
```
156188
cd examples
157189
npm install
158190
159191
node authorize_and_store.js
160192
```
161193

162-
#### Using Modern PAPI (Polkadot API)
194+
##### Using Modern PAPI (Polkadot API)
163195
```bash
164196
cd examples
165197
npm install
@@ -175,7 +207,7 @@ npm run papi:update
175207
node authorize_and_store_papi.js
176208
```
177209

178-
### Example for Multipart / Chunked Content / Big Files
210+
#### Example for Multipart / Chunked Content / Big Files
179211

180212
The code stores one file, splits it into chunks, and then uploads those chunks to Bulletin.
181213

examples/justfile

Lines changed: 153 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
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
912
build:
@@ -13,80 +16,191 @@ build:
1316
npm-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/12D3KooWRkZhiRhsqmrQ28rt73K7V3aCBpqKrLGSXmZ99PTcTZby || true
85+
$IPFS_CMD swarm connect /ip4/127.0.0.1/tcp/10001/ws/p2p/12D3KooWQCkBm1BYtkHpocxCwMgR8yjitEeHGx8spzcDLGt2gkBm || 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

Comments
 (0)