Skip to content

Commit ccba01a

Browse files
authored
Merge pull request #54 from spacesprotocol/addr
Update libveritas and include examples
2 parents 19f68ea + 45c03ac commit ccba01a

28 files changed

Lines changed: 4547 additions & 104 deletions

File tree

.github/workflows/snippets.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Extract code snippets
2+
3+
on:
4+
push:
5+
paths:
6+
- "fabric/examples/**"
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
jobs:
15+
extract:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Extract snippets
21+
run: |
22+
cd fabric/examples
23+
mkdir -p /tmp/snippets
24+
25+
for lang_file in \
26+
rust/src/main.rs \
27+
js/index.mjs \
28+
go/main.go \
29+
python/example.py \
30+
kotlin/Example.kt \
31+
swift/Example.swift; do
32+
33+
lang=$(dirname "$lang_file" | cut -d/ -f1)
34+
mkdir -p "/tmp/snippets/$lang"
35+
./extract-snippets.sh "$lang_file" "/tmp/snippets/$lang"
36+
done
37+
38+
# Create index
39+
echo "# Code Snippets" > /tmp/snippets/index.md
40+
echo "" >> /tmp/snippets/index.md
41+
for lang in rust js go python kotlin swift; do
42+
echo "## $lang" >> /tmp/snippets/index.md
43+
for f in /tmp/snippets/$lang/*.txt; do
44+
name=$(basename "$f" .txt)
45+
echo "- [$name]($lang/$name.txt)" >> /tmp/snippets/index.md
46+
done
47+
echo "" >> /tmp/snippets/index.md
48+
done
49+
50+
- name: Upload artifact
51+
uses: actions/upload-pages-artifact@v3
52+
with:
53+
path: /tmp/snippets
54+
55+
deploy:
56+
needs: extract
57+
runs-on: ubuntu-latest
58+
environment:
59+
name: github-pages
60+
url: ${{ steps.deployment.outputs.page_url }}
61+
steps:
62+
- name: Deploy to GitHub Pages
63+
id: deployment
64+
uses: actions/deploy-pages@v4

Cargo.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
#
4+
# Extract code snippets from example files.
5+
#
6+
# Snippets are delimited by <doc:name> and </doc:name> tags.
7+
# Output: one file per snippet in the output directory.
8+
#
9+
# Usage:
10+
# ./extract-snippets.sh rust/src/main.rs snippets/rust
11+
# ./extract-snippets.sh js/index.mjs snippets/js
12+
#
13+
14+
INPUT="${1:?Usage: extract-snippets.sh <input-file> <output-dir>}"
15+
OUTDIR="${2:?Usage: extract-snippets.sh <input-file> <output-dir>}"
16+
17+
mkdir -p "$OUTDIR"
18+
19+
# Detect language from file extension
20+
EXT="txt"
21+
22+
# Extract each <doc:name> ... </doc:name> block
23+
current_tag=""
24+
current_file=""
25+
26+
while IFS= read -r line; do
27+
# Check for opening tag
28+
if [[ "$line" =~ \<doc:([a-zA-Z0-9_-]+)\> ]]; then
29+
current_tag="${BASH_REMATCH[1]}"
30+
current_file="$OUTDIR/${current_tag}.${EXT}"
31+
> "$current_file" # truncate
32+
continue
33+
fi
34+
35+
# Check for closing tag
36+
if [[ "$line" =~ \</doc: ]]; then
37+
if [ -n "$current_file" ]; then
38+
echo " extracted: $current_tag -> $current_file"
39+
fi
40+
current_tag=""
41+
current_file=""
42+
continue
43+
fi
44+
45+
# Write line to current snippet (strip common leading whitespace)
46+
if [ -n "$current_file" ]; then
47+
echo "$line" >> "$current_file"
48+
fi
49+
done < "$INPUT"
50+
51+
# Clean up: strip common leading whitespace from each snippet
52+
for f in "$OUTDIR"/*."$EXT"; do
53+
[ -f "$f" ] || continue
54+
# Find minimum indentation (ignoring blank lines)
55+
min_indent=$(sed -n '/[^ ]/{ s/^\( *\).*/\1/; p; }' "$f" | awk '{ print length }' | sort -n | head -1)
56+
if [ -n "$min_indent" ] && [ "$min_indent" -gt 0 ]; then
57+
if sed -i '' "s/^ \{1,$min_indent\}//" "$f" 2>/dev/null; then
58+
: # macOS sed
59+
else
60+
sed -i "s/^ \{1,$min_indent\}//" "$f" # Linux sed
61+
fi
62+
fi
63+
done
64+
65+
echo "Done: $(ls "$OUTDIR"/*."$EXT" 2>/dev/null | wc -l | tr -d ' ') snippets extracted"

fabric/examples/go/go.mod

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module example-go
2+
3+
go 1.22
4+
5+
require github.com/spacesprotocol/fabric-go v0.0.0-dev.20260401232107
6+
7+
require (
8+
github.com/spacesprotocol/libveritas-go v0.0.0-dev.20260401232107 // indirect
9+
github.com/btcsuite/btcd/btcec/v2 v2.3.6 // indirect
10+
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
11+
github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect
12+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
13+
)

0 commit comments

Comments
 (0)