pub struct SqliteReceiptStore { /* private fields */ }Implementations§
Source§impl SqliteReceiptStore
impl SqliteReceiptStore
Sourcepub fn record_capability_snapshot(
&self,
token: &CapabilityToken,
parent_capability_id: Option<&str>,
) -> Result<(), CapabilityLineageError>
pub fn record_capability_snapshot( &self, token: &CapabilityToken, parent_capability_id: Option<&str>, ) -> Result<(), CapabilityLineageError>
Record a capability snapshot at issuance time.
Uses INSERT OR IGNORE for idempotency – duplicate inserts are silently dropped, preserving the first-writer-wins record.
The parent_capability_id argument must refer to a capability already
present in the lineage table. If it is Some but the parent is missing,
the depth defaults to 1 (the minimum delegation depth).
Sourcepub fn upsert_capability_snapshot(
&mut self,
snapshot: &CapabilitySnapshot,
) -> Result<(), CapabilityLineageError>
pub fn upsert_capability_snapshot( &mut self, snapshot: &CapabilitySnapshot, ) -> Result<(), CapabilityLineageError>
Upsert an already-materialized capability snapshot.
This is used by cluster replication so followers can converge on the leader’s lineage table without reconstructing full signed tokens.
Sourcepub fn get_lineage(
&self,
capability_id: &str,
) -> Result<Option<CapabilitySnapshot>, CapabilityLineageError>
pub fn get_lineage( &self, capability_id: &str, ) -> Result<Option<CapabilitySnapshot>, CapabilityLineageError>
Retrieve a single capability snapshot by its ID.
Returns None if no snapshot exists for the given capability_id.
Sourcepub fn get_delegation_chain(
&self,
capability_id: &str,
) -> Result<Vec<CapabilitySnapshot>, CapabilityLineageError>
pub fn get_delegation_chain( &self, capability_id: &str, ) -> Result<Vec<CapabilitySnapshot>, CapabilityLineageError>
Walk the delegation chain for a capability, returning root-first ordering.
Uses a WITH RECURSIVE CTE that walks from the given capability up through its parent chain, tracking depth level. The ORDER BY level DESC produces root-first ordering because the root has the highest level value.
A max-depth guard (level < 20) prevents infinite recursion caused by accidental cycles in the parent chain.
Sourcepub fn list_capabilities_for_subject(
&self,
subject_key: &str,
) -> Result<Vec<CapabilitySnapshot>, CapabilityLineageError>
pub fn list_capabilities_for_subject( &self, subject_key: &str, ) -> Result<Vec<CapabilitySnapshot>, CapabilityLineageError>
List all capability snapshots for a given subject key.
Returns snapshots ordered newest-first by issued_at.
Sourcepub fn list_capability_snapshots(
&self,
subject_key: Option<&str>,
issuer_key: Option<&str>,
) -> Result<Vec<CapabilitySnapshot>, CapabilityLineageError>
pub fn list_capability_snapshots( &self, subject_key: Option<&str>, issuer_key: Option<&str>, ) -> Result<Vec<CapabilitySnapshot>, CapabilityLineageError>
List capability snapshots filtered by subject and/or issuer.
If both filters are present they are combined with AND semantics. Results are ordered deterministically oldest-first to keep reputation corpus construction stable across runs.
Sourcepub fn list_capability_snapshots_after_seq(
&self,
after_seq: u64,
limit: usize,
) -> Result<Vec<StoredCapabilitySnapshot>, CapabilityLineageError>
pub fn list_capability_snapshots_after_seq( &self, after_seq: u64, limit: usize, ) -> Result<Vec<StoredCapabilitySnapshot>, CapabilityLineageError>
Return capability lineage snapshots added after a given local sequence.
The sequence is the SQLite rowid, which is monotonic for this
append-only table and therefore suitable as a replication cursor.
Source§impl SqliteReceiptStore
impl SqliteReceiptStore
Sourcepub fn build_evidence_export_bundle(
&self,
query: &EvidenceExportQuery,
) -> Result<EvidenceExportBundle, EvidenceExportError>
pub fn build_evidence_export_bundle( &self, query: &EvidenceExportQuery, ) -> Result<EvidenceExportBundle, EvidenceExportError>
Build a local-only evidence export bundle from the current SQLite store.
This method never fabricates joins that the runtime does not persist. Tool receipts can be scoped by capability or agent subject. Child receipts do not currently have the same attribution fields, so they are either included by query window or omitted with an explicit scope flag.
pub fn build_evidence_export_transparency_summary( &self, checkpoints: &[KernelCheckpoint], ) -> Result<CheckpointTransparencySummary, EvidenceExportError>
Source§impl SqliteReceiptStore
impl SqliteReceiptStore
Sourcepub fn query_receipts(
&self,
query: &ReceiptQuery,
) -> Result<ReceiptQueryResult, ReceiptStoreError>
pub fn query_receipts( &self, query: &ReceiptQuery, ) -> Result<ReceiptQueryResult, ReceiptStoreError>
Query tool receipts with multi-filter support and cursor-based pagination.
Filters are applied with AND semantics. The cursor parameter enables forward-only pagination using the seq column as a stable cursor.
The limit is capped at MAX_QUERY_LIMIT. total_count reflects the full filtered set (no cursor applied), regardless of the page limit.
Source§impl SqliteReceiptStore
impl SqliteReceiptStore
pub fn open(path: impl AsRef<Path>) -> Result<Self, ReceiptStoreError>
pub fn tool_receipt_count(&self) -> Result<u64, ReceiptStoreError>
pub fn child_receipt_count(&self) -> Result<u64, ReceiptStoreError>
pub fn list_tool_receipts( &self, limit: usize, capability_id: Option<&str>, tool_server: Option<&str>, tool_name: Option<&str>, decision_kind: Option<&str>, ) -> Result<Vec<ChioReceipt>, ReceiptStoreError>
Sourcepub fn list_tool_receipts_for_subject(
&self,
subject_key: &str,
) -> Result<Vec<ChioReceipt>, ReceiptStoreError>
pub fn list_tool_receipts_for_subject( &self, subject_key: &str, ) -> Result<Vec<ChioReceipt>, ReceiptStoreError>
List all tool receipts attributed to a given subject public key.
Uses the persisted subject_key column when present and falls back to
the capability lineage join for older rows.
pub fn list_tool_receipts_after_seq( &self, after_seq: u64, limit: usize, ) -> Result<Vec<StoredToolReceipt>, ReceiptStoreError>
pub fn list_child_receipts( &self, limit: usize, session_id: Option<&str>, parent_request_id: Option<&str>, request_id: Option<&str>, operation_kind: Option<&str>, terminal_state: Option<&str>, ) -> Result<Vec<ChildRequestReceipt>, ReceiptStoreError>
pub fn list_child_receipts_after_seq( &self, after_seq: u64, limit: usize, ) -> Result<Vec<StoredChildReceipt>, ReceiptStoreError>
pub fn record_federated_lineage_bridge( &mut self, local_capability_id: &str, parent_capability_id: &str, share_id: Option<&str>, ) -> Result<(), ReceiptStoreError>
pub fn get_combined_lineage( &self, capability_id: &str, ) -> Result<Option<CapabilitySnapshot>, ReceiptStoreError>
pub fn get_combined_delegation_chain( &self, capability_id: &str, ) -> Result<Vec<CapabilitySnapshot>, ReceiptStoreError>
Source§impl SqliteReceiptStore
impl SqliteReceiptStore
pub fn append_chio_receipt_returning_seq( &self, receipt: &ChioReceipt, ) -> Result<u64, ReceiptStoreError>
Sourcepub fn store_checkpoint(
&self,
checkpoint: &KernelCheckpoint,
) -> Result<(), ReceiptStoreError>
pub fn store_checkpoint( &self, checkpoint: &KernelCheckpoint, ) -> Result<(), ReceiptStoreError>
Store a signed KernelCheckpoint in the kernel_checkpoints table.
Sourcepub fn load_checkpoint_by_seq(
&self,
checkpoint_seq: u64,
) -> Result<Option<KernelCheckpoint>, ReceiptStoreError>
pub fn load_checkpoint_by_seq( &self, checkpoint_seq: u64, ) -> Result<Option<KernelCheckpoint>, ReceiptStoreError>
Load a KernelCheckpoint by its checkpoint_seq.
Sourcepub fn receipts_canonical_bytes_range(
&self,
start_seq: u64,
end_seq: u64,
) -> Result<Vec<(u64, Vec<u8>)>, ReceiptStoreError>
pub fn receipts_canonical_bytes_range( &self, start_seq: u64, end_seq: u64, ) -> Result<Vec<(u64, Vec<u8>)>, ReceiptStoreError>
Return canonical JSON bytes for receipts with seq in [start_seq, end_seq], ordered by seq.
Uses RFC 8785 canonical JSON for deterministic Merkle leaf hashing.
Sourcepub fn db_size_bytes(&self) -> Result<u64, ReceiptStoreError>
pub fn db_size_bytes(&self) -> Result<u64, ReceiptStoreError>
Return the current on-disk size of the database in bytes.
Uses PRAGMA page_count and PRAGMA page_size to compute the size
without requiring a filesystem stat, which is consistent in WAL mode.
Sourcepub fn oldest_receipt_timestamp(&self) -> Result<Option<u64>, ReceiptStoreError>
pub fn oldest_receipt_timestamp(&self) -> Result<Option<u64>, ReceiptStoreError>
Return the Unix timestamp (seconds) of the oldest receipt in the live
database, or None if there are no receipts.
Sourcepub fn oldest_receipt_timestamp_for_tenant(
&self,
tenant_id: &str,
) -> Result<Option<u64>, ReceiptStoreError>
pub fn oldest_receipt_timestamp_for_tenant( &self, tenant_id: &str, ) -> Result<Option<u64>, ReceiptStoreError>
Return the oldest live receipt timestamp for a tenant.
Sourcepub fn archive_receipts_before(
&mut self,
cutoff_unix_secs: u64,
archive_path: &str,
) -> Result<u64, ReceiptStoreError>
pub fn archive_receipts_before( &mut self, cutoff_unix_secs: u64, archive_path: &str, ) -> Result<u64, ReceiptStoreError>
Archive all receipts with timestamp < cutoff_unix_secs to an external
SQLite file, then delete them from the live database.
Checkpoint rows whose entire batch (batch_end_seq) falls within the
archived receipt range are also copied to the archive. Partial batches
are never archived to avoid breaking inclusion proofs.
Returns the number of receipt rows deleted from the live database.
Sourcepub fn archive_receipts_before_for_tenant(
&mut self,
cutoff_unix_secs: u64,
archive_path: &str,
tenant_id: &str,
) -> Result<u64, ReceiptStoreError>
pub fn archive_receipts_before_for_tenant( &mut self, cutoff_unix_secs: u64, archive_path: &str, tenant_id: &str, ) -> Result<u64, ReceiptStoreError>
Archive receipts for a single tenant without deleting other tenants’ evidence that may have a longer retention window.
Sourcepub fn rotate_if_needed(
&mut self,
config: &RetentionConfig,
) -> Result<u64, ReceiptStoreError>
pub fn rotate_if_needed( &mut self, config: &RetentionConfig, ) -> Result<u64, ReceiptStoreError>
Check time and size thresholds and archive receipts if either is exceeded.
- Time threshold: receipts older than
config.retention_daysdays are archived. - Size threshold: if
db_size_bytes()exceedsconfig.max_size_bytes, receipts older than the median timestamp are archived (removes roughly half the receipts).
Returns the number of receipt rows archived (0 if no threshold was exceeded).
Source§impl SqliteReceiptStore
impl SqliteReceiptStore
pub fn record_liability_claim_package( &mut self, claim: &SignedLiabilityClaimPackage, ) -> Result<(), ReceiptStoreError>
pub fn record_liability_claim_response( &mut self, response: &SignedLiabilityClaimResponse, ) -> Result<(), ReceiptStoreError>
pub fn record_liability_claim_dispute( &mut self, dispute: &SignedLiabilityClaimDispute, ) -> Result<(), ReceiptStoreError>
pub fn record_liability_claim_adjudication( &mut self, adjudication: &SignedLiabilityClaimAdjudication, ) -> Result<(), ReceiptStoreError>
pub fn record_liability_claim_payout_instruction( &mut self, payout_instruction: &SignedLiabilityClaimPayoutInstruction, ) -> Result<(), ReceiptStoreError>
pub fn record_liability_claim_payout_receipt( &mut self, payout_receipt: &SignedLiabilityClaimPayoutReceipt, ) -> Result<(), ReceiptStoreError>
pub fn record_liability_claim_settlement_instruction( &mut self, settlement_instruction: &SignedLiabilityClaimSettlementInstruction, ) -> Result<(), ReceiptStoreError>
pub fn record_liability_claim_settlement_receipt( &mut self, settlement_receipt: &SignedLiabilityClaimSettlementReceipt, ) -> Result<(), ReceiptStoreError>
pub fn query_liability_claim_workflows( &self, query: &LiabilityClaimWorkflowQuery, ) -> Result<LiabilityClaimWorkflowReport, ReceiptStoreError>
Source§impl SqliteReceiptStore
impl SqliteReceiptStore
pub fn record_liability_provider( &mut self, provider: &SignedLiabilityProvider, ) -> Result<(), ReceiptStoreError>
pub fn query_liability_providers( &self, query: &LiabilityProviderListQuery, ) -> Result<LiabilityProviderListReport, ReceiptStoreError>
pub fn resolve_liability_provider( &self, query: &LiabilityProviderResolutionQuery, ) -> Result<LiabilityProviderResolutionReport, ReceiptStoreError>
pub fn record_liability_quote_request( &mut self, request: &SignedLiabilityQuoteRequest, ) -> Result<(), ReceiptStoreError>
pub fn record_liability_quote_response( &mut self, response: &SignedLiabilityQuoteResponse, ) -> Result<(), ReceiptStoreError>
pub fn record_liability_placement( &mut self, placement: &SignedLiabilityPlacement, ) -> Result<(), ReceiptStoreError>
pub fn record_liability_bound_coverage( &mut self, coverage: &SignedLiabilityBoundCoverage, ) -> Result<(), ReceiptStoreError>
pub fn record_liability_auto_bind_decision( &mut self, decision: &SignedLiabilityAutoBindDecision, ) -> Result<(), ReceiptStoreError>
pub fn query_liability_market_workflows( &self, query: &LiabilityMarketWorkflowQuery, ) -> Result<LiabilityMarketWorkflowReport, ReceiptStoreError>
Source§impl SqliteReceiptStore
impl SqliteReceiptStore
pub fn query_receipt_analytics( &self, query: &ReceiptAnalyticsQuery, ) -> Result<ReceiptAnalyticsResponse, ReceiptStoreError>
pub fn query_cost_attribution_report( &self, query: &CostAttributionQuery, ) -> Result<CostAttributionReport, ReceiptStoreError>
pub fn query_compliance_report( &self, query: &OperatorReportQuery, ) -> Result<ComplianceReport, ReceiptStoreError>
pub fn upsert_settlement_reconciliation( &self, receipt_id: &str, reconciliation_state: SettlementReconciliationState, note: Option<&str>, ) -> Result<i64, ReceiptStoreError>
pub fn upsert_metered_billing_reconciliation( &self, receipt_id: &str, evidence: &MeteredBillingEvidenceRecord, reconciliation_state: MeteredBillingReconciliationState, note: Option<&str>, ) -> Result<i64, ReceiptStoreError>
pub fn query_metered_billing_reconciliation_report( &self, query: &OperatorReportQuery, ) -> Result<MeteredBillingReconciliationReport, ReceiptStoreError>
pub fn query_economic_receipt_projection_report( &self, query: &OperatorReportQuery, ) -> Result<EconomicReceiptProjectionReport, ReceiptStoreError>
pub fn query_economic_completion_flow_report( &self, query: &ExposureLedgerQuery, ) -> Result<EconomicCompletionFlowReport, ReceiptStoreError>
pub fn query_settlement_reconciliation_report( &self, query: &OperatorReportQuery, ) -> Result<SettlementReconciliationReport, ReceiptStoreError>
pub fn query_behavioral_feed_receipts( &self, query: &BehavioralFeedQuery, ) -> Result<(BehavioralFeedSettlementSummary, BehavioralFeedGovernedActionSummary, BehavioralFeedMeteredBillingSummary, BehavioralFeedReceiptSelection), ReceiptStoreError>
pub fn query_recent_credit_loss_receipts( &self, query: &BehavioralFeedQuery, limit: usize, ) -> Result<(u64, Vec<BehavioralFeedReceiptRow>), ReceiptStoreError>
Source§impl SqliteReceiptStore
impl SqliteReceiptStore
pub fn record_session_anchor_record( &self, session_id: &str, anchor_id: &str, auth_context_fingerprint: &str, issued_at: u64, supersedes_anchor_id: Option<&str>, anchor_json: &Value, ) -> Result<(), ReceiptStoreError>
pub fn record_request_lineage_record( &self, session_id: &str, request_id: &str, parent_request_id: Option<&str>, session_anchor_id: Option<&str>, recorded_at: u64, request_fingerprint: Option<&str>, lineage_json: &Value, ) -> Result<(), ReceiptStoreError>
pub fn record_receipt_lineage_statement_record( &self, child_receipt_id: &str, request_id: Option<&str>, session_id: Option<&str>, session_anchor_id: Option<&str>, parent_request_id: Option<&str>, parent_receipt_id: Option<&str>, chain_id: Option<&str>, recorded_at: u64, statement_json: &Value, ) -> Result<(), ReceiptStoreError>
pub fn list_receipt_lineage_statement_links( &self, receipt_id: &str, ) -> Result<Vec<ReceiptLineageStatementLink>, ReceiptStoreError>
pub fn receipt_lineage_verification( &self, receipt_id: &str, ) -> Result<Option<ReceiptLineageVerification>, ReceiptStoreError>
pub fn append_child_receipt_record( &self, receipt: &ChildRequestReceipt, ) -> Result<(), ReceiptStoreError>
Source§impl SqliteReceiptStore
impl SqliteReceiptStore
pub fn record_checkpoint_publication_trust_anchor_binding( &mut self, checkpoint_seq: u64, binding: &CheckpointPublicationTrustAnchorBinding, ) -> Result<(), ReceiptStoreError>
Source§impl SqliteReceiptStore
impl SqliteReceiptStore
pub fn record_underwriting_decision( &mut self, decision: &SignedUnderwritingDecision, ) -> Result<(), ReceiptStoreError>
pub fn create_underwriting_appeal( &mut self, request: &UnderwritingAppealCreateRequest, ) -> Result<UnderwritingAppealRecord, ReceiptStoreError>
pub fn resolve_underwriting_appeal( &mut self, request: &UnderwritingAppealResolveRequest, ) -> Result<UnderwritingAppealRecord, ReceiptStoreError>
pub fn query_underwriting_decisions( &self, query: &UnderwritingDecisionQuery, ) -> Result<UnderwritingDecisionListReport, ReceiptStoreError>
pub fn record_credit_facility( &mut self, facility: &SignedCreditFacility, ) -> Result<(), ReceiptStoreError>
pub fn query_credit_facilities( &self, query: &CreditFacilityListQuery, ) -> Result<CreditFacilityListReport, ReceiptStoreError>
pub fn record_credit_bond( &mut self, bond: &SignedCreditBond, ) -> Result<(), ReceiptStoreError>
pub fn query_credit_bonds( &self, query: &CreditBondListQuery, ) -> Result<CreditBondListReport, ReceiptStoreError>
pub fn record_credit_loss_lifecycle( &mut self, event: &SignedCreditLossLifecycle, ) -> Result<(), ReceiptStoreError>
pub fn query_credit_loss_lifecycle( &self, query: &CreditLossLifecycleListQuery, ) -> Result<CreditLossLifecycleListReport, ReceiptStoreError>
Source§impl SqliteReceiptStore
impl SqliteReceiptStore
Sourcepub fn with_strict_tenant_isolation(&self, strict: bool)
pub fn with_strict_tenant_isolation(&self, strict: bool)
Phase 1.5 multi-tenant receipt isolation: toggle strict-isolation mode on tenant-scoped queries.
When strict = true, a tenant_filter = Some(id) query returns
ONLY rows whose tenant_id = id. Legacy pre-1.5 receipts with
tenant_id IS NULL are excluded.
When strict = false, the same query also includes rows where
tenant_id IS NULL – the pre-multitenant “public” fallback
set – so legacy receipts remain visible during an explicit
compatibility window.
A tenant_filter = None admin / compat query always returns
every row regardless of this setting.
Sourcepub fn strict_tenant_isolation_enabled(&self) -> bool
pub fn strict_tenant_isolation_enabled(&self) -> bool
Read the current strict-tenant-isolation setting.
Trait Implementations§
Source§impl ReceiptStore for SqliteReceiptStore
impl ReceiptStore for SqliteReceiptStore
fn append_chio_receipt( &mut self, receipt: &ChioReceipt, ) -> Result<(), ReceiptStoreError>
fn append_chio_receipt_returning_seq( &mut self, receipt: &ChioReceipt, ) -> Result<Option<u64>, ReceiptStoreError>
fn receipts_canonical_bytes_range( &self, start_seq: u64, end_seq: u64, ) -> Result<Vec<(u64, Vec<u8>)>, ReceiptStoreError>
fn store_checkpoint( &mut self, checkpoint: &KernelCheckpoint, ) -> Result<(), ReceiptStoreError>
fn load_checkpoint_by_seq( &self, checkpoint_seq: u64, ) -> Result<Option<KernelCheckpoint>, ReceiptStoreError>
fn supports_kernel_signed_checkpoints(&self) -> bool
fn record_capability_snapshot( &mut self, token: &CapabilityToken, parent_capability_id: Option<&str>, ) -> Result<(), ReceiptStoreError>
fn get_capability_snapshot( &self, capability_id: &str, ) -> Result<Option<CapabilitySnapshot>, ReceiptStoreError>
fn get_capability_delegation_chain( &self, capability_id: &str, ) -> Result<Vec<CapabilitySnapshot>, ReceiptStoreError>
Source§fn record_session_anchor(
&mut self,
session_id: &str,
anchor_id: &str,
auth_context_fingerprint: &str,
issued_at: u64,
supersedes_anchor_id: Option<&str>,
anchor_json: &Value,
) -> Result<(), ReceiptStoreError>
fn record_session_anchor( &mut self, session_id: &str, anchor_id: &str, auth_context_fingerprint: &str, issued_at: u64, supersedes_anchor_id: Option<&str>, anchor_json: &Value, ) -> Result<(), ReceiptStoreError>
SessionAnchor while the concrete P1-A type remains in flight.Source§fn record_request_lineage(
&mut self,
session_id: &str,
request_id: &str,
parent_request_id: Option<&str>,
session_anchor_id: Option<&str>,
recorded_at: u64,
request_fingerprint: Option<&str>,
lineage_json: &Value,
) -> Result<(), ReceiptStoreError>
fn record_request_lineage( &mut self, session_id: &str, request_id: &str, parent_request_id: Option<&str>, session_anchor_id: Option<&str>, recorded_at: u64, request_fingerprint: Option<&str>, lineage_json: &Value, ) -> Result<(), ReceiptStoreError>
RequestLineageRecord while the concrete P1-A type remains in flight.Source§fn record_receipt_lineage_statement(
&mut self,
child_receipt_id: &str,
request_id: Option<&str>,
session_id: Option<&str>,
session_anchor_id: Option<&str>,
parent_request_id: Option<&str>,
parent_receipt_id: Option<&str>,
chain_id: Option<&str>,
recorded_at: u64,
statement_json: &Value,
) -> Result<(), ReceiptStoreError>
fn record_receipt_lineage_statement( &mut self, child_receipt_id: &str, request_id: Option<&str>, session_id: Option<&str>, session_anchor_id: Option<&str>, parent_request_id: Option<&str>, parent_receipt_id: Option<&str>, chain_id: Option<&str>, recorded_at: u64, statement_json: &Value, ) -> Result<(), ReceiptStoreError>
ReceiptLineageStatement while the concrete P1-A type remains in flight.