-
-
Notifications
You must be signed in to change notification settings - Fork 463
fix: register explorer dependency routes #6733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1391,6 +1391,92 @@ def ensure_epoch_enroll_integer_weights(conn: sqlite3.Connection): | |
| except Exception as e: | ||
| print(f"[RIP-0305 Track C] Failed to register bridge endpoints: {e}") | ||
|
|
||
| # RIP-302 Agent Economy endpoints used by the explorer dashboard | ||
| try: | ||
| if REPO_ROOT not in sys.path: | ||
| sys.path.insert(0, REPO_ROOT) | ||
| from rip302_agent_economy import register_agent_economy | ||
|
|
||
| register_agent_economy(app, DB_PATH) | ||
| print("[RIP-302] Agent Economy endpoints registered") | ||
| except ImportError as e: | ||
| print(f"[RIP-302] Agent Economy module not available: {e}") | ||
| except Exception as e: | ||
| print(f"[RIP-302] Failed to register Agent Economy endpoints: {e}") | ||
|
|
||
| # Ergo anchor transparency endpoints used by explorer/navigation links. | ||
| _ANCHOR_ROUTES_REGISTERED = False | ||
| try: | ||
| from rustchain_ergo_anchor import AnchorService, create_anchor_api_routes | ||
|
|
||
| create_anchor_api_routes(app, AnchorService(DB_PATH)) | ||
| _ANCHOR_ROUTES_REGISTERED = True | ||
| print("[ANCHOR] Ergo anchor read-only endpoints registered") | ||
| except ImportError as e: | ||
| print(f"[ANCHOR] Ergo anchor module not available: {e}") | ||
| except Exception as e: | ||
| print(f"[ANCHOR] Failed to register Ergo anchor endpoints: {e}") | ||
|
|
||
|
|
||
| if not _ANCHOR_ROUTES_REGISTERED: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fallback branch is now part of the explorer's availability guarantee, but the added integrated-app test only exercises it if |
||
| def _fallback_anchor_int_arg(name, default, minimum, maximum=None): | ||
| raw_value = request.args.get(name) | ||
| if raw_value is None or raw_value == "": | ||
| return default, None | ||
| try: | ||
| value = int(raw_value) | ||
| except (TypeError, ValueError): | ||
| return None, f"{name}_must_be_integer" | ||
| if value < minimum: | ||
| return None, f"{name}_must_be_at_least_{minimum}" | ||
| if maximum is not None: | ||
| value = min(value, maximum) | ||
| return value, None | ||
|
|
||
| def _ensure_fallback_anchor_table(cursor): | ||
| cursor.execute(""" | ||
| CREATE TABLE IF NOT EXISTS ergo_anchors ( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| rustchain_height INTEGER NOT NULL, | ||
| rustchain_hash TEXT NOT NULL, | ||
| commitment_hash TEXT NOT NULL, | ||
| ergo_tx_id TEXT NOT NULL, | ||
| ergo_height INTEGER, | ||
| confirmations INTEGER DEFAULT 0, | ||
| status TEXT DEFAULT 'pending', | ||
| created_at INTEGER NOT NULL | ||
| ) | ||
| """) | ||
|
|
||
| @app.route("/anchor/list", methods=["GET"]) | ||
| def fallback_anchor_list(): | ||
| limit, error = _fallback_anchor_int_arg("limit", 50, 1, 100) | ||
| if error: | ||
| return jsonify({"error": error}), 400 | ||
| offset, error = _fallback_anchor_int_arg("offset", 0, 0, 10_000) | ||
| if error: | ||
| return jsonify({"error": error}), 400 | ||
|
|
||
| with sqlite3.connect(DB_PATH) as conn: | ||
| conn.row_factory = sqlite3.Row | ||
| cursor = conn.cursor() | ||
| _ensure_fallback_anchor_table(cursor) | ||
| rows = cursor.execute(""" | ||
| SELECT * FROM ergo_anchors | ||
| ORDER BY rustchain_height DESC | ||
| LIMIT ? OFFSET ? | ||
| """, (limit, offset)).fetchall() | ||
|
|
||
| return jsonify({ | ||
| "count": len(rows), | ||
| "anchors": [dict(row) for row in rows], | ||
| }) | ||
|
|
||
|
|
||
| @app.route("/anchors", methods=["GET"]) | ||
| def anchors_alias(): | ||
| return redirect("/anchor/list", code=302) | ||
|
|
||
| # BoTTube RSS/Atom Feed endpoints (Issue #759) | ||
| if HAVE_BOTTUBE_FEED: | ||
| try: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good extraction here: using
_ensure_anchor_table(cursor)before the list query keeps/anchor/listaligned withget_last_anchor()on empty deployments. That matters for the explorer fix because a fresh DB should render an empty anchor list instead of surfacing a route-level error to first-time users.