pub struct IndexerDatabase { /* private fields */ }Expand description
SQLite database for the indexer.
Implementations§
Source§impl IndexerDatabase
impl IndexerDatabase
Sourcepub async fn open(path: &Path, network: Network) -> Result<Self, Error>
pub async fn open(path: &Path, network: Network) -> Result<Self, Error>
Opens or creates the indexer database at the given path.
The database file is stored in a network-specific subdirectory to prevent mixing data from different networks (mainnet, testnet, signet, etc.).
Sourcepub async fn load_state(&self) -> Result<Option<IndexerState>, Error>
pub async fn load_state(&self) -> Result<Option<IndexerState>, Error>
Load indexer state from database.
Sourcepub async fn save_state(&self, state: &IndexerState) -> Result<(), Error>
pub async fn save_state(&self, state: &IndexerState) -> Result<(), Error>
Save indexer state to database.
Sourcepub async fn insert_block(
&self,
height: u32,
hash: &[u8; 32],
timestamp: u32,
) -> Result<(), Error>
pub async fn insert_block( &self, height: u32, hash: &[u8; 32], timestamp: u32, ) -> Result<(), Error>
Insert a block record.
Sourcepub async fn last_block_height(&self) -> Result<Option<u32>, Error>
pub async fn last_block_height(&self) -> Result<Option<u32>, Error>
Get the last indexed block height.
Sourcepub async fn insert_transaction(
&self,
txid: &Txid,
block_height: u32,
tx_index: u32,
) -> Result<(), Error>
pub async fn insert_transaction( &self, txid: &Txid, block_height: u32, tx_index: u32, ) -> Result<(), Error>
Insert a transaction record.
Sourcepub async fn get_transaction(
&self,
txid: &Txid,
) -> Result<Option<(u32, u32)>, Error>
pub async fn get_transaction( &self, txid: &Txid, ) -> Result<Option<(u32, u32)>, Error>
Get transaction position by txid.
Sourcepub async fn insert_output(
&self,
txid: &Txid,
vout: u32,
script_pubkey: &ScriptBuf,
value: u64,
block_height: u32,
) -> Result<(), Error>
pub async fn insert_output( &self, txid: &Txid, vout: u32, script_pubkey: &ScriptBuf, value: u64, block_height: u32, ) -> Result<(), Error>
Insert an output record.
Sourcepub async fn mark_output_spent(
&self,
outpoint: &OutPoint,
spent_txid: &Txid,
spent_vout: u32,
spent_block_height: u32,
) -> Result<(), Error>
pub async fn mark_output_spent( &self, outpoint: &OutPoint, spent_txid: &Txid, spent_vout: u32, spent_block_height: u32, ) -> Result<(), Error>
Mark an output as spent.
Sourcepub async fn get_output_info(
&self,
outpoint: &OutPoint,
) -> Result<Option<(String, u64)>, Error>
pub async fn get_output_info( &self, outpoint: &OutPoint, ) -> Result<Option<(String, u64)>, Error>
Get the address for an output (for computing deltas during spending).
Sourcepub async fn insert_address_history(
&self,
address: &str,
txid: &Txid,
block_height: u32,
delta: i64,
) -> Result<(), Error>
pub async fn insert_address_history( &self, address: &str, txid: &Txid, block_height: u32, delta: i64, ) -> Result<(), Error>
Insert an address history entry.
Sourcepub async fn revert_to_height(&self, height: u32) -> Result<(), Error>
pub async fn revert_to_height(&self, height: u32) -> Result<(), Error>
Revert all data above the given block height (for handling reorgs).
Sourcepub async fn begin_transaction(&self) -> Result<Transaction<'_, Sqlite>, Error>
pub async fn begin_transaction(&self) -> Result<Transaction<'_, Sqlite>, Error>
Begin a database transaction for batch operations.
Sourcepub fn parse_txid(bytes: &[u8]) -> Result<Txid, Error>
pub fn parse_txid(bytes: &[u8]) -> Result<Txid, Error>
Parse a txid from database bytes.
Sourcepub async fn index_block(
&self,
height: u32,
block: &Block,
network: Network,
) -> Result<(), Error>
pub async fn index_block( &self, height: u32, block: &Block, network: Network, ) -> Result<(), Error>
Index a single block in a database transaction (for live sync).
Sourcepub async fn index_blocks_batch(
&self,
blocks: &[(u32, Block)],
network: Network,
) -> Result<(), Error>
pub async fn index_blocks_batch( &self, blocks: &[(u32, Block)], network: Network, ) -> Result<(), Error>
Index multiple blocks in a single database transaction for better performance. Used during historical sync for batching, and indirectly for single blocks during live sync.
Optimized with:
- Bulk pre-fetch of outputs (eliminates N+1 queries)
- Collect all data in memory first, then bulk insert by table
- Pre-aggregate address history deltas (avoids ON CONFLICT overhead)
Trait Implementations§
Source§impl Clone for IndexerDatabase
impl Clone for IndexerDatabase
Source§fn clone(&self) -> IndexerDatabase
fn clone(&self) -> IndexerDatabase
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for IndexerDatabase
impl !RefUnwindSafe for IndexerDatabase
impl Send for IndexerDatabase
impl Sync for IndexerDatabase
impl Unpin for IndexerDatabase
impl !UnwindSafe for IndexerDatabase
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
§fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
§fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<Src, Dest> IntoTuple<Dest> for Srcwhere
Dest: FromTuple<Src>,
impl<Src, Dest> IntoTuple<Dest> for Srcwhere
Dest: FromTuple<Src>,
fn into_tuple(self) -> Dest
§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T. Read more§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from.§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T.