CSV Adapter Store
SQLite persistence layer for CSV Adapter seal and anchor storage.
Overview
This crate provides SQLite-backed storage for CSV Adapter seals and anchors. It implements the SealStore trait from csv-adapter-core, enabling persistent tracking of consumed seals and published anchors across all supported chains.
Key Features
- Seal Tracking: Persist consumed seals with chain-specific isolation
- Anchor Storage: Store published anchors with finality status
- Multi-Chain Support: Separate namespaces per blockchain
- Reorg Recovery: Handle chain reorganizations gracefully
- In-Memory Mode: Built-in support for testing without disk I/O
- Indexed Queries: Optimized lookups by chain, height, and status
Installation
Or in your Cargo.toml:
[]
= "0.1"
Quick Start
Creating a Store
use SqliteSealStore;
// Open a persistent store at a file path
let store = open?;
// Or create an in-memory store (for testing)
let store = in_memory?;
Recording Seal Consumption
use SqliteSealStore;
use ;
let mut store = in_memory?;
// Record a consumed seal
let record = SealRecord ;
store.save_seal?;
// Check if a seal has been consumed
let is_consumed = store.is_seal_consumed?;
assert!;
Managing Anchors
use SqliteSealStore;
use ;
let mut store = in_memory?;
// Record a published anchor
let record = AnchorRecord ;
store.save_anchor?;
// Check for pending anchors
let pending = store.pending_anchors?;
assert_eq!;
// Finalize after confirmations
store.finalize_anchor?;
Handling Reorganizations
use SqliteSealStore;
let mut store = in_memory?;
// Remove seals/anchors after a reorg height
let removed_seals = store.remove_seals_after?;
let removed_anchors = store.remove_anchors_after?;
println!;
Schema
The store creates two tables:
seals
| Column | Type | Description |
|---|---|---|
id |
INTEGER | Auto-incrementing primary key |
chain |
TEXT | Blockchain identifier |
seal_id |
BLOB | Unique seal identifier |
consumed_at_height |
INTEGER | Block height of consumption |
commitment_hash |
BLOB | Associated commitment hash |
recorded_at |
INTEGER | Unix timestamp of recording |
anchors
| Column | Type | Description |
|---|---|---|
id |
INTEGER | Auto-incrementing primary key |
chain |
TEXT | Blockchain identifier |
anchor_id |
BLOB | Unique anchor identifier |
block_height |
INTEGER | Block height of publication |
commitment_hash |
BLOB | Associated commitment hash |
is_finalized |
INTEGER | Finality status (0/1) |
confirmations |
INTEGER | Number of confirmations |
recorded_at |
INTEGER | Unix timestamp of recording |
License
This project is dual-licensed under either:
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contributing
We welcome contributions! Please see our GitHub repository for more information.