Skip to content
Merged
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
70 changes: 70 additions & 0 deletions scripts/fetch-sidechain-hashes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
#
# Populate the BIP300 hash_id_1 / hash_id_2 fields of the sidechains/*.json
# proposal requests from each sidechain's most recent GitHub release.

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
SIDECHAIN_DIR="$REPO_ROOT/sidechains"

# slot -> github owner/repo of the canonical node software.
declare -A REPOS=(
[2]="LayerTwo-Labs/plain-bitnames"
[4]="LayerTwo-Labs/plain-bitassets"
[9]="LayerTwo-Labs/thunder-rust"
[13]="LayerTwo-Labs/truthcoin-dc"
[98]="iwakura-rein/thunder-orchard"
[99]="LayerTwo-Labs/photon"
[255]="LayerTwo-Labs/coinshift-rs"
)

command -v gh >/dev/null || { echo "❌ gh (GitHub CLI) is required" >&2; exit 1; }

shopt -s nullglob
files=("$SIDECHAIN_DIR"/*.json)
shopt -u nullglob
[ ${#files[@]} -gt 0 ] || { echo "❌ no request files in $SIDECHAIN_DIR" >&2; exit 1; }

for f in "${files[@]}"; do
slot="$(jq -r '.sidechain_id' "$f")"
repo="${REPOS[$slot]:-}"
if [ -z "$repo" ]; then
echo "❌ slot $slot ($(basename "$f")): no repo mapping" >&2
exit 1
fi

# Most recent published release (excludes drafts and pre-releases).
tag="$(gh api "repos/$repo/releases/latest" --jq '.tag_name' 2>/dev/null || true)"
if [ -z "$tag" ]; then
echo "❌ slot $slot ($repo): no published release" >&2
exit 1
fi

# hash_id_2: the 20-byte (40 hex) commit the release tag resolves to.
commit="$(gh api "repos/$repo/commits/$tag" --jq '.sha' 2>/dev/null || true)"
if ! [[ "$commit" =~ ^[0-9a-f]{40}$ ]]; then
echo "❌ slot $slot ($repo@$tag): could not resolve commit" >&2
exit 1
fi

# hash_id_1: sha256 of the release's source tarball.
tarball="$(mktemp)"
if ! curl -fsSL "https://github.com/$repo/archive/refs/tags/$tag.tar.gz" -o "$tarball"; then
echo "❌ slot $slot ($repo@$tag): tarball download failed" >&2
rm -f "$tarball"
exit 1
fi
h1="$(shasum -a 256 "$tarball" | cut -d' ' -f1)"
rm -f "$tarball"

tmp="$(mktemp)"
jq --arg h1 "$h1" --arg h2 "$commit" \
'.declaration.v0.hash_id_1.hex = $h1 | .declaration.v0.hash_id_2.hex = $h2' \
"$f" > "$tmp" && mv "$tmp" "$f"

echo "✅ slot $slot $repo $tag"
echo " hash_id_1 $h1"
echo " hash_id_2 $commit"
done
15 changes: 15 additions & 0 deletions sidechains/02-bitnames.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"sidechain_id": 2,
"declaration": {
"v0": {
"title": "BitNames",
"description": "A variant of Namecoin/BitDNS that aims to replace ICANN",
"hash_id_1": {
"hex": "2b4dfd7a97c94502ed88441e917b13533a30929a028568231eacccc6c25daf23"
},
"hash_id_2": {
"hex": "67a981fe0f2ea78126e7ad94d4f233c5bfdc1575"
}
}
}
}
15 changes: 15 additions & 0 deletions sidechains/04-bitassets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"sidechain_id": 4,
"declaration": {
"v0": {
"title": "BitAssets",
"description": "A sidechain for digital assets",
"hash_id_1": {
"hex": "45ae898ac83b47bb4d62b3ea509d2fd0275ebe31ef93da6e32dacd72f8a0912a"
},
"hash_id_2": {
"hex": "664d418f3523f96e8222999f9fec6686b7a0642d"
}
}
}
}
15 changes: 15 additions & 0 deletions sidechains/09-thunder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"sidechain_id": 9,
"declaration": {
"v0": {
"title": "Thunder",
"description": "A sidechain with a large & growing blocksize, plus fraud proofs",
"hash_id_1": {
"hex": "c46e3297057b396024798ccfe05c4d1488dbc9f14f47af5858f1a81479e3d742"
},
"hash_id_2": {
"hex": "2559908bfe6e0542edb80078e9c2316c59a0ba30"
}
}
}
}
15 changes: 15 additions & 0 deletions sidechains/13-truthcoin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"sidechain_id": 13,
"declaration": {
"v0": {
"title": "Truthcoin",
"description": "A sidechain for decentralized prediction markets and oracle data",
"hash_id_1": {
"hex": "3e9f805a57ada7ad062b413c532e268343ee0514fdb65762dcea549de38078ce"
},
"hash_id_2": {
"hex": "435ce0d2e24196de240db92c27ffd0753bd14b80"
}
}
}
}
15 changes: 15 additions & 0 deletions sidechains/255-coinshift.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"sidechain_id": 255,
"declaration": {
"v0": {
"title": "Coinshift",
"description": "Sidechain with a P2P, trustless L2-L1 swap system",
"hash_id_1": {
"hex": "eaef35566f8849b13bd1efeb33f94b00118a549bf3decafcf3e3a64f3a78db5a"
},
"hash_id_2": {
"hex": "74f7ea60255aeb974c71eb18b2072ddb0215350f"
}
}
}
}
15 changes: 15 additions & 0 deletions sidechains/98-zside.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"sidechain_id": 98,
"declaration": {
"v0": {
"title": "zSide",
"description": "Sidechain with private transactions",
"hash_id_1": {
"hex": "ca96e7f0b9d29bae32cce839a7f4792319f98a6dafabd866da786247ad9d14d4"
},
"hash_id_2": {
"hex": "7be59b90c7c099dc732e3ad82cd77b2abee3c6de"
}
}
}
}
15 changes: 15 additions & 0 deletions sidechains/99-photon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"sidechain_id": 99,
"declaration": {
"v0": {
"title": "Photon",
"description": "Sidechain using post-quantum cryptography",
"hash_id_1": {
"hex": "e924266aeaee69e861f0f40ae4108790c32102fdc9005c3a642e0b418c768569"
},
"hash_id_2": {
"hex": "470285933cd504336a1be30ff929d5dc48296e32"
}
}
}
}
Loading