Skip to content
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

fix(backend): remove wallet address from OP response id and fix receiver service #2115

Merged
merged 9 commits into from
Oct 25, 2023

Conversation

sabineschaller
Copy link
Member

@sabineschaller sabineschaller commented Oct 25, 2023

Changes proposed in this pull request

  • removes wallet address from id in OP responses (incoming payment, quote, outgoing payment)
  • adds auth server url to public incoming payment response
  • fixes receiver service to get public incoming payment instead of wallet address to figure out where to find the auth server
  • fixes getting the wallet address on resource GET requests through the wallet address middleware

Context

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Documentation added
  • Make sure that all checks pass
  • Postman collection updated

@github-actions github-actions bot added type: tests Testing related pkg: backend Changes in the backend package. type: source Changes business logic labels Oct 25, 2023
@sabineschaller sabineschaller marked this pull request as ready for review October 25, 2023 14:34
Copy link
Contributor

@BlairCurrey BlairCurrey Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it the changes here mean we can remove the wallet address from body/query params in the open payments spec for /quotes, /incoming-payments, /outgoing-payments, correct? Since we're just getting it via the resource id.

Copy link
Contributor

@mkurapov mkurapov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first pass

@@ -477,6 +477,7 @@ export class App {
// Read incoming payment
router.get<DefaultState, SubresourceContextWithAuthenticatedStatus>(
'/incoming-payments/:id',
createWalletAddressMiddleware(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this middleware is already fetching the resources, does it make sense to also then call incomingPaymentRoutes.get?

(applies to all of them)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could (this isn't great per se) store the fetched resource right on the context, and the skip the second lookup if we already have something defined in the ctx

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per call, disregard ^

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create issue for that @mkurapov

id: ctx.params.id
})
if (!incomingPayment || !incomingPayment.walletAddress) {
ctx.throw(401)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

401 as to not give away whether the resource exists or not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't really thinking that through but I think that counts as reasoning ;-)

ctx.walletAddressUrl = ctx.query['wallet-address'] as string
} else if (ctx.method === 'POST') {
ctx.walletAddressUrl = (ctx.request.body as CreateBody).walletAddress
if (ctx.method === 'GET') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should break this up into multiple middlewares or at least separate functions in this file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later. Please create issue 😉

@mkurapov
Copy link
Contributor

@BlairCurrey

I take it the changes here mean we can remove the wallet address from body/query params in the open payments spec for /quotes, /incoming-payments, /outgoing-payments, correct? Since we're just getting it via the resource id.

We still need it, during resource creation we don't have the resource id yet so we need a way to specify for which walletAddress the request is for

Likewise when we are GETting a list of resources, we don't have just a single resource to go off of

return undefined
}
const publicIncomingPayment = await publicIncomingPaymentResponse.json()
if (!publicIncomingPayment || !publicIncomingPayment.authServer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have an issue for adding authServer to the public incoming payment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet. It also needs to be added to the spec. Once we have that, we can use the op sdk

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

})
ctx.body = incomingPayment?.toPublicOpenPaymentsType()
ctx.body = incomingPayment?.toPublicOpenPaymentsType(
deps.config.authServerGrantUrl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would there ever be a reason we'd need to return this in the private incoming payment response as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so because if you can get a private one, you've already gone through the auth flow.

})
if (!walletAddress) {
// TODO: replace with OP client method
// const publicIncomingPayment =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep it to not forget?

ctx.walletAddressUrl = ctx.query['wallet-address'] as string
} else if (ctx.method === 'POST') {
ctx.walletAddressUrl = (ctx.request.body as CreateBody).walletAddress
console.log(ctx.walletAddressUrl)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to keep this console.log?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gone

@sabineschaller sabineschaller merged commit 6aea8ba into nl-open-payments-updates Oct 25, 2023
@sabineschaller sabineschaller deleted the s2-fix-op-responses branch October 25, 2023 17:53
sabineschaller added a commit that referenced this pull request Oct 26, 2023
* feat(backend): rename "payment pointer" tables & columns to use "wallet address" (#1937)

Co-authored-by: Nathan Lie <nathanlie@Nathans-MacBook-Pro.local>

* feat(backend, mock-ase): rename payment pointer to wallet address in rafiki code (#2029)

* fix(backend): rename paymentPointerId column in combinedPaymentsView to walletAddressId (#2043)

* docs: replace payment pointer with wallet address (#1951)

* feat(backend): remove connections route (#1940) (#2051)

Co-authored-by: Ömer Talha Özdemir <omer@fynbos.dev>

* feat(backend): unauthenticated get incoming payment (#1952) (#2052)

Co-authored-by: Ömer Talha Özdemir <omer@fynbos.dev>
Co-authored-by: Blair Currey <12960453+BlairCurrey@users.noreply.github.com>

* feat(auth): fix auth tests for access tokens (#2053)

* feat(backend): remove payment pointer from url, retrieve it from request query or body (#2042)

* refactor(backend): swap connection for methods (#2054)

Co-authored-by: Nathan Lie <lie4nathan@gmail.com>

* fix(backend): resolve breaking build after main rebase (#2085)

* fix(backend): combined_payment, ilp service tests (#2094)

* fix(backend): combined_payment, ilp service tests

* chore(backend): format

* fix(backend): bad test refactor

* fix(postman): invalid json (#2096)

* fix: fetch walletAddress graph in quote and outgoing payment service (#2099)

* fix(postman): env var usage (#2107)

* feat(backend): add quotes route to exceptions in wallet address middleware (#2108)

* chore: formatting

* fix(backend): fix GET /incoming-payments (#2111)

* fix(backend): remove wallet address from OP response id and fix receiver service (#2115)

* fix: remove wallet address from op resource urls

* feat: return auth server url in public incoming payment and fix receiver service

* fix: quote issue

* fix: walletAddress middleware

* chore: update postman

* fix: listing

* chore: remove console.log

* fix: progress towards making listing work

* fix(backend): fix create remote incoming payment (#2121)

* fix(postman): misc postman fixes

* fix(postman): complete incoming payment (#2126)

* fix: file name correction (#2127)

* fix: GET resource lists, use op client (#2122)

* fix(postman): update list urls

* fix(openapi): rm defaults for first, last

* refactor(postman): query param order for readability

* fix(backend): update to new open-payments pkgs

* fix(backend): use op client to get authServer

* fix(backend): rm old code

* fix(backend): receiver tests

* chore: cleanup

* feat: make list query parameter configurable

* chore: update OP package and fix types

---------

Co-authored-by: Sabine Schaller <sabine@interledger.org>

* fix(postman): additional fixes

* fix: wallet address on the fly creation (#2129)

* chore: update postman environments

* Postman: update description for P2P example

* Postman: Remove finalizationReason from getGrants API + fix createWalletAddress

* chore: bump open-payments package in auth

* chore: update last few remaining mentions of payment pointers

* chore(postman): remove references to payment pointer

* chore: update another reference to pp

---------

Co-authored-by: Nathan Lie <nathanlie@Nathans-MacBook-Pro.local>
Co-authored-by: Ömer Talha Özdemir <omer@fynbos.dev>
Co-authored-by: Blair Currey <12960453+BlairCurrey@users.noreply.github.com>
Co-authored-by: Sabine Schaller <sabine@interledger.org>
Co-authored-by: Sarah Jones <sarah38186@gmail.com>
Co-authored-by: Max Kurapov <maxkurapov@gmail.com>
Co-authored-by: Max Kurapov <max@interledger.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: backend Changes in the backend package. type: source Changes business logic type: tests Testing related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants