ConnectionPool

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.

Note that this function does not initialise the node DB tables by default. See the ConnectionPool::with_tables constructor.

Source

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

Create the connection pool from the given configuration and ensure the DB tables have been created if they do not already exist before returning.

## Example

let conf = essential_node_db::pool::Config::default();
let db = essential_node_db::ConnectionPool::with_tables(&conf).unwrap();
for block in db.list_blocks(0..100).await.unwrap() {
    println!("Block: {block:?}");
}
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 solution sets, add a row into the solution_set and block_solution_set 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_block( &self, block_address: ContentAddress, ) -> Result<Option<Block>, AcquireThenQueryError>

Fetches a block by its hash.

Source

pub async fn get_solution_set( &self, ca: ContentAddress, ) -> Result<SolutionSet, AcquireThenQueryError>

Fetches a solution set 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 query_latest_finalized_block( &self, contract_ca: ContentAddress, key: Key, ) -> Result<Option<Value>, AcquireThenQueryError>

Fetches the state value for the given contract content address and key pair within a range of blocks.

Source

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

Fetches the state value for the given contract content address and key pair within a range of blocks inclusive. ..=block.

Source

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

Fetches the state value for the given contract content address and key pair within a range of blocks exclusive. ..block.

Source

pub async fn query_state_finalized_inclusive_solution_set( &self, contract_ca: ContentAddress, key: Key, block_number: Word, solution_set_ix: u64, ) -> Result<Option<Value>, AcquireThenQueryError>

Fetches the state value for the given contract content address and key pair within a range of blocks and solution sets inclusive. ..block[..=solution_set].

Source

pub async fn query_state_finalized_exclusive_solution_set( &self, contract_ca: ContentAddress, key: Key, block_number: Word, solution_set_ix: u64, ) -> Result<Option<Value>, AcquireThenQueryError>

Fetches the state value for the given contract content address and key pair within a range of blocks and solution sets exclusive. ..=block[..solution_set].

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 get_next_block_addresses( &self, current_block: ContentAddress, ) -> Result<Vec<ContentAddress>, AcquireThenQueryError>

Get next block(s) given the current 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 solution sets 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 + AsMut<Connection>>

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

impl AsRef<AsyncConnectionPool> for ConnectionPool

Source§

fn as_ref(&self) -> &AsyncConnectionPool

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for ConnectionPool

Source§

fn clone(&self) -> ConnectionPool

Returns a duplicate 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, 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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