Struct IndexerDatabase

Source
pub struct IndexerDatabase { /* private fields */ }
Expand description

SQLite database for the indexer.

Implementations§

Source§

impl IndexerDatabase

Source

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.).

Source

pub fn pool(&self) -> &SqlitePool

Get the underlying connection pool.

Source

pub fn network(&self) -> Network

Get the Bitcoin network.

Source

pub async fn load_state(&self) -> Result<Option<IndexerState>, Error>

Load indexer state from database.

Source

pub async fn save_state(&self, state: &IndexerState) -> Result<(), Error>

Save indexer state to database.

Source

pub async fn insert_block( &self, height: u32, hash: &[u8; 32], timestamp: u32, ) -> Result<(), Error>

Insert a block record.

Source

pub async fn last_block_height(&self) -> Result<Option<u32>, Error>

Get the last indexed block height.

Source

pub async fn insert_transaction( &self, txid: &Txid, block_height: u32, tx_index: u32, ) -> Result<(), Error>

Insert a transaction record.

Source

pub async fn get_transaction( &self, txid: &Txid, ) -> Result<Option<(u32, u32)>, Error>

Get transaction position by txid.

Source

pub async fn insert_output( &self, txid: &Txid, vout: u32, script_pubkey: &ScriptBuf, value: u64, block_height: u32, ) -> Result<(), Error>

Insert an output record.

Source

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.

Source

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).

Source

pub async fn insert_address_history( &self, address: &str, txid: &Txid, block_height: u32, delta: i64, ) -> Result<(), Error>

Insert an address history entry.

Source

pub async fn revert_to_height(&self, height: u32) -> Result<(), Error>

Revert all data above the given block height (for handling reorgs).

Source

pub async fn begin_transaction(&self) -> Result<Transaction<'_, Sqlite>, Error>

Begin a database transaction for batch operations.

Source

pub fn parse_txid(bytes: &[u8]) -> Result<Txid, Error>

Parse a txid from database bytes.

Source

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).

Source

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:

  1. Bulk pre-fetch of outputs (eliminates N+1 queries)
  2. Collect all data in memory first, then bulk insert by table
  3. Pre-aggregate address history deltas (avoids ON CONFLICT overhead)

Trait Implementations§

Source§

impl Clone for IndexerDatabase

Source§

fn clone(&self) -> IndexerDatabase

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CheckedConversion for T

§

fn checked_from<T>(t: T) -> Option<Self>
where Self: TryFrom<T>,

Convert from a value of T into an equivalent instance of Option<Self>. Read more
§

fn checked_into<T>(self) -> Option<T>
where Self: TryInto<T>,

Consume self to return Some equivalent value of Option<T>. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 Src
where Dest: FromTuple<Src>,

§

fn into_tuple(self) -> Dest

§

impl<T, Outer> IsWrappedBy<Outer> for T
where Outer: AsRef<T> + AsMut<T> + From<T>, T: From<Outer>,

§

fn from_ref(outer: &Outer) -> &T

Get a reference to the inner from the outer.

§

fn from_mut(outer: &mut Outer) -> &mut T

Get a mutable reference to the inner from the outer.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> SaturatedConversion for T

§

fn saturated_from<T>(t: T) -> Self
where Self: UniqueSaturatedFrom<T>,

Convert from a value of T into an equivalent instance of Self. Read more
§

fn saturated_into<T>(self) -> T
where Self: UniqueSaturatedInto<T>,

Consume self to return an equivalent value of T. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<S, T> UncheckedInto<T> for S
where T: UncheckedFrom<S>,

§

fn unchecked_into(self) -> T

The counterpart to unchecked_from.
§

impl<T, S> UniqueSaturatedInto<T> for S
where T: Bounded, S: TryInto<T>,

§

fn unique_saturated_into(self) -> T

Consume self to return an equivalent value of T.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> JsonSchemaMaybe for T