Transactions model #1
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
the transactions table will track multi-currency balance changes on users
each row in the table has the user_id sats_balance cents_balance, and metadata
a transaction has a type one of:
CREDIT - a manual increase in credit granted by admin
REWARD - an automatic increase in credit applied as a reward
REDEEM - a user-consenting or automatic decrease in credit spent on the store or subscription
REVOKE - a manual decrease in credit invoked by an admin
DEPOSIT - an automatic increase in credit from user deposits
These types should be in an enum or something
create a method
getUserBalanceById(user_id)
to get the user's balance of both currencies by user_id, just use SUM() on balance fields for all tx by user_idcreate a method
add(allRequiredFields)
to add a tx - include some sanity checks and validation in this function, i.e. no negative balances, make sure a user has the funds, make sure if the transaction type is an increase the balance change is positive, if a decrease negative, no decimalscreate a method
getRecent(n)
to get the n most recent transactionscreate a method
getWhales(n, currency)
to get the n top users by balance of each currencycreate a method
liabilities(currency)
to get the total amount of currency owed to users by the store