Skip to main content

TransactionHandler

Struct TransactionHandler 

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

Executes one, and only one, full SignedTransaction against the environment: root_invoke, then try_commit_transaction or abort_transaction.

Implementations§

Source§

impl TransactionHandler

Source

pub fn new(env: Rc<TestEnvironment>, stx: &SignedTransaction) -> Self

Open a handler for executing stx against env.

Source

pub fn root_invoke(&mut self) -> RootInvokeResult

Invokes the transaction represented by the TransactionHandler. This must be called before other methods that rely on actions taken within the transaction. This method must only be called once per transaction.

Returns the result of the root invocation. This does NOT commit the transaction to the database. The caller should subsequently call try_commit_transaction or abort_transaction before advancing to the next block.

try_commit_transaction checks the result of the root invocation, and will abort the transaction if the root invocation failed. So it is safe to call either try_commit_transaction or abort_transaction after root_invoke, regardless of whether the root invocation succeeded or failed.

Source

pub fn get_signed_transaction(&self) -> &SignedTransaction

The signed transaction this handler executes.

Source

pub fn try_commit_transaction(&mut self) -> TryCommitResult

Tries to commit the transaction to the database. This must be called after root_invoke, and only once per transaction.

Returns the TryCommitResult reported by the executor; check it to see whether the commit succeeded. On a nondeterministic (two-phase commit) failure it carries the storage-conflict diagnostic.

This will abort the transaction if the root invocation failed. So it is safe to call either try_commit_transaction or abort_transaction after root_invoke, regardless of whether the root invocation succeeded or failed.

§Panics

Panics if called before root_invoke, or if the transaction was already committed or aborted.

Source

pub fn abort_transaction(&mut self)

Aborts the transaction. This can only be called after root_invoke, and can only be called once per transaction.

Trait Implementations§

Source§

impl Drop for TransactionHandler

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> StaticIfNoAlloc for T

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.