qb-core icon indicating copy to clipboard operation
qb-core copied to clipboard

[SUGGESTION] Implement monetary transactions as a function

Open LordChunk opened this issue 2 years ago • 2 comments

The problem

It is currently impossible to safely conduct transactions between players. The most common way is to use the AddMoney and RemoveMoney functions, but this causes several problems.

Firstly, it is not possible to see where money comes from. Yes, you do have a reason parameter, but this is optional.

You can't use SQL transactions to safely update players' balance, as the mutations are running separately.

Ideal solution

Store player balances separately from the player table in a dedicated table with support for different bank account types. Also have a table for tracking transactions between accounts and other bank account mutations. Also, have a dedicated function for transferring money between different accounts.

Alternative solutions

Implement a money transfer method. This would not require a dedicated table, which would lead to big migration overhead for existing servers. This transfer method would be able to transfer money of both cash and bank balances to different users, or be able to convert cash to bank balances and vice versa.

Additional context

No response

LordChunk avatar Feb 09 '23 15:02 LordChunk

You can't use SQL transactions to safely update players' balance, as the mutations are running separately.

I'm confused by your wording here, since I'm not sure if you are speaking about SQL Transactions or just a transaction, the act of exchanging something, so I'll propose a implementation assuming you are speaking about a normal transaction.

Upon reading thru the oxmysql documentation, there is a method, called a transaction that only executes at the same time, and if a problem occurs a rollback occurs, so this would be the indicated method to use on said implementation of your idea.

PatalJunior avatar Feb 18 '23 16:02 PatalJunior

In your quoted line I'm talking about SQL transactions (not monetary transactions).

I am ware of oxmysql's support for SQL transactions, but you cannot use those if you wish to use the native QB-Core events as these do not allow you to pass a SQL transaction. Fruthermore, events to update a player's balance may also be triggered from the client in which case you can't create an SQL transaction outright.

LordChunk avatar Mar 06 '23 13:03 LordChunk