Hey Daniel,
I'd say something like this works best as a project-local hack, rather than part of the library interface. The user can perfectly well do (execute "begin") outside of the macro, causing the *transaction* variable to no longer reflect the actual situation.
Best, Marijn