essential_node::db

Struct ConnectionPool

source
pub struct ConnectionPool(/* private fields */);
Expand description

Access to the node’s DB connection pool and DB-access-related methods.

The handle is safe to clone and share between threads.

Implementations§

source§

impl ConnectionPool

source

pub fn new(conf: &Config) -> Result<Self>

Create the connection pool from the given configuration.

source

pub async fn acquire(&self) -> Result<ConnectionHandle, AcquireError>

Acquire a temporary database ConnectionHandle from the inner pool.

In the case that all connections are busy, waits for the first available connection.

source

pub fn try_acquire(&self) -> Result<ConnectionHandle, TryAcquireError>

Attempt to synchronously acquire a temporary database ConnectionHandle from the inner pool.

Returns Err in the case that all database connections are busy or if the node has been closed.

source

pub fn close(&self) -> Result<(), ConnectionCloseErrors>

Close a connection pool, returning a ConnectionCloseErrors in the case of any errors.

source§

impl ConnectionPool

Short-hand methods for async DB access.

source

pub async fn acquire_then<F, T, E>( &self, f: F, ) -> Result<T, AcquireThenError<E>>
where F: 'static + Send + FnOnce(&mut ConnectionHandle) -> Result<T, E>, T: 'static + Send, E: 'static + Send,

Asynchronous access to the node’s DB via the given function.

Requests and awaits a connection from the connection pool, then spawns a blocking task for the given function providing access to the connection handle.

source

pub async fn create_tables(&self) -> Result<(), AcquireThenRusqliteError>

Create all database tables.

source

pub async fn insert_block( &self, block: Arc<Block>, ) -> Result<ContentAddress, AcquireThenRusqliteError>

Insert the given block into the block table and for each of its solutions, add a row into the solution and block_solution tables.

source

pub async fn finalize_block( &self, block_ca: ContentAddress, ) -> Result<(), AcquireThenRusqliteError>

Finalizes the block with the given hash. This sets the block to be the only block at a particular block number.

source

pub async fn update_state( &self, contract_ca: ContentAddress, key: Key, value: Value, ) -> Result<(), AcquireThenRusqliteError>

Updates the state for a given contract content address and key.

source

pub async fn delete_state( &self, contract_ca: ContentAddress, key: Key, ) -> Result<(), AcquireThenRusqliteError>

Deletes the state for a given contract content address and key.

source

pub async fn get_solution( &self, ca: ContentAddress, ) -> Result<Option<Solution>, AcquireThenQueryError>

Fetches a solution by its content address.

source

pub async fn query_state( &self, contract_ca: ContentAddress, key: Key, ) -> Result<Option<Value>, AcquireThenQueryError>

Fetches the state value for the given contract content address and key pair.

source

pub async fn get_state_progress( &self, ) -> Result<Option<ContentAddress>, AcquireThenQueryError>

Get the state progress, returning the last block hash.

source

pub async fn get_validation_progress( &self, ) -> Result<Option<ContentAddress>, AcquireThenQueryError>

Get the validation progress, returning the last block hash.

source

pub async fn update_validation_progress( &self, block_ca: ContentAddress, ) -> Result<(), AcquireThenRusqliteError>

Update the validation progress to point to the block with the given CA.

source

pub async fn list_blocks( &self, block_range: Range<Word>, ) -> Result<Vec<Block>, AcquireThenQueryError>

Lists all blocks in the given range.

source

pub async fn list_blocks_by_time( &self, range: Range<Duration>, page_size: i64, page_number: i64, ) -> Result<Vec<Block>, AcquireThenQueryError>

Lists blocks and their solutions within a specific time range with pagination.

source

pub fn subscribe_blocks( &self, start_block: Word, await_new_block: impl AwaitNewBlock, ) -> impl Stream<Item = Result<Block, QueryError>>

Subscribe to all blocks from the given starting block number.

Trait Implementations§

source§

impl AcquireConnection for ConnectionPool

source§

async fn acquire_connection(&self) -> Option<impl 'static + AsRef<Connection>>

Asynchronously acquire a handle to a Connection. Read more
source§

impl Clone for ConnectionPool

source§

fn clone(&self) -> ConnectionPool

Returns a copy of the value. Read more
1.0.0 · source§

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
source§

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

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

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

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

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

Initializes a with the given initializer. Read more
source§

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

Dereferences the given pointer. Read more
source§

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

Mutably dereferences the given pointer. Read more
source§

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
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.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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