grantstamp-server 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright 2026 The Grantstamp Authors
3
+ """The Grantstamp registry server (FastAPI).
4
+
5
+ Licensed under the GNU Affero General Public License, version 3 only (see
6
+ server/LICENSE). The client library it builds on, ``grantstamp``, is
7
+ Apache-2.0. Install with ``pip install grantstamp-server`` and run with
8
+ ``grantstamp serve``.
9
+ """
10
+
11
+ __version__ = "0.1.0"
@@ -0,0 +1,67 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright 2026 The Grantstamp Authors
3
+ """Operator actions that run directly against the registry database.
4
+
5
+ These are deliberately not HTTP endpoints: the operator runs them on the
6
+ server (``grantstamp admin ...``). Every change is written to the transparency log.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from typing import Any
12
+
13
+ from .db import Database
14
+ from .store import Store
15
+
16
+
17
+ def open_store(db_url: str) -> Store:
18
+ return Store(Database(db_url))
19
+
20
+
21
+ def verify_domain(store: Store, owner_id: str, domain: str, note: str = "manual") -> dict[str, Any]:
22
+ if not store.owner(owner_id):
23
+ raise SystemExit(f"no such owner {owner_id}")
24
+ row = store.db.one("SELECT * FROM domains WHERE owner_id = ? AND domain = ?", (owner_id, domain))
25
+ if not row:
26
+ store.domain_challenge(owner_id, domain, "manual")
27
+ store.mark_domain_verified(owner_id, domain, f"operator:{note}")
28
+ return store.owner_public(owner_id) or {}
29
+
30
+
31
+ def trust_agent(store: Store, agent_id: str, trust: str = "trusted") -> dict[str, Any]:
32
+ if trust not in ("registered", "trusted", "blocked"):
33
+ raise SystemExit("trust must be registered, trusted or blocked")
34
+ if not store.agent(agent_id):
35
+ raise SystemExit(f"no such agent {agent_id}")
36
+ store.set_agent_trust(agent_id, trust)
37
+ return store.agent(agent_id) or {}
38
+
39
+
40
+ def set_stamp_status(store: Store, stamp_id: str, status: str) -> dict[str, Any]:
41
+ if status not in ("active", "conflict", "suspended", "withdrawn"):
42
+ raise SystemExit("status must be active, conflict, suspended or withdrawn")
43
+ if not store.stamp(stamp_id):
44
+ raise SystemExit(f"no such stamp {stamp_id}")
45
+ store.set_stamp_status(stamp_id, status)
46
+ return store.stamp_public(stamp_id) or {}
47
+
48
+
49
+ def set_owner_status(store: Store, owner_id: str, status: str) -> dict[str, Any]:
50
+ if status not in ("active", "suspended"):
51
+ raise SystemExit("status must be active or suspended")
52
+ store.db.execute("UPDATE owners SET status = ? WHERE id = ?", (status, owner_id))
53
+ store.log_append("owner.status", owner_id, {"status": status})
54
+ return store.owner_public(owner_id) or {}
55
+
56
+
57
+ def resolve_dispute(store: Store, dispute_id: str, status: str, resolution: str) -> dict[str, Any]:
58
+ if status not in ("upheld", "rejected", "withdrawn"):
59
+ raise SystemExit("status must be upheld, rejected or withdrawn")
60
+ if not store.dispute(dispute_id):
61
+ raise SystemExit(f"no such dispute {dispute_id}")
62
+ store.resolve_dispute(dispute_id, status, resolution)
63
+ return store.dispute(dispute_id) or {}
64
+
65
+
66
+ def list_disputes(store: Store, status: str = "open") -> list[dict[str, Any]]:
67
+ return store.db.query("SELECT * FROM disputes WHERE status = ? ORDER BY created", (status,))