You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: api/paidAction/README.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -194,6 +194,12 @@ All functions have the following signature: `function(args: Object, context: Obj
194
194
-`models`: the current prisma client (for anything that doesn't need to be done atomically with the payment)
195
195
-`lnd`: the current lnd client
196
196
197
+
## Recording Cowboy Credits
198
+
199
+
To avoid adding sats and credits together everywhere to show an aggregate sat value, in most cases we denormalize a `sats` field that carries the "sats value", the combined sats + credits of something, and a `credits` field that carries only the earned `credits`. For example, the `Item` table has an `msats` field that carries the sum of the `mcredits` and `msats` earned and a `mcredits` field that carries the value of the `mcredits` earned. So, the sats value an item earned is `item.msats` BUT the real sats earned is `item.msats - item.mcredits`.
200
+
201
+
The ONLY exception to this are for the `users` table where we store a stacker's rewards sats and credits balances separately.
202
+
197
203
## `IMPORTANT: transaction isolation`
198
204
199
205
We use a `read committed` isolation level for actions. This means paid actions need to be mindful of concurrency issues. Specifically, reading data from the database and then writing it back in `read committed` is a common source of consistency bugs (aka serialization anamolies).
0 commit comments