Skip to content

Commit b43f98e

Browse files
willemnealclaudechadoh
authored
feat(registry): update to new contract id for registry (#478)
* fix(registry): root sub_reg events in constructor should go first * feat(registry): update to new contract id for registry * fix: update the contract id tests and add expect_test to regenerate in future * fix: update to new contract id again and fix clippy * feat: add dry run options and update tests * fix: revert toolchain * fix: add root registry arg to deploy script * fix: update to 0.6.1 * fix: skip batch if no contracts provided * feat: add shellcheck and use .salt file as source of truth * fix: resolve shellcheck warnings in deploy scripts - deploy.sh: drop useless cat (SC2002) - deploy_initial_registries.sh: remove dead INITIAL_BATCH var (SC2034) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix: ensure that the registry CLI is up to date * Apply suggestions from code review Co-authored-by: Chad Ostrowski <221614+chadoh@users.noreply.github.com> * feat: upgrade contract to newest soroban-sdk --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Chad Ostrowski <221614+chadoh@users.noreply.github.com>
1 parent 8ac90ea commit b43f98e

11 files changed

Lines changed: 215 additions & 65 deletions

File tree

Cargo.lock

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

check-shell.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
cd "$SCRIPT_DIR"
6+
7+
if ! command -v shellcheck >/dev/null 2>&1; then
8+
echo "error: shellcheck is not installed" >&2
9+
echo "install with: apt install shellcheck | brew install shellcheck" >&2
10+
exit 127
11+
fi
12+
13+
mapfile -d '' scripts < <(
14+
find . \
15+
\( -path ./target -o -path ./node_modules -o -path '*/target' -o -path '*/node_modules' \) -prune \
16+
-o -type f -name '*.sh' -print0
17+
)
18+
19+
if [ "${#scripts[@]}" -eq 0 ]; then
20+
echo "no shell scripts found"
21+
exit 0
22+
fi
23+
24+
echo "checking ${#scripts[@]} script(s) with shellcheck $(shellcheck --version | awk '/^version:/ {print $2}')"
25+
26+
fail=0
27+
for script in "${scripts[@]}"; do
28+
echo "-> $script"
29+
if ! shellcheck -x "$script"; then
30+
fail=1
31+
fi
32+
done
33+
34+
if [ "$fail" -ne 0 ]; then
35+
echo "shellcheck found issues" >&2
36+
exit 1
37+
fi
38+
39+
echo "all scripts passed"

contracts/registry/.salt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2026-04-24T13:41:00

contracts/registry/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "registry"
33
description = "A crate for managing and deploying smart contracts on the Soroban blockchain."
4-
version = "0.6.1"
4+
version = "0.6.2"
55
authors = ["The Aha Company <hello@theaha.co>"]
66
license = "Apache-2.0"
77
rust-version = "1.69"

contracts/registry/deploy.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
PATH=./target/bin:$PATH
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
REPO_ROOT="$SCRIPT_DIR/../.."
7+
8+
DRY_RUN=0
9+
for arg in "$@"; do
10+
case "$arg" in
11+
--dry-run|-n)
12+
DRY_RUN=1
13+
;;
14+
-h|--help)
15+
echo "Usage: $0 [--dry-run|-n]"
16+
exit 0
17+
;;
18+
*)
19+
echo "Unknown option: $arg" >&2
20+
echo "Usage: $0 [--dry-run|-n]" >&2
21+
exit 1
22+
;;
23+
esac
24+
done
25+
26+
run() {
27+
if [ "$DRY_RUN" -eq 1 ]; then
28+
printf '[dry-run] '
29+
printf '%q ' "$@"
30+
printf '\n'
31+
else
32+
"$@"
33+
fi
34+
}
35+
36+
# sha256 -s verified
37+
#
38+
39+
registry_version() {
40+
awk -F'"' '/^version[[:space:]]*=/ { print $2; exit }' \
41+
"$REPO_ROOT/contracts/registry/Cargo.toml"
42+
}
43+
VERSION=v$(registry_version)
44+
WASM_URL="https://github.com/theahaco/scaffold-stellar/releases/download/registry-$VERSION/registry_$VERSION.wasm"
45+
WASM_PATH="$REPO_ROOT/target/stellar/registry_$VERSION.wasm"
46+
47+
48+
if [ "$DRY_RUN" -eq 1 ]; then
49+
echo "[dry-run] curl -L $WASM_URL > $WASM_PATH"
50+
else
51+
curl -L "$WASM_URL" > "$WASM_PATH"
52+
fi
53+
54+
55+
SALT=$(shasum -a 256 < "$SCRIPT_DIR/.salt" | awk '{print $1}')
56+
57+
ADMIN=theahaco
58+
ADDRESS=GAMPJROHOAW662FINQ4XQOY2ULX5IEGYXCI4SMZYE75EHQBR6PSTJG3M
59+
60+
run stellar contract deploy --alias registry \
61+
--wasm "$WASM_PATH" \
62+
--source "$ADMIN" \
63+
--salt "$SALT" \
64+
-- \
65+
--admin "$ADMIN" \
66+
--manager "\"$ADDRESS\""
67+
68+
run just registry publish --wasm "$WASM_PATH" \
69+
--author "$ADMIN" \
70+
--source "$ADMIN"

contracts/registry/deploy_initial_registries.sh

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,77 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
ADMIN="\"GAMPJROHOAW662FINQ4XQOY2ULX5IEGYXCI4SMZYE75EHQBR6PSTJG3M\""
4+
DRY_RUN=0
5+
for arg in "$@"; do
6+
case "$arg" in
7+
--dry-run|-n)
8+
DRY_RUN=1
9+
;;
10+
-h|--help)
11+
echo "Usage: $0 [--dry-run|-n]"
12+
exit 0
13+
;;
14+
*)
15+
echo "Unknown option: $arg" >&2
16+
echo "Usage: $0 [--dry-run|-n]" >&2
17+
exit 1
18+
;;
19+
esac
20+
done
21+
22+
run() {
23+
if [ "$DRY_RUN" -eq 1 ]; then
24+
printf '[dry-run] '
25+
printf '%q ' "$@"
26+
printf '\n'
27+
else
28+
"$@"
29+
fi
30+
}
31+
532
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
33+
## build so that we use the latest registry
34+
cargo build --package stellar-registry-cli
35+
PATH=$SCRIPT_DIR/../../target/debug:$PATH
36+
37+
ROOT_REGISTRY=$(stellar registry fetch-contract-id registry)
38+
39+
ADMIN=theahaco
40+
MANAGER="\"$(stellar keys public-key $ADMIN)\""
641
INITIAL_CONTRACTS="$SCRIPT_DIR/initial_contracts.json"
7-
INITIAL_BATCH="$SCRIPT_DIR/initial_batch.json"
842

9-
# Prints (does not execute) the commands to deploy a named registry.
43+
# Deploys a named registry if it isn't already registered. Always ensures the
44+
# local stellar alias exists.
1045
deploy () {
1146
local name="$1"
12-
stellar registry deploy --contract-name "$name" --wasm-name registry -- --admin theahaco --manager "$ADMIN"
13-
stellar registry create-alias "$name"
47+
if existing_id=$(stellar registry fetch-contract-id "$name" 2>/dev/null) && [ -n "$existing_id" ]; then
48+
echo "Contract '$name' already registered (id: $existing_id); skipping deploy"
49+
else
50+
run stellar registry deploy --contract-name "$name" --wasm-name registry -- \
51+
--admin $ADMIN \
52+
--manager "$MANAGER" \
53+
--root "\"$ROOT_REGISTRY\""
54+
fi
55+
run stellar registry create-alias "$name" --force
1456
}
1557

1658
# Prints (does not execute) the batch-register invocation for the given
1759
# registry contract alias and the JSON array of [name, address, owner] tuples.
1860
batch_register () {
1961
local alias="$1"
2062
local contracts_json="$2"
21-
stellar contract invoke --id "$alias" --source theahaco -- batch-register --contracts "$contracts_json"
63+
run stellar contract invoke --id "$alias" --source theahaco -- batch-register --contracts "$contracts_json"
64+
run stellar contract invoke --id "$alias" --source theahaco -- process_batch --limit 10
2265
}
2366

2467
# Per-project registries from initial_contracts.json:
2568
# each top-level entry is {"<name>": [[name, address, owner], ...]}.
2669
while IFS= read -r name; do
27-
CONTRACT_ID=$(stellar registry fetch-contract-id $name)
28-
echo WHEN contract_id = \'$CONTRACT_ID\' THEN \'$name\'
29-
30-
# deploy "$name"
31-
# contracts=$(jq -c --arg k "$name" '.[] | select(has($k)) | .[$k]' "$INITIAL_CONTRACTS")
32-
# batch_register "$name" "$contracts"
33-
# stellar contract invoke --id "$name" -- process-batch --limit 10
70+
deploy "$name"
71+
contracts=$(jq -c --arg k "$name" '.[] | select(has($k)) | .[$k]' "$INITIAL_CONTRACTS")
72+
if [ "$(jq 'length' <<<"$contracts")" -eq 0 ]; then
73+
echo "No contracts for '$name'; skipping batch-register"
74+
continue
75+
fi
76+
batch_register "$name" "$contracts"
3477
done < <(jq -r '.[] | keys[0]' "$INITIAL_CONTRACTS")
35-
36-
# # Top-level contracts batch-registered into the root theahaco registry.
37-
# batch_register theahaco "$(jq -c '.' "$INITIAL_BATCH")"

contracts/registry/initial_contracts.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[
2+
{ "oz": [] },
23
{
34
"circle": [
45
[

crates/stellar-registry-build/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ sha2 = { workspace = true }
2929

3030
dotenvy = "0.15.7"
3131
# soroban-rpc = "=20.3.3"
32+
33+
[dev-dependencies]
34+
expect-test = "1.5"

crates/stellar-registry-build/src/registry.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,49 +77,52 @@ pub fn contract_id(network_passphrase: &str, salt: &str) -> stellar_strkey::Cont
7777
}
7878

7979
pub fn verified_contract_id(network_passphrase: &str) -> stellar_strkey::Contract {
80-
contract_id(network_passphrase, "v0.4.1")
80+
contract_id(
81+
network_passphrase,
82+
include_str!("../../../contracts/registry/.salt").trim(),
83+
)
8184
}
8285

8386
#[cfg(test)]
8487
mod generate_id {
88+
use expect_test::{Expect, expect};
8589
use stellar_cli::config::network::passphrase::*;
8690

87-
fn test_contract_id((passphrase, contract_id): (&str, &str)) {
88-
assert_eq!(
89-
&super::verified_contract_id(passphrase).to_string(),
90-
contract_id,
91-
"{passphrase}"
92-
);
91+
/// Run with `UPDATE_EXPECT=1 cargo test` to regenerate the expected contract
92+
/// IDs in-place after bumping the registry version or src/registry/.salt
93+
fn check(passphrase: &str, expected: &Expect) {
94+
expected.assert_eq(&super::verified_contract_id(passphrase).to_string());
9395
}
96+
9497
#[test]
9598
fn futurenet() {
96-
test_contract_id((
99+
check(
97100
FUTURENET,
98-
"CDMAKNALA4EKEA52CP645Y6H5NUM5AZPOPBM5RHOG2SRNHUOAPFHK6P4",
99-
));
101+
&expect!["CC6YGVN57L5XC4HDZ7AIUJSURGWGC2EEQDKC6NK4DZ6LUHTZY5WXOTLX"],
102+
);
100103
}
101104

102105
#[test]
103106
fn testnet() {
104-
test_contract_id((
107+
check(
105108
TESTNET,
106-
"CCA256DWBJJEEYXAWQHP5N4ZAJ2NW4P5T52LZCGC766Q5XHFVNQBMFZV",
107-
));
109+
&expect!["CAAXJETKPYAATU4HVVQUTE2FFBULNFGZNEOC3MS635U5K3GZLAY2HI4M"],
110+
);
108111
}
109112

110113
#[test]
111114
fn mainnet() {
112-
test_contract_id((
115+
check(
113116
MAINNET,
114-
"CAYVNQYGQ7IVZBBKMZ46UNRUQIFGBVHVZFCG47CYCMA2SAODDVDVCWMS",
115-
));
117+
&expect!["CDU4M3LDIOUJJ5F3YXKJ4EJEP5VPRPG6N2LJ5HOQIMN7MNGL3NS3EGUY"],
118+
);
116119
}
117120

118121
#[test]
119122
fn local() {
120-
test_contract_id((
123+
check(
121124
LOCAL,
122-
"CB7GPZFAAJQJYJD63P7HUAVABBSGLRWJB2C35RKR5TQ33AMRSS2XFL3C",
123-
));
125+
&expect!["CA55VGAFPIZHOY2X26KANRJYFBWPEXGNLIEHR7Q5TR2576HKHOFPLBTX"],
126+
);
124127
}
125128
}

deploy_registry.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)