Executes the provided function 'func' within a database transaction context.

Synopsis

Declared in <wallet/walletdb.h>

bool
RunWithinTxn(
    WalletDatabase& database,
    std::string_view process_desc,
    std::function<bool(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

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.

Created with MrDocs