-
Notifications
You must be signed in to change notification settings - Fork 104
feat: grant spent amounts #3757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BlairCurrey
wants to merge
22
commits into
main
Choose a base branch
from
bc/raf-1031/grant-spent-amounts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
4374044
feat: add grant spent amount table (#3389)
BlairCurrey f9ad11f
Merge branch 'main' into bc/raf-1031/grant-spent-amounts
BlairCurrey 06e3acf
Merge branch 'main' into bc/raf-1031/grant-spent-amounts
BlairCurrey 7a522db
feat: calculate grant spent amounts from new table (#3412)
BlairCurrey 1be38b5
feat: handle grant spent amount calculation on payment completion (#3…
BlairCurrey eacf1c5
Merge branch 'main' into bc/raf-1031/grant-spent-amounts
BlairCurrey bb46de4
fix: test to use tenantid
BlairCurrey eed6d10
fix: update lifecycle tests for mt
BlairCurrey 23756ed
feat: use new open payments spec version
BlairCurrey e637544
fix: failing lifecycle tests
BlairCurrey a922f95
feat: add /GET outgoing-payment-grant route (#3756)
BlairCurrey 6608da7
Merge branch 'main' into bc/raf-1031/grant-spent-amounts
BlairCurrey 1371fb9
fix: import
BlairCurrey c94cf27
chore: fix typo in bruno folder
BlairCurrey a7c3b38
fix: calculate legacy path in get spent amounts
BlairCurrey ddbe537
refactor: simplifiy get grant spent amounts logic
BlairCurrey 465e92b
fix: migrate legacy payments
BlairCurrey bf27169
fix: use trx
BlairCurrey 0214779
test(backend): ensure middleware next is called
BlairCurrey 1b8d896
Merge branch 'main' into bc/raf-1031/grant-spent-amounts
BlairCurrey 457478b
fix(backend): fix potential precision loss
BlairCurrey 99d5ed9
feat: add metric to unexpected state (that doesnt error)
BlairCurrey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...ctions/Rafiki/Examples/Vailidating Wallet Address Ownership with Open Payments/folder.bru
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| meta { | ||
| name: Vailidating Wallet Address Ownership with Open Payments | ||
| name: Validating Wallet Address Ownership with Open Payments | ||
| seq: 6 | ||
| } |
33 changes: 33 additions & 0 deletions
33
...llections/Rafiki/Open Payments APIs/Outgoing Payment Grant/Get Outgoing Payment Grant.bru
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| meta { | ||
| name: Get Outgoing Payment Grant | ||
| type: http | ||
| seq: 1 | ||
| } | ||
|
|
||
| get { | ||
| url: {{senderOpenPaymentsHost}}/outgoing-payment-grant | ||
| body: json | ||
| auth: none | ||
| } | ||
|
|
||
| headers { | ||
| Authorization: GNAP {{accessToken}} | ||
| } | ||
|
|
||
| script:pre-request { | ||
| const scripts = require('./scripts'); | ||
|
|
||
| scripts.addHostHeader(); | ||
|
|
||
| await scripts.addSignatureHeaders(); | ||
| } | ||
|
|
||
| tests { | ||
| test("Status code is 201", function() { | ||
| expect(res.getStatus()).to.equal(200); | ||
| }); | ||
| } | ||
|
|
||
| docs { | ||
| Uses GNAP access token to determine the grant. | ||
| } |
Submodule open-payments-specifications
updated
4 files
| +1 −1 | VERSION | |
| +87 −18 | openapi/auth-server.yaml | |
| +45 −3 | openapi/resource-server.yaml | |
| +1 −1 | openapi/wallet-address-server.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/backend/migrations/20250409173617_add_outgoing_payment_grant_spent_amounts_table.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /** | ||
| * @param { import("knex").Knex } knex | ||
| * @returns { Promise<void> } | ||
| */ | ||
| exports.up = function (knex) { | ||
| return knex.schema | ||
| .createTable('outgoingPaymentGrantSpentAmounts', function (table) { | ||
| table.uuid('id').notNullable().primary() | ||
| table.string('grantId').notNullable() | ||
| table.foreign('grantId').references('outgoingPaymentGrants.id') | ||
| table.uuid('outgoingPaymentId').notNullable() | ||
| table.foreign('outgoingPaymentId').references('outgoingPayments.id') | ||
| table.integer('receiveAmountScale').notNullable() | ||
| table.string('receiveAmountCode').notNullable() | ||
| table.bigInteger('paymentReceiveAmountValue').notNullable() | ||
| table.bigInteger('intervalReceiveAmountValue').nullable() | ||
| table.bigInteger('grantTotalReceiveAmountValue').notNullable() | ||
| table.integer('debitAmountScale').notNullable() | ||
| table.string('debitAmountCode').notNullable() | ||
| table.bigInteger('paymentDebitAmountValue').notNullable() | ||
| table.bigInteger('intervalDebitAmountValue').nullable() | ||
| table.bigInteger('grantTotalDebitAmountValue').notNullable() | ||
| table.string('paymentState').notNullable() | ||
| table.timestamp('intervalStart').nullable() | ||
| table.timestamp('intervalEnd').nullable() | ||
| table.timestamp('createdAt').defaultTo(knex.fn.now()) | ||
| }) | ||
| .then(() => { | ||
| return knex.raw( | ||
| 'CREATE INDEX outgoingPaymentGrantSpentAmounts_grantId_createdAt_desc_idx ON "outgoingPaymentGrantSpentAmounts" ("grantId", "createdAt" DESC)' | ||
| ) | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @param { import("knex").Knex } knex | ||
| * @returns { Promise<void> } | ||
| */ | ||
| exports.down = function (knex) { | ||
| return knex.schema.dropTableIfExists('outgoingPaymentGrantSpentAmounts') | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
packages/backend/migrations/20250410162417_add_interval_op_grant_table.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /** | ||
| * @param { import("knex").Knex } knex | ||
| * @returns { Promise<void> } | ||
| */ | ||
| exports.up = function (knex) { | ||
| return knex.schema.alterTable('outgoingPaymentGrants', function (table) { | ||
| table.string('interval').nullable() | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @param { import("knex").Knex } knex | ||
| * @returns { Promise<void> } | ||
| */ | ||
| exports.down = function (knex) { | ||
| return knex.schema.alterTable('outgoingPaymentGrants', function (table) { | ||
| table.dropColumn('interval') | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll leave it for now.... but I was thinking about changing this:
'CREATE INDEX outgoingPaymentGrantSpentAmounts_grantId_createdAt_desc_idx ON "outgoingPaymentGrantSpentAmounts" ("grantId", "createdAt" DESC)'To include the interval fields:
because we look it up like this in the worker when processing the payment:
Dont have great intuition on tradeoffs. I guess it would slow writes some amount in all cases and speed up reads some amount in a subset of cases (when we lookup by interval - only in worker I think). Probably no db storage space difference since a created_at index is going to already lead to a unique index entry per row. Overall I guess it feels like a bad idea. I guess we probably read a bit more (read and write on create, read and write in worker, read in
GET /outgoing-payment-grant) but we only lookup by interval in one place.