[#wallet-RunWithinTxn] = xref:wallet.adoc[wallet]::RunWithinTxn :relfileprefix: ../ :mrdocs: Executes the provided function 'func' within a database transaction context. == Synopsis Declared in `<wallet/walletdb.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- bool RunWithinTxn( xref:wallet/WalletDatabase.adoc[WalletDatabase]& database, std::string_view process_desc, std::function<bool(xref:wallet/WalletBatch.adoc[WalletBatch]&)> const& func); ---- == Description This function ensures that all db modifications performed within 'func()' are atomically committed to the db at the end of the process. And, in case of a failure during execution, all performed changes are rolled back. == Return Value true if the db txn executed successfully, false otherwise. == Parameters [cols="1,4"] |=== | Name| Description | *database* | The db connection instance to perform the transaction on. | *process_desc* | A description of the process being executed, used for logging purposes in the event of a failure. | *func* | The function to be executed within the db txn context. It returns a boolean indicating whether to commit or roll back the txn. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#