Open
Description
Currently, when an outgoing payment is being created under a particular grant, we need to make sure that the outgoing payment is within the particular limits of the grant (and the grant's interval).
Instead of doing what we are currently doing: grabbing all of the outgoing payments under that grant and calculating the limits in memory, we can leverage the outgoingPaymentGrantSpentAmounts
table created in RAF-1032.
When an outgoing payment is being created we need to:
- Fetch the existing
outgoingPaymentGrant
, and at the same time, grab the most recentoutgoingPaymentGrantSpentAmounts
row:- When fetching the
outgoingPaymentGrants
we need to use the FOR NO KEY UPDATE lock to prevent any concurrency issues - To fetch the most recent
outgoingPaymentGrantSpentAmounts
row:SELECT * FROM “outgoingPaymentGrantSpentAmounts” WHERE grantId = {grantId} ORDER BY createdAt DESC LIMIT 1
.
- When fetching the
After we fetch both, in order to make this a backwards compatible change (since we will have existing grants that will not end up having any outgoingPaymentGrantSpentAmounts records yet), we will need to do the following (pseudocode):
if (outgoingPaymentGrantRecord && !outgoingPaymentGrantSpentAmountsRecord) {
// in this case, an existing grant is being requested. We haven't stored any records
// for it in outgoingPaymentGrantSpentAmountsRecord, so we need to use the old calculation
// in `validateGrantAndAddSpentAmountsToPayment` to generate the first values we will insert
// in the outgoingPaymentGrantSpentAmounts table:
// 1. upsert outgoingPaymentGrant
// 2. Determine new cumulative grant amounts using existing validateGrantAndAddSpentAmountsToPayment logic
// 3. Fail if payment exceeds grant or interval limits
// 4. insert new outgoingPaymentGrantSpentAmounts record
} else {
// 1. upsert outgoingPaymentGrant
// 2. Determine new cumulative grant amounts (use existing outgoingPaymentGrantSpentAmountsRecord as starting point if present)
// 3. Fail if payment exceeds grant or interval limits
// 4. insert new outgoingPaymentGrantSpentAmounts record
}
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Backlog