-
Notifications
You must be signed in to change notification settings - Fork 89
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
feat(backend): add local payment #2857
Merged
Merged
Changes from all commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
bb77152
feat(backend): add local payment quote migration
BlairCurrey fc06e24
feat(backend): WIP seperate ILPModels, LocalQuote, BaseQuote models
BlairCurrey 257fd01
refactor(backend): change model/services to reflect optional ilp quot…
BlairCurrey d9fa20e
Merge branch 'main' into bc/2834/non-ilp-local-payments
BlairCurrey 2e76ee2
feat(backend): WIP local payment method with getQuote
BlairCurrey 4fab5d8
feat(backend): add local payment method to payment method handler
BlairCurrey b17db75
chore(backend): fix format
BlairCurrey 6e37420
Merge branch 'main' into bc/2834/non-ilp-local-payments
BlairCurrey 9ef7f94
feat(backend): stub in control payment handler service with receiver …
BlairCurrey 320ee21
feat(backend): local payment .pay
BlairCurrey 07569a7
Merge branch 'main' into bc/2834/non-ilp-local-payments
BlairCurrey f3d5f5d
chore: rm comment
BlairCurrey d795ce2
chore: WIP debugging wrong sentAmount
BlairCurrey 251c60a
chore: rm comment
BlairCurrey 8f0bcb8
Merge branch 'main' into bc/2834/non-ilp-local-payments
BlairCurrey eca01f1
feat(backend): use receiver.isLocal to control payment method in quot…
BlairCurrey 770d7ea
Merge branch 'main' into bc/2834/non-ilp-local-payments
BlairCurrey 3849db7
Merge branch 'main' into bc/2834/non-ilp-local-payments
BlairCurrey 170bcc3
fix(backend): added source amount
BlairCurrey 88618ce
fix(backend): p2p case (cross currency, local, fixed send)
BlairCurrey 823c512
fix: lint error
BlairCurrey 2e9f043
chore: rm logs
BlairCurrey 3fb02e5
fix: quote service test
BlairCurrey 569f029
fix: lint errors
BlairCurrey dae1de1
Merge branch 'main' into bc/2834/non-ilp-local-payments
BlairCurrey 2016469
Merge branch 'main' into bc/2834/non-ilp-local-payments
BlairCurrey 3182944
refactor(backend): split migrations
BlairCurrey 3665188
refactor(backend): rm migration that was split into many
BlairCurrey 5b8bad3
WIP bruno requests for testing
BlairCurrey b49e08e
feat(backend): start rm ilpQuoteDetail join on op where not used
BlairCurrey eedacb5
fix(backend): rm unecessary ilpQuoteDetail join
BlairCurrey 27a64b2
chore(backend): format
BlairCurrey 26d0539
fix(backend): dont join op on quote.ilpQuoteDetails on get
BlairCurrey 2723961
fix(backend): rm ilpQuoteDetails join on op cancel
BlairCurrey 08126c5
fix(backend): rm unecessary join in op validate grant amount
BlairCurrey 205447d
fix(backend): rm join from fundPayment
BlairCurrey 0471d84
fix(backend): rm unecessary join, unused method
BlairCurrey 7b5142d
fix(backend): fetch ilpQuoteDetails where used instead of joining
BlairCurrey 773e4f2
chore(backend): move ilpquotedetails dir
BlairCurrey 0a3adf4
chore(backend): rm console.log
BlairCurrey 347f9b0
fix(backend): rm ilpQuoteDetails joins from quote service
BlairCurrey 37d399e
chore(backend): rm console.log
BlairCurrey 78d42b6
refactor(backend): rename sourceAmount to debitAmountMinusFees
BlairCurrey a96d654
chore(backend): cleanup, rm unused fee method
BlairCurrey 7941f05
test(backend): add local payment tests
BlairCurrey 753a57b
chore: format
BlairCurrey ed30066
Merge branch 'main' into bc/2834/non-ilp-local-payments
BlairCurrey 8476615
fix(bruno): local open payments requests
BlairCurrey f8a979c
test(backend): add integration tests for local payments
BlairCurrey 5cee618
chore(backend): cleanup
BlairCurrey d41777e
chore: restore old version of date definition in test
BlairCurrey e0f988d
chore: cleanup
BlairCurrey 5d631bd
fix: rm unused import
BlairCurrey ececad2
test(integration): new case - p2p, fixed-send, local
BlairCurrey 63011ae
chore(integration): rename test for consistency
BlairCurrey bd12e30
fix(backend): throw error in pay if incoming payment is not pending
BlairCurrey b0eaf8d
Merge branch 'main' into bc/2834/non-ilp-local-payments
BlairCurrey 0d69a3d
feat(backend): simplify migrations
BlairCurrey 31e6cc7
chore(backend): clarify comment
BlairCurrey bb9d334
chore(auth): format
BlairCurrey b0897d9
refactor(backend): use IlpQuoteDetails model directly in ilp payment …
BlairCurrey 2d8048a
refactor(backend): rm ilpQuoteDetails service
BlairCurrey 15d8929
Merge branch 'main' into bc/2834/non-ilp-local-payments
BlairCurrey c40db9e
fix(integration): wa typo
BlairCurrey 0dbb2d3
chore: rm bruno test examples
BlairCurrey 61b1010
refactor: mv debitAmountMinusFees to fee calc and clarify TODO
BlairCurrey 0dea97d
Merge branch 'main' into bc/2834/non-ilp-local-payments
BlairCurrey 6c995d9
Update bruno/collections/Rafiki/Examples/Admin API - only locally/Pe…
BlairCurrey 86f6db6
fix: make timeout required again
BlairCurrey 3fc6924
feat: error when post fails in local pay
BlairCurrey 6634b8f
refactor(backend): add optional quoteId to getQuote args
BlairCurrey 6706557
refactor: rm ilp quote details out of quote service
BlairCurrey 998ee25
refactor: insert ilp quote details in ilp getQuote
BlairCurrey a4cf57a
fix(backend): payment handler test
BlairCurrey 1835bc4
chore(bruno): rename request
BlairCurrey 7db833b
chore(integration): rm erroneous todo comment
BlairCurrey 4437438
Merge branch 'main' into bc/2834/non-ilp-local-payments
BlairCurrey 3149428
Merge branch 'main' into bc/2834/non-ilp-local-payments
BlairCurrey fe63991
fix(backend): local quote amounts, estimatedExchangeRaet
BlairCurrey e6cad1e
chore(backend): format
BlairCurrey f120aab
refactor(backend): rate convert methods to be explicit
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
72 changes: 72 additions & 0 deletions
72
...Examples/Admin API - only locally/Peer-to-Peer Local Payment/Create Outgoing Payment.bru
This file contains 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,72 @@ | ||
meta { | ||
name: Create Outgoing Payment | ||
type: graphql | ||
seq: 3 | ||
} | ||
|
||
post { | ||
url: {{RafikiGraphqlHost}}/graphql | ||
body: graphql | ||
auth: none | ||
} | ||
|
||
body:graphql { | ||
mutation CreateOutgoingPayment($input: CreateOutgoingPaymentInput!) { | ||
createOutgoingPayment(input: $input) { | ||
payment { | ||
createdAt | ||
error | ||
metadata | ||
id | ||
walletAddressId | ||
receiveAmount { | ||
assetCode | ||
assetScale | ||
value | ||
} | ||
receiver | ||
debitAmount { | ||
assetCode | ||
assetScale | ||
value | ||
} | ||
sentAmount { | ||
assetCode | ||
assetScale | ||
value | ||
} | ||
state | ||
stateAttempts | ||
} | ||
} | ||
} | ||
} | ||
|
||
body:graphql:vars { | ||
{ | ||
"input": { | ||
"walletAddressId": "{{gfranklinWalletAddressId}}", | ||
"quoteId": "{{quoteId}}" | ||
} | ||
} | ||
} | ||
|
||
script:pre-request { | ||
const scripts = require('./scripts'); | ||
|
||
scripts.addApiSignatureHeader(); | ||
} | ||
|
||
script:post-response { | ||
const body = res.getBody(); | ||
|
||
if (body?.data) { | ||
bru.setEnvVar("outgoingPaymentId", body.data.createOutgoingPayment.payment.id); | ||
} | ||
} | ||
|
||
tests { | ||
test("Outgoing Payment id is string", function() { | ||
expect(bru.getEnvVar("outgoingPaymentId")).to.be.a("string"); | ||
}) | ||
} |
66 changes: 66 additions & 0 deletions
66
...ons/Rafiki/Examples/Admin API - only locally/Peer-to-Peer Local Payment/Create Quote.bru
This file contains 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,66 @@ | ||
meta { | ||
name: Create Quote | ||
type: graphql | ||
seq: 2 | ||
} | ||
|
||
post { | ||
url: {{RafikiGraphqlHost}}/graphql | ||
body: graphql | ||
auth: none | ||
} | ||
|
||
body:graphql { | ||
mutation CreateQuote($input: CreateQuoteInput!) { | ||
createQuote(input: $input) { | ||
quote { | ||
createdAt | ||
expiresAt | ||
id | ||
walletAddressId | ||
receiveAmount { | ||
assetCode | ||
assetScale | ||
value | ||
} | ||
receiver | ||
debitAmount { | ||
assetCode | ||
assetScale | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
body:graphql:vars { | ||
{ | ||
"input": { | ||
"walletAddressId": "{{gfranklinWalletAddressId}}", | ||
"receiver": "{{receiverId}}" | ||
} | ||
} | ||
} | ||
|
||
script:pre-request { | ||
const scripts = require('./scripts'); | ||
|
||
await scripts.loadWalletAddressIdsIntoVariables(); | ||
|
||
scripts.addApiSignatureHeader(); | ||
} | ||
|
||
script:post-response { | ||
const body = res.getBody(); | ||
|
||
if (body?.data) { | ||
bru.setEnvVar("quoteId", body.data.createQuote.quote.id); | ||
} | ||
} | ||
|
||
tests { | ||
test("Quote id is string", function() { | ||
expect(bru.getEnvVar("quoteId")).to.be.a("string"); | ||
}) | ||
} |
73 changes: 73 additions & 0 deletions
73
...I - only locally/Peer-to-Peer Local Payment/Create Receiver -local Incoming Payment-.bru
This file contains 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,73 @@ | ||
meta { | ||
name: Create Receiver -local Incoming Payment- | ||
type: graphql | ||
seq: 1 | ||
} | ||
|
||
post { | ||
url: {{RafikiGraphqlHost}}/graphql | ||
body: graphql | ||
auth: none | ||
} | ||
|
||
body:graphql { | ||
mutation CreateReceiver($input: CreateReceiverInput!) { | ||
createReceiver(input: $input) { | ||
receiver { | ||
completed | ||
createdAt | ||
expiresAt | ||
metadata | ||
id | ||
incomingAmount { | ||
assetCode | ||
assetScale | ||
value | ||
} | ||
walletAddressUrl | ||
receivedAmount { | ||
assetCode | ||
assetScale | ||
value | ||
} | ||
updatedAt | ||
} | ||
} | ||
} | ||
} | ||
|
||
body:graphql:vars { | ||
{ | ||
"input": { | ||
"metadata": { | ||
"description": "For lunch!" | ||
}, | ||
"incomingAmount": { | ||
"assetCode": "USD", | ||
"assetScale": 2, | ||
"value": 500 | ||
}, | ||
"walletAddressUrl": "https://cloud-nine-wallet-backend/accounts/bhamchest" | ||
} | ||
} | ||
} | ||
|
||
script:pre-request { | ||
const scripts = require('./scripts'); | ||
|
||
scripts.addApiSignatureHeader(); | ||
} | ||
|
||
script:post-response { | ||
const body = res.getBody(); | ||
|
||
if (body?.data) { | ||
bru.setEnvVar("receiverId", body.data.createReceiver.receiver.id); | ||
} | ||
} | ||
|
||
tests { | ||
test("Receiver id is string", function() { | ||
expect(bru.getEnvVar("receiverId")).to.be.a("string"); | ||
}) | ||
} |
57 changes: 57 additions & 0 deletions
57
...ki/Examples/Admin API - only locally/Peer-to-Peer Local Payment/Get Outgoing Payment.bru
This file contains 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,57 @@ | ||
meta { | ||
name: Get Outgoing Payment | ||
type: graphql | ||
seq: 4 | ||
} | ||
|
||
post { | ||
url: {{RafikiGraphqlHost}}/graphql | ||
body: graphql | ||
auth: none | ||
} | ||
|
||
body:graphql { | ||
query GetOutgoingPayment($id: String!) { | ||
outgoingPayment(id: $id) { | ||
createdAt | ||
error | ||
metadata | ||
id | ||
grantId | ||
walletAddressId | ||
quote { | ||
id | ||
} | ||
receiveAmount { | ||
assetCode | ||
assetScale | ||
value | ||
} | ||
receiver | ||
debitAmount { | ||
assetCode | ||
assetScale | ||
value | ||
} | ||
sentAmount { | ||
assetCode | ||
assetScale | ||
value | ||
} | ||
state | ||
stateAttempts | ||
} | ||
} | ||
} | ||
|
||
body:graphql:vars { | ||
{ | ||
"id": "{{outgoingPaymentId}}" | ||
} | ||
} | ||
|
||
script:pre-request { | ||
const scripts = require('./scripts'); | ||
|
||
scripts.addApiSignatureHeader(); | ||
} |
This file contains 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
30 changes: 30 additions & 0 deletions
30
packages/backend/migrations/20240916181643_require_estimated_exchange_rate.js
This file contains 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,30 @@ | ||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
|
||
exports.up = function (knex) { | ||
return knex('quotes') | ||
.whereNull('estimatedExchangeRate') | ||
.update({ | ||
estimatedExchangeRate: knex.raw('?? / ??', [ | ||
'lowEstimatedExchangeRateNumerator', | ||
'lowEstimatedExchangeRateDenominator' | ||
]) | ||
}) | ||
.then(() => { | ||
return knex.schema.table('quotes', (table) => { | ||
table.decimal('estimatedExchangeRate', 20, 10).notNullable().alter() | ||
}) | ||
}) | ||
} | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.down = function (knex) { | ||
return knex.schema.table('quotes', (table) => { | ||
table.decimal('estimatedExchangeRate', 20, 10).nullable().alter() | ||
}) | ||
} |
68 changes: 68 additions & 0 deletions
68
packages/backend/migrations/20240916181659_add_ilp_quote_details.js
This file contains 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,68 @@ | ||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.up = function (knex) { | ||
return ( | ||
knex.schema | ||
// Create new table with columns from "quotes" to migrate | ||
.createTable('ilpQuoteDetails', function (table) { | ||
table.uuid('id').notNullable().primary() | ||
|
||
// quoteId is purposefully not a FK referencing quote.id | ||
// this allows us to create ilpQuoteDetail before quotes in service of | ||
// fully decoupling payment method/quote services. | ||
// https://github.com/interledger/rafiki/pull/2857#discussion_r1825891327 | ||
table.uuid('quoteId').notNullable().unique().index() | ||
|
||
table.bigInteger('maxPacketAmount').notNullable() | ||
table.decimal('minExchangeRateNumerator', 64, 0).notNullable() | ||
table.decimal('minExchangeRateDenominator', 64, 0).notNullable() | ||
table.decimal('lowEstimatedExchangeRateNumerator', 64, 0).notNullable() | ||
table | ||
.decimal('lowEstimatedExchangeRateDenominator', 64, 0) | ||
.notNullable() | ||
table.decimal('highEstimatedExchangeRateNumerator', 64, 0).notNullable() | ||
table | ||
.decimal('highEstimatedExchangeRateDenominator', 64, 0) | ||
.notNullable() | ||
|
||
table.timestamp('createdAt').defaultTo(knex.fn.now()) | ||
table.timestamp('updatedAt').defaultTo(knex.fn.now()) | ||
}) | ||
.then(() => { | ||
return knex.raw(` | ||
INSERT INTO "ilpQuoteDetails" ( | ||
id, | ||
"quoteId", | ||
"maxPacketAmount", | ||
"minExchangeRateNumerator", | ||
"minExchangeRateDenominator", | ||
"lowEstimatedExchangeRateNumerator", | ||
"lowEstimatedExchangeRateDenominator", | ||
"highEstimatedExchangeRateNumerator", | ||
"highEstimatedExchangeRateDenominator" | ||
) | ||
SELECT | ||
gen_random_uuid(), | ||
id AS "quoteId", | ||
"maxPacketAmount", | ||
"minExchangeRateNumerator", | ||
"minExchangeRateDenominator", | ||
"lowEstimatedExchangeRateNumerator", | ||
"lowEstimatedExchangeRateDenominator", | ||
"highEstimatedExchangeRateNumerator", | ||
"highEstimatedExchangeRateDenominator" | ||
FROM "quotes"; | ||
`) | ||
}) | ||
) | ||
} | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.down = function (knex) { | ||
return knex.schema.dropTableIfExists('ilpQuoteDetails') | ||
} |
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.
In which cases the
estimatedExchangeRate
was null?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 dont know of any specific cases where it would be null, but since it's nullable we should handle that possibility.