[#wallet-RunWithinTxn]
= xref:wallet.adoc[wallet]::RunWithinTxn
:relfileprefix: ../
:mrdocs:

Executes the provided function &apos;func&apos; within a database transaction context&period;

== Synopsis

Declared in `&lt;wallet&sol;walletdb&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
bool
RunWithinTxn(
    xref:wallet/WalletDatabase.adoc[WalletDatabase]& database,
    std::string&lowbar;view process&lowbar;desc,
    std::function&lt;bool(xref:wallet/WalletBatch.adoc[WalletBatch]&)&gt; const& func);
----

== Description

This function ensures that all db modifications performed within &apos;func()&apos; are atomically committed to the db at the end of the process&period; And, in case of a failure during execution, all performed changes are rolled back&period;

== Return Value

true if the db txn executed successfully, false otherwise&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *database*
| The db connection instance to perform the transaction on&period;
| *process&lowbar;desc*
| A description of the process being executed, used for logging purposes in the event of a failure&period;
| *func*
| The function to be executed within the db txn context&period; It returns a boolean indicating whether to commit or roll back the txn&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
