pub struct TxStore {
pub main: Tree,
pub location: Tree,
pub pending: Tree,
pub pending_order: Tree,
}
Expand description
The TxStore
is a structure representing all sled
trees related
to storing the blockchain’s transactions information.
Fields§
§main: Tree
Main sled
tree, storing all the blockchain’s transactions, where
the key is the transaction hash, and the value is the serialized
transaction.
location: Tree
The sled
tree storing the location of the blockchain’s transactions
locations, where the key is the transaction hash, and the value is a
serialized tuple containing the height and the vector index of the
block the transaction is included.
pending: Tree
The sled
tree storing all the node pending transactions, where
the key is the transaction hash, and the value is the serialized
transaction.
pending_order: Tree
The sled
tree storing the order of all the node pending transactions,
where the key is an incremental value, and the value is the serialized
transaction.
Implementations§
Source§impl TxStore
impl TxStore
Sourcepub fn new(db: &Db) -> Result<Self>
pub fn new(db: &Db) -> Result<Self>
Opens a new or existing TxStore
on the given sled database.
Sourcepub fn insert(
&self,
transactions: &[Transaction],
) -> Result<Vec<TransactionHash>>
pub fn insert( &self, transactions: &[Transaction], ) -> Result<Vec<TransactionHash>>
Insert a slice of Transaction
into the store’s main tree.
Sourcepub fn insert_location(
&self,
txs_hashes: &[TransactionHash],
block_height: u32,
) -> Result<()>
pub fn insert_location( &self, txs_hashes: &[TransactionHash], block_height: u32, ) -> Result<()>
Insert a slice of TransactionHash
into the store’s location tree.
Sourcepub fn insert_pending(
&self,
transactions: &[Transaction],
) -> Result<Vec<TransactionHash>>
pub fn insert_pending( &self, transactions: &[Transaction], ) -> Result<Vec<TransactionHash>>
Insert a slice of Transaction
into the store’s pending txs tree.
Sourcepub fn insert_pending_order(&self, txs_hashes: &[TransactionHash]) -> Result<()>
pub fn insert_pending_order(&self, txs_hashes: &[TransactionHash]) -> Result<()>
Insert a slice of TransactionHash
into the store’s pending txs order tree.
Sourcepub fn insert_batch(
&self,
transactions: &[Transaction],
) -> (Batch, Vec<TransactionHash>)
pub fn insert_batch( &self, transactions: &[Transaction], ) -> (Batch, Vec<TransactionHash>)
Generate the sled batch corresponding to an insert to the main tree,
so caller can handle the write operation.
The transactions are hashed with BLAKE3 and this hash is used as
the key, while the value is the serialized Transaction
itself.
On success, the function returns the transaction hashes in the same
order as the input transactions, along with the corresponding operation
batch.
Sourcepub fn insert_batch_location(
&self,
txs_hashes: &[TransactionHash],
block_height: u32,
) -> Batch
pub fn insert_batch_location( &self, txs_hashes: &[TransactionHash], block_height: u32, ) -> Batch
Generate the sled batch corresponding to an insert to the location tree, so caller can handle the write operation. The location tuple is built using the index of each transaction has in the slice, along with the provided block height
Sourcepub fn insert_batch_pending(
&self,
transactions: &[Transaction],
) -> (Batch, Vec<TransactionHash>)
pub fn insert_batch_pending( &self, transactions: &[Transaction], ) -> (Batch, Vec<TransactionHash>)
Generate the sled batch corresponding to an insert to the pending txs tree,
so caller can handle the write operation.
The transactions are hashed with BLAKE3 and this hash is used as
the key, while the value is the serialized Transaction
itself.
On success, the function returns the transaction hashes in the same
order as the input transactions, along with the corresponding operation
batch.
Sourcepub fn insert_batch_pending_order(
&self,
tx_hashes: &[TransactionHash],
) -> Result<Batch>
pub fn insert_batch_pending_order( &self, tx_hashes: &[TransactionHash], ) -> Result<Batch>
Generate the sled batch corresponding to an insert to the pending txs order tree, so caller can handle the write operation.
Sourcepub fn contains(&self, tx_hash: &TransactionHash) -> Result<bool>
pub fn contains(&self, tx_hash: &TransactionHash) -> Result<bool>
Check if the store’s main tree contains a given transaction hash.
Sourcepub fn contains_pending(&self, tx_hash: &TransactionHash) -> Result<bool>
pub fn contains_pending(&self, tx_hash: &TransactionHash) -> Result<bool>
Check if the store’s pending txs tree contains a given transaction hash.
Sourcepub fn get(
&self,
tx_hashes: &[TransactionHash],
strict: bool,
) -> Result<Vec<Option<Transaction>>>
pub fn get( &self, tx_hashes: &[TransactionHash], strict: bool, ) -> Result<Vec<Option<Transaction>>>
Fetch given tx hashes from the store’s main tree.
The resulting vector contains Option
, which is Some
if the tx
was found in the txstore, and otherwise it is None
, if it has not.
The second parameter is a boolean which tells the function to fail in
case at least one tx was not found.
Sourcepub fn get_location(
&self,
tx_hashes: &[TransactionHash],
strict: bool,
) -> Result<Vec<Option<(u32, u16)>>>
pub fn get_location( &self, tx_hashes: &[TransactionHash], strict: bool, ) -> Result<Vec<Option<(u32, u16)>>>
Fetch given tx hashes locations from the store’s location tree.
The resulting vector contains Option
, which is Some
if the tx
was found in the txstore, and otherwise it is None
, if it has not.
The second parameter is a boolean which tells the function to fail in
case at least one tx was not found.
Sourcepub fn get_pending(
&self,
tx_hashes: &[TransactionHash],
strict: bool,
) -> Result<Vec<Option<Transaction>>>
pub fn get_pending( &self, tx_hashes: &[TransactionHash], strict: bool, ) -> Result<Vec<Option<Transaction>>>
Fetch given tx hashes from the store’s pending txs tree.
The resulting vector contains Option
, which is Some
if the tx
was found in the pending tx store, and otherwise it is None
, if it has not.
The second parameter is a boolean which tells the function to fail in
case at least one tx was not found.
Sourcepub fn get_all(&self) -> Result<Vec<(TransactionHash, Transaction)>>
pub fn get_all(&self) -> Result<Vec<(TransactionHash, Transaction)>>
Retrieve all transactions from the store’s main tree in the form of
a tuple (tx_hash
, tx
).
Be careful as this will try to load everything in memory.
Sourcepub fn get_all_location(&self) -> Result<Vec<(TransactionHash, (u32, u16))>>
pub fn get_all_location(&self) -> Result<Vec<(TransactionHash, (u32, u16))>>
Retrieve all transactions locations from the store’s location tree in
the form of a tuple (tx_hash
, (block_height
, index
)).
Be careful as this will try to load everything in memory.
Sourcepub fn get_all_pending(&self) -> Result<HashMap<TransactionHash, Transaction>>
pub fn get_all_pending(&self) -> Result<HashMap<TransactionHash, Transaction>>
Retrieve all transactions from the store’s pending txs tree in the form of a HashMap with key the transaction hash and value the transaction itself. Be careful as this will try to load everything in memory.
Sourcepub fn get_all_pending_order(&self) -> Result<Vec<(u64, TransactionHash)>>
pub fn get_all_pending_order(&self) -> Result<Vec<(u64, TransactionHash)>>
Retrieve all transactions from the store’s pending txs order tree in
the form of a tuple (u64
, TransactionHash
).
Be careful as this will try to load everything in memory.
Sourcepub fn get_after_pending(
&self,
order: u64,
n: usize,
) -> Result<(u64, Vec<Transaction>)>
pub fn get_after_pending( &self, order: u64, n: usize, ) -> Result<(u64, Vec<Transaction>)>
Fetch n transactions after given order([order..order+n)). In the iteration, if a transaction order is not found, the iteration stops and the function returns what it has found so far in the store’s pending order tree.
Sourcepub fn remove_pending(&self, txs_hashes: &[TransactionHash]) -> Result<()>
pub fn remove_pending(&self, txs_hashes: &[TransactionHash]) -> Result<()>
Remove a slice of TransactionHash
from the store’s pending txs tree.
Sourcepub fn remove_pending_order(&self, indexes: &[u64]) -> Result<()>
pub fn remove_pending_order(&self, indexes: &[u64]) -> Result<()>
Remove a slice of u64
from the store’s pending txs order tree.
Sourcepub fn remove_batch_pending(&self, txs_hashes: &[TransactionHash]) -> Batch
pub fn remove_batch_pending(&self, txs_hashes: &[TransactionHash]) -> Batch
Generate the sled batch corresponding to a remove from the store’s pending txs tree, so caller can handle the write operation.
Sourcepub fn remove_batch_pending_order(&self, indexes: &[u64]) -> Batch
pub fn remove_batch_pending_order(&self, indexes: &[u64]) -> Batch
Generate the sled batch corresponding to a remove from the store’s pending txs order tree, so caller can handle the write operation.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TxStore
impl !RefUnwindSafe for TxStore
impl Send for TxStore
impl Sync for TxStore
impl Unpin for TxStore
impl !UnwindSafe for TxStore
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§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<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2where
T: SharedNiching<N1, N2>,
N1: Niching<T>,
N2: Niching<T>,
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2where
T: SharedNiching<N1, N2>,
N1: Niching<T>,
N2: Niching<T>,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Pointee for T
impl<T> Pointee for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.