|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -euo pipefail |
3 | 3 |
|
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 | + |
5 | 32 | 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)\"" |
6 | 41 | INITIAL_CONTRACTS="$SCRIPT_DIR/initial_contracts.json" |
7 | | -INITIAL_BATCH="$SCRIPT_DIR/initial_batch.json" |
8 | 42 |
|
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. |
10 | 45 | deploy () { |
11 | 46 | 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 |
14 | 56 | } |
15 | 57 |
|
16 | 58 | # Prints (does not execute) the batch-register invocation for the given |
17 | 59 | # registry contract alias and the JSON array of [name, address, owner] tuples. |
18 | 60 | batch_register () { |
19 | 61 | local alias="$1" |
20 | 62 | 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 |
22 | 65 | } |
23 | 66 |
|
24 | 67 | # Per-project registries from initial_contracts.json: |
25 | 68 | # each top-level entry is {"<name>": [[name, address, owner], ...]}. |
26 | 69 | 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" |
34 | 77 | 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")" |
|
0 commit comments