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
impl TransactionHandler
Sourcepub fn new(env: Rc<TestEnvironment>, stx: &SignedTransaction) -> Self
pub fn new(env: Rc<TestEnvironment>, stx: &SignedTransaction) -> Self
Open a handler for executing stx against env.
Sourcepub fn root_invoke(&mut self) -> RootInvokeResult
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.
Sourcepub fn get_signed_transaction(&self) -> &SignedTransaction
pub fn get_signed_transaction(&self) -> &SignedTransaction
The signed transaction this handler executes.
Sourcepub fn try_commit_transaction(&mut self) -> TryCommitResult
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.
Sourcepub fn abort_transaction(&mut self)
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.